#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 */
unsigned long add(int, unsigned long *);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(int argc, char *argv[]) {
  unsigned long elements[1000000000];
  for (unsigned int i = 0; i < 1000000000; ++i) {
    elements[i] = i << 1;
  }
  unsigned long sum = add(1000000000, elements);
  printf("Sum of all elements was: %lu\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
movabs $0x1dcd65020,%rax
sub    %rax,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,0x2329afec(%rbp)
cmpl   $0x3b9aca00,0x2329afec(%rbp)
ca 9a 3b
jae    1188 <main+0x68>
mov    0x2329afec(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    0x2329afec(%rbp),%eax
mov    %rcx,0x2329aff0(%rbp,%rax,8)
23
mov    0x2329afec(%rbp),%eax
add    $0x1,%eax
mov    %eax,0x2329afec(%rbp)
jmp    1149 <main+0x29>
lea    0x2329aff0(%rbp),%rsi
mov    $0x3b9aca00,%edi
call   1030 <add@plt>
mov    %rax,0x2329afe0(%rbp)
mov    0x2329afe0(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x7fffffff,%rsp
add    $0x7fffffff,%rsp
add    $0x7fffffff,%rsp
add    $0x5cd65023,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x1dcd65008,%rax
sub    %rax,%rsp
movdqa 0xecb(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xece(%rip),%xmm1
movdqa 0xed6(%rip),%xmm2
movdqa 0xede(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm0,%xmm4
paddq  %xmm0,%xmm4
movdqa %xmm4,%xmm5
paddq  %xmm1,%xmm5
movdqa %xmm4,-0x30(%rsp,%rax,8)
movdqa %xmm5,-0x20(%rsp,%rax,8)
movdqa %xmm4,%xmm5
paddq  %xmm2,%xmm5
paddq  %xmm3,%xmm4
movdqa %xmm5,-0x10(%rsp,%rax,8)
movdqa %xmm4,(%rsp,%rax,8)
paddq  %xmm2,%xmm0
add    $0x8,%rax
cmp    $0x3b9aca06,%rax
jne    1160 <main+0x40>
mov    %rsp,%rsi
mov    $0x3b9aca00,%edi
call   1030 <add@plt>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
movabs $0x1dcd65008,%rcx
add    %rcx,%rsp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Sum of all elements was: %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000000000 x i64]
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %19, %2
%10 = load i32, i32* %7
%11 = icmp ult i32 %10, 1000000000
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %7
%14 = shl i32 %13, 1
%15 = zext i32 %14 to i64
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [1000000000 x i64], [1000000000 x i64]* %6, i64 0, i64 %17
store i64 %15, i64* %18
br label %19
19: ; preds = %12
%20 = load i32, i32* %7
%21 = add i32 %20, 1
store i32 %21, i32* %7
br label %9
22: ; preds = %9
%23 = getelementptr inbounds [1000000000 x i64], [1000000000 x i64]* %6, i64 0, i64 0
%24 = call i64 @add(i32 1000000000, i64* %23)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [30 x i8] c"Sum of all elements was: %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000000000 x i64]
%4 = bitcast [1000000000 x i64]* %3 to i8*
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %24, %5 ]
%7 = phi <2 x i64> [ <i64 0, i64 1>, %2 ], [ %25, %5 ]
%8 = shl nuw nsw <2 x i64> %7, <i64 1, i64 1>
%9 = shl <2 x i64> %7, <i64 1, i64 1>
%10 = add <2 x i64> %9, <i64 4, i64 4>
%11 = getelementptr inbounds [1000000000 x i64], [1000000000 x i64]* %3, i64 0, i64 %6
%12 = bitcast i64* %11 to <2 x i64>*
store <2 x i64> %8, <2 x i64>* %12
%13 = getelementptr inbounds i64, i64* %11, i64 2
%14 = bitcast i64* %13 to <2 x i64>*
store <2 x i64> %10, <2 x i64>* %14
%15 = or i64 %6, 4
%16 = add <2 x i64> %7, <i64 4, i64 4>
%17 = shl nuw nsw <2 x i64> %16, <i64 1, i64 1>
%18 = shl <2 x i64> %16, <i64 1, i64 1>
%19 = add <2 x i64> %18, <i64 4, i64 4>
%20 = getelementptr inbounds [1000000000 x i64], [1000000000 x i64]* %3, i64 0, i64 %15
%21 = bitcast i64* %20 to <2 x i64>*
store <2 x i64> %17, <2 x i64>* %21
%22 = getelementptr inbounds i64, i64* %20, i64 2
%23 = bitcast i64* %22 to <2 x i64>*
store <2 x i64> %19, <2 x i64>* %23
%24 = add nuw nsw i64 %6, 8
%25 = add <2 x i64> %7, <i64 8, i64 8>
%26 = icmp eq i64 %24, 1000000000
br i1 %26, label %27, label %5
27: ; preds = %5
%28 = getelementptr inbounds [1000000000 x i64], [1000000000 x i64]* %3, i64 0, i64 0
%29 = call i64 @add(i32 1000000000, i64* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %29)
ret i32 0
}