more test added
[libfirm] / ir / be / test / llvm / sumarraymalloc.c
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #define SIZE 100
5
6 static int SumArray(int *Array, unsigned Num) {
7   int Result = 0;
8   unsigned i;
9   for (i = 0; i < Num; ++i)
10     Result += Array[i];
11
12   return Result;
13 }
14
15 static int SumArray2(int *Array, unsigned Num) {
16   int Result = 0;
17   unsigned i;
18   for (i = 0; i < Num; ++i)
19     Result += *Array++;
20
21   return Result;
22 }
23
24 static void FillArray(int *Array, unsigned Num) {
25   unsigned i;
26   for (i = 0; i < Num; ++i)
27     Array[i] = i;
28 }
29
30 int
31 main(int argc, char** argv)
32 {
33   int size;
34   int *MyArray;
35
36   size = (argc < 2)? SIZE : atoi(argv[1]);
37   MyArray = malloc(sizeof(int)* size);
38
39   FillArray(MyArray, size);
40   printf("Sum1 = %d\n", SumArray(MyArray, SIZE));
41   printf("Sum2 = %d\n", SumArray2(MyArray, SIZE));
42   free(MyArray);
43   return(0);
44 }