#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float, ...);
float sum_array(float *, int);
int main() {
  float xx[0x1000];
  for (int i = 0; i < 0x1000; i++) {
    xx[i] = i;
  }
  float sum;
  struct timeval start, end;
  gettimeofday(&start, NULL);
  sum = sum_array(xx, 0x1000);
  gettimeofday(&end, NULL);
  printf("end   : %d.%d\n", end.tv_sec - start.tv_sec,
         end.tv_usec - start.tv_usec);
  printf("sum %f\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x4014(%rbp)
cmpl   $0x1000,-0x4014(%rbp)
jge    1188 <main+0x58>
cvtsi2ssl -0x4014(%rbp),%xmm0
ff
movslq -0x4014(%rbp),%rax
movss  %xmm0,-0x4010(%rbp,%rax,4)
ff ff
mov    -0x4014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4014(%rbp)
jmp    114c <main+0x1c>
lea    -0x4020(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x4010(%rbp),%rdi
mov    $0x1000,%esi
call   1030 <sum_array@plt>
movss  %xmm0,-0x4018(%rbp)
ff
lea    -0x4028(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x4028(%rbp),%eax
sub    -0x4020(%rbp),%eax
cvtsi2ss %eax,%xmm0
mov    -0x4024(%rbp),%esi
sub    -0x401c(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x4018(%rbp),%xmm0
ff
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x4028,%rsp
movdqa 0xec1(%rip),%xmm0
xor    %eax,%eax
movdqa 0xec7(%rip),%xmm1
movdqa 0xecf(%rip),%xmm2
movdqa 0xed7(%rip),%xmm3
movdqa 0xedf(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
cvtdq2ps %xmm0,%xmm6
cvtdq2ps %xmm5,%xmm5
movaps %xmm6,0x20(%rsp,%rax,4)
movaps %xmm5,0x30(%rsp,%rax,4)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
cvtdq2ps %xmm5,%xmm5
cvtdq2ps %xmm6,%xmm6
movaps %xmm5,0x40(%rsp,%rax,4)
movaps %xmm6,0x50(%rsp,%rax,4)
add    $0x10,%rax
paddd  %xmm4,%xmm0
cmp    $0x1000,%rax
jne    1170 <main+0x40>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
call   1030 <sum_array@plt>
movd   %xmm0,0xc(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x10(%rsp),%eax
sub    0x18(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mov    0x14(%rsp),%esi
sub    0x1c(%rsp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe4e(%rip),%rdi
movss  0xc(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x4028,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [15 x i8] c"end : %d.%d\0A\00"
@.str.1 = [8 x i8] c"sum %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x float]
%3 = alloca i32
%4 = alloca float
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
store i32 0, i32* %1
store i32 0, i32* %3
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 4096
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sitofp i32 %11 to float
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4096 x float], [4096 x float]* %2, i64 0, i64 %14
store float %12, float* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %7
19: ; preds = %7
%20 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%21 = getelementptr inbounds [4096 x float], [4096 x float]* %2, i64 0, i64 0
%22 = call float @sum_array(float* %21, i32 4096)
store float %22, float* %4
%23 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = sitofp i32 %28 to float
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%33 = load i32, i32* %32
%34 = sub nsw i32 %31, %33
%35 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float %29, i32 %34)
%36 = load float, float* %4
%37 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), float %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [15 x i8] c"end : %d.%d\0A\00"
@.str.1 = [8 x i8] c"sum %f\0A\00"
define i32 @main() {
%1 = alloca [4096 x float]
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast [4096 x float]* %1 to i8*
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %24, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %25, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = sitofp <4 x i32> %7 to <4 x float>
%10 = sitofp <4 x i32> %8 to <4 x float>
%11 = getelementptr inbounds [4096 x float], [4096 x float]* %1, i64 0, i64 %6
%12 = bitcast float* %11 to <4 x float>*
store <4 x float> %9, <4 x float>* %12
%13 = getelementptr inbounds float, float* %11, i64 4
%14 = bitcast float* %13 to <4 x float>*
store <4 x float> %10, <4 x float>* %14
%15 = or i64 %6, 8
%16 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%17 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%18 = sitofp <4 x i32> %16 to <4 x float>
%19 = sitofp <4 x i32> %17 to <4 x float>
%20 = getelementptr inbounds [4096 x float], [4096 x float]* %1, i64 0, i64 %15
%21 = bitcast float* %20 to <4 x float>*
store <4 x float> %18, <4 x float>* %21
%22 = getelementptr inbounds float, float* %20, i64 4
%23 = bitcast float* %22 to <4 x float>*
store <4 x float> %19, <4 x float>* %23
%24 = add nuw nsw i64 %6, 16
%25 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%26 = icmp eq i64 %24, 4096
br i1 %26, label %27, label %5
27: ; preds = %5
%28 = bitcast %struct.timeval* %2 to i8*
%29 = bitcast %struct.timeval* %3 to i8*
%30 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%31 = getelementptr inbounds [4096 x float], [4096 x float]* %1, i64 0, i64 0
%32 = call float @sum_array(float* %31, i32 4096)
%33 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%37 = load i32, i32* %36
%38 = sub nsw i32 %35, %37
%39 = sitofp i32 %38 to float
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%43 = load i32, i32* %42
%44 = sub nsw i32 %41, %43
%45 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float %39, i32 %44)
%46 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), float %32)
ret i32 0
}