#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
double sum_array(double *, int);
int main() {
  double a[100000];
  int i;
  clock_t start, end;
  double cpu_time;
  for (i = 0; i < 100000; i++) {
    a[i] = i;
  }
  start = clock();
  double sum = sum_array(a, 100000);
  end = clock();
  printf("%f ", sum);
  cpu_time = ((double)(end - start)) / CLOCKS_PER_SEC;
  cpu_time *= 1000000;
  printf("%f usegs\n", cpu_time);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc3540,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc3514(%rbp)
cmpl   $0x186a0,-0xc3514(%rbp)
jge    1188 <main+0x58>
cvtsi2sdl -0xc3514(%rbp),%xmm0
ff
movslq -0xc3514(%rbp),%rax
movsd  %xmm0,-0xc3510(%rbp,%rax,8)
f3 ff
mov    -0xc3514(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3514(%rbp)
jmp    114c <main+0x1c>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0xc3520(%rbp)
lea    -0xc3510(%rbp),%rdi
mov    $0x186a0,%esi
call   1030 <sum_array@plt>
movsd  %xmm0,-0xc3538(%rbp)
ff
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0xc3528(%rbp)
movsd  -0xc3538(%rbp),%xmm0
ff
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc3528(%rbp),%rax
sub    -0xc3520(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dfd(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0xc3530(%rbp)
ff
movsd  0xe01(%rip),%xmm0
mulsd  -0xc3530(%rbp),%xmm0
ff
movsd  %xmm0,-0xc3530(%rbp)
ff
movsd  -0xc3530(%rbp),%xmm0
ff
lea    0xdee(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xc3540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xc3518,%rsp
movdqa 0xebe(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xec1(%rip),%xmm1
movdqa 0xec9(%rip),%xmm2
movdqa 0xed1(%rip),%xmm3
movdqa 0xed9(%rip),%xmm4
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movaps %xmm6,-0x20(%rsp,%rax,8)
movaps %xmm5,-0x10(%rsp,%rax,8)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movaps %xmm5,(%rsp,%rax,8)
movaps %xmm6,0x10(%rsp,%rax,8)
paddd  %xmm4,%xmm0
add    $0x8,%rax
cmp    $0x186a6,%rax
jne    1170 <main+0x40>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x186a0,%esi
call   1030 <sum_array@plt>
movq   %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
lea    0xe6d(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    0x2de0(%rip),%rax
divsd  (%rax),%xmm0
mulsd  0xe3c(%rip),%xmm0
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc3518,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f \00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [10 x i8] c"%f usegs\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100000 x double]
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
store i32 0, i32* %3
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 100000
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to double
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100000 x double], [100000 x double]* %2, i64 0, i64 %15
store double %13, double* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %8
20: ; preds = %8
%21 = call i64 (...) @clock()
store i64 %21, i64* %4
%22 = getelementptr inbounds [100000 x double], [100000 x double]* %2, i64 0, i64 0
%23 = call double @sum_array(double* %22, i32 100000)
store double %23, double* %7
%24 = call i64 (...) @clock()
store i64 %24, i64* %5
%25 = load double, double* %7
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %25)
%27 = load i64, i64* %5
%28 = load i64, i64* %4
%29 = sub nsw i64 %27, %28
%30 = sitofp i64 %29 to double
%31 = load double, double* @CLOCKS_PER_SEC
%32 = fdiv double %30, %31
store double %32, double* %6
%33 = load double, double* %6
%34 = fmul double %33, 1.000000e+06
store double %34, double* %6
%35 = load double, double* %6
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f \00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [10 x i8] c"%f usegs\0A\00"
define i32 @main() {
%1 = alloca [100000 x double]
%2 = bitcast [100000 x double]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %22, %3 ]
%5 = phi <2 x i32> [ <i32 0, i32 1>, %0 ], [ %23, %3 ]
%6 = add <2 x i32> %5, <i32 2, i32 2>
%7 = sitofp <2 x i32> %5 to <2 x double>
%8 = sitofp <2 x i32> %6 to <2 x double>
%9 = getelementptr inbounds [100000 x double], [100000 x double]* %1, i64 0, i64 %4
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> %7, <2 x double>* %10
%11 = getelementptr inbounds double, double* %9, i64 2
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> %8, <2 x double>* %12
%13 = or i64 %4, 4
%14 = add <2 x i32> %5, <i32 4, i32 4>
%15 = add <2 x i32> %5, <i32 6, i32 6>
%16 = sitofp <2 x i32> %14 to <2 x double>
%17 = sitofp <2 x i32> %15 to <2 x double>
%18 = getelementptr inbounds [100000 x double], [100000 x double]* %1, i64 0, i64 %13
%19 = bitcast double* %18 to <2 x double>*
store <2 x double> %16, <2 x double>* %19
%20 = getelementptr inbounds double, double* %18, i64 2
%21 = bitcast double* %20 to <2 x double>*
store <2 x double> %17, <2 x double>* %21
%22 = add nuw nsw i64 %4, 8
%23 = add <2 x i32> %5, <i32 8, i32 8>
%24 = icmp eq i64 %22, 100000
br i1 %24, label %25, label %3
25: ; preds = %3
%26 = tail call i64 (...) @clock()
%27 = getelementptr inbounds [100000 x double], [100000 x double]* %1, i64 0, i64 0
%28 = call double @sum_array(double* %27, i32 100000)
%29 = call i64 (...) @clock()
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %28)
%31 = sub nsw i64 %29, %26
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
%35 = fmul double %34, 1.000000e+06
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %35)
ret i32 0
}