1/* 2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <assert.h> 8#include <camkes.h> 9#include <stddef.h> 10#include <stdio.h> 11#include <stdlib.h> 12 13int a_calculate(size_t operands_sz, const int *operands, size_t *other_sz, int **other, size_t *inplace_sz, int **inplace) { 14 const char *name = get_instance_name(); 15 int total = 1; 16 for (int i = 0; i < operands_sz; i++) { 17 printf("%s: multiplying %d\n", name, operands[i]); 18 total *= operands[i]; 19 } 20 int i; 21 *other = (int*)malloc(sizeof(int) * *inplace_sz); 22 assert(*other != NULL); 23 for (i = 0; i < *inplace_sz; i++) { 24 printf("%s: stashing %d\n", name, (*inplace)[i]); 25 (*other)[i] = (*inplace)[i]; 26 } 27 *other_sz = i; 28 for (i = 1; i < *inplace_sz; i++) { 29 printf("%s: multiplying %d\n", name, (*inplace)[i]); 30 (*inplace)[0] *= (*inplace)[i]; 31 } 32 *inplace_sz = 1; 33 return total; 34} 35