#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int array_sum(int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int *array = malloc(64 * sizeof(int));
  int sum;
  for (int i = 0; i < 64; i++) {
    array[i] = i;
  }
  sum = array_sum(array, 64);
  printf("Sum returned: %d\n", sum);
  if (sum == (64 - 1) * (64) / 2) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x40,-0x18(%rbp)
jge    117a <main+0x4a>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <main+0x24>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1050 <array_sum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x7e0,-0x14(%rbp)
jne    11b3 <main+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11ba <main+0x8a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x100,%edi
call   1040 <malloc@plt>
movaps 0xebe(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xec4(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xec9(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xece(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xed3(%rip),%xmm0
movups %xmm0,0x40(%rax)
movaps 0xed8(%rip),%xmm0
movups %xmm0,0x50(%rax)
movaps 0xedd(%rip),%xmm0
movups %xmm0,0x60(%rax)
movaps 0xee2(%rip),%xmm0
movups %xmm0,0x70(%rax)
movaps 0xee7(%rip),%xmm0
movups %xmm0,0x80(%rax)
movaps 0xee9(%rip),%xmm0
movups %xmm0,0x90(%rax)
movaps 0xeeb(%rip),%xmm0
movups %xmm0,0xa0(%rax)
movaps 0xeed(%rip),%xmm0
movups %xmm0,0xb0(%rax)
movaps 0xeef(%rip),%xmm0
movups %xmm0,0xc0(%rax)
movaps 0xef1(%rip),%xmm0
movups %xmm0,0xd0(%rax)
movaps 0xef3(%rip),%xmm0
movups %xmm0,0xe0(%rax)
movaps 0xef5(%rip),%xmm0
movups %xmm0,0xf0(%rax)
mov    %rax,%rdi
mov    $0x40,%esi
call   1050 <array_sum@plt>
mov    %eax,%ebx
lea    0xee8(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
cmp    $0x7e0,%ebx
setne  %al
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Sum returned: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @malloc(i32 256)
store i32* %5, i32** %2
store i32 0, i32* %4
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %4
%11 = load i32*, i32** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 %10, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %6
18: ; preds = %6
%19 = load i32*, i32** %2
%20 = call i32 @array_sum(i32* %19, i32 64)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 2016
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 0, i32* %1
br label %27
26: ; preds = %18
store i32 1, i32* %1
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [18 x i8] c"Sum returned: %d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 256)
%2 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %2
%3 = getelementptr inbounds i32, i32* %1, i64 4
%4 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %4
%5 = getelementptr inbounds i32, i32* %1, i64 8
%6 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %6
%7 = getelementptr inbounds i32, i32* %1, i64 12
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, <4 x i32>* %8
%9 = getelementptr inbounds i32, i32* %1, i64 16
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %1, i64 20
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 20, i32 21, i32 22, i32 23>, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %1, i64 24
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %1, i64 28
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 28, i32 29, i32 30, i32 31>, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %1, i64 32
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> <i32 32, i32 33, i32 34, i32 35>, <4 x i32>* %18
%19 = getelementptr inbounds i32, i32* %1, i64 36
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 36, i32 37, i32 38, i32 39>, <4 x i32>* %20
%21 = getelementptr inbounds i32, i32* %1, i64 40
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 40, i32 41, i32 42, i32 43>, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %1, i64 44
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 44, i32 45, i32 46, i32 47>, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %1, i64 48
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 48, i32 49, i32 50, i32 51>, <4 x i32>* %26
%27 = getelementptr inbounds i32, i32* %1, i64 52
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> <i32 52, i32 53, i32 54, i32 55>, <4 x i32>* %28
%29 = getelementptr inbounds i32, i32* %1, i64 56
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> <i32 56, i32 57, i32 58, i32 59>, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %1, i64 60
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> <i32 60, i32 61, i32 62, i32 63>, <4 x i32>* %32
%33 = tail call i32 @array_sum(i32* %1, i32 64)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = icmp ne i32 %33, 2016
%36 = zext i1 %35 to i32
ret i32 %36
}