#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 */
double example_function1(double *, int);
int example_function2(int *, int);
double example_static_function(double *, int);
void *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  double *double_array = malloc(sizeof(double) * (1024 * 1024));
  int *int_array = malloc(sizeof(int) * (1024 * 1024));
  int i;
  for (i = 0; i < (1024 * 1024); i++) {
    double_array[i] = (i * i) / 31;
  }
  double sum_double = example_function1(double_array, (1024 * 1024));
  for (i = 0; i < (1024 * 1024); i++) {
    double_array[i] = (i * i) / 31;
  }
  double static_sum_double =
      example_static_function(double_array, (1024 * 1024));
  for (i = 0; i < (1024 * 1024); i++) {
    int_array[i] = i % 17;
  }
  int sum_int = example_function2(int_array, (1024 * 1024));
  printf("sum double = %lf\n", sum_double);
  printf("static sum double = %lf\n", static_sum_double);
  printf("sum int = %d\n", sum_int);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x800000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100000,-0x24(%rbp)
jge    11c4 <main+0x74>
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <main+0x39>
mov    -0x18(%rbp),%rdi
mov    $0x100000,%esi
call   1030 <example_function1@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100000,-0x24(%rbp)
jge    1219 <main+0xc9>
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11de <main+0x8e>
mov    -0x18(%rbp),%rdi
mov    $0x100000,%esi
call   1050 <example_static_function@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100000,-0x24(%rbp)
jge    1264 <main+0x114>
mov    -0x24(%rbp),%eax
mov    $0x11,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1233 <main+0xe3>
mov    -0x20(%rbp),%rdi
mov    $0x100000,%esi
call   1070 <example_function2@plt>
mov    %eax,-0x3c(%rbp)
cvttsd2si -0x30(%rbp),%esi
lea    0xd86(%rip),%rdi
call   1040 <printf@plt>
cvttsd2si -0x38(%rbp),%esi
lea    0xd6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x800000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x400000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ecx
imul   %ecx,%ecx
imul   $0x8421085,%rcx,%rdx
shr    $0x20,%rdx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x4,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
lea    0x1(%rax),%ecx
imul   %ecx,%ecx
imul   $0x8421085,%rcx,%rdx
shr    $0x20,%rdx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x4,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  %xmm0,(%rbx,%rax,8)
movsd  %xmm1,0x8(%rbx,%rax,8)
add    $0x2,%rax
cmp    $0x100000,%rax
jne    1180 <main+0x30>
mov    %rbx,%rdi
mov    $0x100000,%esi
call   1030 <example_function1@plt>
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
nopl   (%rax)
mov    %eax,%ecx
imul   %ecx,%ecx
imul   $0x8421085,%rcx,%rdx
shr    $0x20,%rdx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x4,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
lea    0x1(%rax),%ecx
imul   %ecx,%ecx
imul   $0x8421085,%rcx,%rdx
shr    $0x20,%rdx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x4,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  %xmm0,(%rbx,%rax,8)
movsd  %xmm1,0x8(%rbx,%rax,8)
add    $0x2,%rax
cmp    $0x100000,%rax
jne    11f0 <main+0xa0>
mov    %rbx,%rdi
mov    $0x100000,%esi
call   1050 <example_static_function@plt>
movsd  %xmm0,0x8(%rsp)
movdqa 0xd9d(%rip),%xmm0
xor    %eax,%eax
movdqa 0xda2(%rip),%xmm8
movdqa 0xdaa(%rip),%xmm2
movdqa 0xdb1(%rip),%xmm9
movdqa 0xdb9(%rip),%xmm4
movdqa 0xdc1(%rip),%xmm5
nop
movdqa %xmm0,%xmm6
paddd  %xmm8,%xmm6
movdqa %xmm0,%xmm7
pmuludq %xmm2,%xmm7
pshufd $0xed,%xmm7,%xmm7
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm7
psrld  $0x4,%xmm7
movdqa %xmm7,%xmm1
pslld  $0x4,%xmm1
paddd  %xmm7,%xmm1
movdqa %xmm0,%xmm7
psubd  %xmm1,%xmm7
movdqa %xmm6,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm6,%xmm3
pmuludq %xmm2,%xmm3
pshufd $0xed,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
psrld  $0x4,%xmm1
movdqa %xmm1,%xmm3
pslld  $0x4,%xmm3
paddd  %xmm1,%xmm3
psubd  %xmm3,%xmm6
movdqu %xmm7,(%r14,%rax,4)
movdqu %xmm6,0x10(%r14,%rax,4)
movdqa %xmm0,%xmm6
paddd  %xmm9,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
movdqa %xmm6,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm6,%xmm3
pmuludq %xmm2,%xmm3
pshufd $0xed,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
psrld  $0x4,%xmm1
movdqa %xmm1,%xmm3
pslld  $0x4,%xmm3
paddd  %xmm1,%xmm3
psubd  %xmm3,%xmm6
movdqa %xmm7,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm7,%xmm3
pmuludq %xmm2,%xmm3
pshufd $0xed,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
psrld  $0x4,%xmm1
movdqa %xmm1,%xmm3
pslld  $0x4,%xmm3
paddd  %xmm1,%xmm3
psubd  %xmm3,%xmm7
movdqu %xmm6,0x20(%r14,%rax,4)
movdqu %xmm7,0x30(%r14,%rax,4)
add    $0x10,%rax
paddd  %xmm5,%xmm0
cmp    $0x100000,%rax
jne    1290 <main+0x140>
mov    %r14,%rdi
mov    $0x100000,%esi
call   1070 <example_function2@plt>
mov    %eax,%ebx
cvttsd2si 0x10(%rsp),%esi
lea    0xc9a(%rip),%rdi
call   1040 <printf@plt>
cvttsd2si 0x8(%rsp),%esi
lea    0xc81(%rip),%rdi
call   1040 <printf@plt>
lea    0xc8e(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"sum double = %lf\0A\00"
@.str.1 = [25 x i8] c"static sum double = %lf\0A\00"
@.str.2 = [14 x i8] c"sum int = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i8* @malloc(i32 8388608)
%13 = bitcast i8* %12 to double*
store double* %13, double** %6
%14 = call i8* @malloc(i32 4194304)
%15 = bitcast i8* %14 to i32*
store i32* %15, i32** %7
store i32 0, i32* %8
br label %16
16: ; preds = %29, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 1048576
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i32, i32* %8
%21 = load i32, i32* %8
%22 = mul nsw i32 %20, %21
%23 = sdiv i32 %22, 31
%24 = sitofp i32 %23 to double
%25 = load double*, double** %6
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
store double %24, double* %28
br label %29
29: ; preds = %19
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %16
32: ; preds = %16
%33 = load double*, double** %6
%34 = call double @example_function1(double* %33, i32 1048576)
store double %34, double* %9
store i32 0, i32* %8
br label %35
35: ; preds = %48, %32
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, 1048576
br i1 %37, label %38, label %51
38: ; preds = %35
%39 = load i32, i32* %8
%40 = load i32, i32* %8
%41 = mul nsw i32 %39, %40
%42 = sdiv i32 %41, 31
%43 = sitofp i32 %42 to double
%44 = load double*, double** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %38
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %35
51: ; preds = %35
%52 = load double*, double** %6
%53 = call double @example_static_function(double* %52, i32 1048576)
store double %53, double* %10
store i32 0, i32* %8
br label %54
54: ; preds = %64, %51
%55 = load i32, i32* %8
%56 = icmp slt i32 %55, 1048576
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = load i32, i32* %8
%59 = srem i32 %58, 17
%60 = load i32*, i32** %7
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
store i32 %59, i32* %63
br label %64
64: ; preds = %57
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %54
67: ; preds = %54
%68 = load i32*, i32** %7
%69 = call i32 @example_function2(i32* %68, i32 1048576)
store i32 %69, i32* %11
%70 = load double, double* %9
%71 = fptosi double %70 to i32
%72 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = load double, double* %10
%74 = fptosi double %73 to i32
%75 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %11
%77 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"sum double = %lf\0A\00"
@.str.1 = [25 x i8] c"static sum double = %lf\0A\00"
@.str.2 = [14 x i8] c"sum int = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(8388608) i8* @malloc(i32 8388608)
%4 = bitcast i8* %3 to double*
%5 = tail call dereferenceable_or_null(4194304) i8* @malloc(i32 4194304)
br label %6
6: ; preds = %6, %2
%7 = phi i64 [ 0, %2 ], [ %19, %6 ]
%8 = trunc i64 %7 to i32
%9 = mul nsw i32 %8, %8
%10 = udiv i32 %9, 31
%11 = sitofp i32 %10 to double
%12 = getelementptr inbounds double, double* %4, i64 %7
store double %11, double* %12
%13 = or i64 %7, 1
%14 = trunc i64 %13 to i32
%15 = mul nsw i32 %14, %14
%16 = udiv i32 %15, 31
%17 = sitofp i32 %16 to double
%18 = getelementptr inbounds double, double* %4, i64 %13
store double %17, double* %18
%19 = add nuw nsw i64 %7, 2
%20 = icmp eq i64 %19, 1048576
br i1 %20, label %21, label %6
21: ; preds = %6
%22 = tail call double @example_function1(double* %4, i32 1048576)
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %36, %23 ]
%25 = trunc i64 %24 to i32
%26 = mul nsw i32 %25, %25
%27 = udiv i32 %26, 31
%28 = sitofp i32 %27 to double
%29 = getelementptr inbounds double, double* %4, i64 %24
store double %28, double* %29
%30 = or i64 %24, 1
%31 = trunc i64 %30 to i32
%32 = mul nsw i32 %31, %31
%33 = udiv i32 %32, 31
%34 = sitofp i32 %33 to double
%35 = getelementptr inbounds double, double* %4, i64 %30
store double %34, double* %35
%36 = add nuw nsw i64 %24, 2
%37 = icmp eq i64 %36, 1048576
br i1 %37, label %38, label %23
38: ; preds = %23
%39 = bitcast i8* %5 to i32*
%40 = tail call double @example_static_function(double* %4, i32 1048576)
br label %41
41: ; preds = %41, %38
%42 = phi i64 [ 0, %38 ], [ %60, %41 ]
%43 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %38 ], [ %61, %41 ]
%44 = add <4 x i32> %43, <i32 4, i32 4, i32 4, i32 4>
%45 = urem <4 x i32> %43, <i32 17, i32 17, i32 17, i32 17>
%46 = urem <4 x i32> %44, <i32 17, i32 17, i32 17, i32 17>
%47 = getelementptr inbounds i32, i32* %39, i64 %42
%48 = bitcast i32* %47 to <4 x i32>*
store <4 x i32> %45, <4 x i32>* %48
%49 = getelementptr inbounds i32, i32* %47, i64 4
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> %46, <4 x i32>* %50
%51 = or i64 %42, 8
%52 = add <4 x i32> %43, <i32 8, i32 8, i32 8, i32 8>
%53 = add <4 x i32> %43, <i32 12, i32 12, i32 12, i32 12>
%54 = urem <4 x i32> %52, <i32 17, i32 17, i32 17, i32 17>
%55 = urem <4 x i32> %53, <i32 17, i32 17, i32 17, i32 17>
%56 = getelementptr inbounds i32, i32* %39, i64 %51
%57 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> %54, <4 x i32>* %57
%58 = getelementptr inbounds i32, i32* %56, i64 4
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> %55, <4 x i32>* %59
%60 = add nuw nsw i64 %42, 16
%61 = add <4 x i32> %43, <i32 16, i32 16, i32 16, i32 16>
%62 = icmp eq i64 %60, 1048576
br i1 %62, label %63, label %41
63: ; preds = %41
%64 = tail call i32 @example_function2(i32* %39, i32 1048576)
%65 = fptosi double %22 to i32
%66 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %65)
%67 = fptosi double %40 to i32
%68 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %67)
%69 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %64)
ret i32 0
}