#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sum(int *, int, int *);
int main() {
  int i;
  int accum = 0;
  int data[40];
  for (i = 0; i < 40; ++i)
    data[i] = i;
  sum(&accum, 40, data);
  printf("sum is %d\n", accum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x28,-0x8(%rbp)
jge    1166 <main+0x46>
mov    -0x8(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0xb0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <main+0x20>
lea    -0xb0(%rbp),%rdx
lea    -0xc(%rbp),%rdi
mov    $0x28,%esi
call   1040 <sum@plt>
mov    -0xc(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xb8,%rsp
movl   $0x0,0xc(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xee6(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xee7(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xee8(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    $0x28,%esi
call   1040 <sum@plt>
mov    0xc(%rsp),%esi
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"sum is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [40 x i32]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %2
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 40
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [40 x i32], [40 x i32]* %4, i64 0, i64 %11
store i32 %9, i32* %12
br label %13
13: ; preds = %8
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %5
16: ; preds = %5
%17 = getelementptr inbounds [40 x i32], [40 x i32]* %4, i64 0, i64 0
%18 = call i32 @sum(i32* %3, i32 40, i32* %17)
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"sum is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [40 x i32]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast [40 x i32]* %2 to i8*
%5 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 0
%6 = bitcast [40 x i32]* %2 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %6
%7 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %8
%9 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 8
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %10
%11 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 12
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, <4 x i32>* %12
%13 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 16
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, <4 x i32>* %14
%15 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 20
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 20, i32 21, i32 22, i32 23>, <4 x i32>* %16
%17 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 24
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, <4 x i32>* %18
%19 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 28
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 28, i32 29, i32 30, i32 31>, <4 x i32>* %20
%21 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 32
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 32, i32 33, i32 34, i32 35>, <4 x i32>* %22
%23 = getelementptr inbounds [40 x i32], [40 x i32]* %2, i64 0, i64 36
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 36, i32 37, i32 38, i32 39>, <4 x i32>* %24
%25 = call i32 @sum(i32* %1, i32 40, i32* %5)
%26 = load i32, i32* %1
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %26)
ret i32 0
}