#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 */
scalar_t__ foo_compute(int, double *, double *, double *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  double res = 0;
  struct timeval t1, t2;
  double *a, *b, *c;
  a = malloc(sizeof(double) * 100);
  b = malloc(sizeof(double) * 100);
  c = malloc(sizeof(double) * 100);
  for (i = 0; i < 100; i++) {
    a[i] = i;
    b[i] = i;
  }
  printf("START !\n");
  if (gettimeofday(&t1, NULL)) {
    perror("gettimeofday");
  }
  for (i = 0; i < 1000000; i++) {
    res += foo_compute(100, a, b, c);
  }
  if (gettimeofday(&t2, NULL)) {
    perror("gettimeofday");
  }
  printf("STOP !\n");
  printf("res = %lf\n", res);
  printf("%d iterations in %lf s (%lf µs per iteration)\n", 1000000,
         ((t2.tv_sec - t1.tv_sec) * 1e6 + (t2.tv_usec - t1.tv_usec)) / 1e6,
         ((t2.tv_sec - t1.tv_sec) * 1e6 + (t2.tv_usec - t1.tv_usec)) / 1000000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11d4 <main+0x84>
cvtsi2sdl -0x8(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x8(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1198 <main+0x48>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     1205 <main+0xb5>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    124c <main+0xfc>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x64,%edi
call   1030 <foo_compute@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120c <main+0xbc>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     126f <main+0x11f>
lea    0xda7(%rip),%rdi
call   1070 <perror@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xd9d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xd54(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd44(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  0xd24(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xd14(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xd3a(%rip),%rdi
mov    $0xf4240,%esi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x320,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x320,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x320,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
movdqa 0xe67(%rip),%xmm0
mov    $0x8,%eax
movdqa 0xe6a(%rip),%xmm1
movdqa 0xe72(%rip),%xmm2
movdqa 0xe7a(%rip),%xmm3
movdqa 0xe82(%rip),%xmm4
movdqa 0xe8a(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
cvtdq2pd %xmm0,%xmm6
movups %xmm6,-0x40(%r14,%rax,8)
movups %xmm6,-0x40(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm6,-0x30(%r14,%rax,8)
movdqa %xmm0,%xmm7
paddd  %xmm2,%xmm7
cvtdq2pd %xmm7,%xmm7
movups %xmm6,-0x30(%rbx,%rax,8)
movups %xmm7,-0x20(%r14,%rax,8)
movups %xmm7,-0x20(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm6,-0x10(%r14,%rax,8)
movups %xmm6,-0x10(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm4,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm6,(%r14,%rax,8)
movups %xmm6,(%rbx,%rax,8)
paddd  %xmm5,%xmm0
add    $0xa,%rax
cmp    $0x6c,%rax
jne    11d0 <main+0x70>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1342 <main+0x1e2>
pxor   %xmm0,%xmm0
mov    $0xf4240,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   %xmm0,(%rsp)
mov    $0x64,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <foo_compute@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movq   (%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1280 <main+0x120>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1353 <main+0x1f3>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
lea    0xd95(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0x14(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  0xd4e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
lea    0xd5b(%rip),%rdi
mov    $0xf4240,%esi
movapd %xmm0,%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1f(%rip),%rdi
call   1080 <perror@plt>
jmp    1268 <main+0x108>
lea    0xd0e(%rip),%rdi
call   1080 <perror@plt>
jmp    12cd <main+0x16d>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [9 x i8] c"START !\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.2 = [8 x i8] c"STOP !\0A\00"
@.str.3 = [11 x i8] c"res = %lf\0A\00"
@.str.4 = [48 x i8] c"%d iterations in %lf s (%lf \C2\B5s per iteration)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
store i32 0, i32* %1
store double 0.000000e+00, double* %3
%9 = call double* @malloc(i32 800)
store double* %9, double** %6
%10 = call double* @malloc(i32 800)
store double* %10, double** %7
%11 = call double* @malloc(i32 800)
store double* %11, double** %8
store i32 0, i32* %2
br label %12
12: ; preds = %28, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 100
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = load double*, double** %6
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
store double %17, double* %21
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = load double*, double** %7
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %23, double* %27
br label %28
28: ; preds = %15
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %12
31: ; preds = %12
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%33 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
store i32 0, i32* %2
br label %38
38: ; preds = %49, %37
%39 = load i32, i32* %2
%40 = icmp slt i32 %39, 1000000
br i1 %40, label %41, label %52
41: ; preds = %38
%42 = load double*, double** %6
%43 = load double*, double** %7
%44 = load double*, double** %8
%45 = call i64 @foo_compute(i32 100, double* %42, double* %43, double* %44)
%46 = sitofp i64 %45 to double
%47 = load double, double* %3
%48 = fadd double %47, %46
store double %48, double* %3
br label %49
49: ; preds = %41
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %38
52: ; preds = %38
%53 = call i64 @gettimeofday(%struct.timeval* %5, i32* null)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%59 = load double, double* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %59)
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%64 = load i32, i32* %63
%65 = sub nsw i32 %62, %64
%66 = sitofp i32 %65 to double
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%70 = load i32, i32* %69
%71 = sub nsw i32 %68, %70
%72 = sitofp i32 %71 to double
%73 = call double @llvm.fmuladd.f64(double %66, double 1.000000e+06, double %72)
%74 = fdiv double %73, 1.000000e+06
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%78 = load i32, i32* %77
%79 = sub nsw i32 %76, %78
%80 = sitofp i32 %79 to double
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%82 = load i32, i32* %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%84 = load i32, i32* %83
%85 = sub nsw i32 %82, %84
%86 = sitofp i32 %85 to double
%87 = call double @llvm.fmuladd.f64(double %80, double 1.000000e+06, double %86)
%88 = fdiv double %87, 1.000000e+06
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 1000000, double %74, double %88)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.3 = [11 x i8] c"res = %lf\0A\00"
@.str.4 = [48 x i8] c"%d iterations in %lf s (%lf \C2\B5s per iteration)\0A\00"
@str = [8 x i8] c"START !\00"
@str.5 = [7 x i8] c"STOP !\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = tail call double* @malloc(i32 800)
%6 = tail call double* @malloc(i32 800)
%7 = tail call double* @malloc(i32 800)
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ 0, %0 ], [ %44, %8 ]
%10 = phi <2 x i32> [ <i32 0, i32 1>, %0 ], [ %45, %8 ]
%11 = sitofp <2 x i32> %10 to <2 x double>
%12 = getelementptr inbounds double, double* %5, i64 %9
%13 = bitcast double* %12 to <2 x double>*
store <2 x double> %11, <2 x double>* %13
%14 = getelementptr inbounds double, double* %6, i64 %9
%15 = bitcast double* %14 to <2 x double>*
store <2 x double> %11, <2 x double>* %15
%16 = add nuw nsw i64 %9, 2
%17 = add <2 x i32> %10, <i32 2, i32 2>
%18 = sitofp <2 x i32> %17 to <2 x double>
%19 = getelementptr inbounds double, double* %5, i64 %16
%20 = bitcast double* %19 to <2 x double>*
store <2 x double> %18, <2 x double>* %20
%21 = getelementptr inbounds double, double* %6, i64 %16
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> %18, <2 x double>* %22
%23 = add nuw nsw i64 %9, 4
%24 = add <2 x i32> %10, <i32 4, i32 4>
%25 = sitofp <2 x i32> %24 to <2 x double>
%26 = getelementptr inbounds double, double* %5, i64 %23
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %25, <2 x double>* %27
%28 = getelementptr inbounds double, double* %6, i64 %23
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> %25, <2 x double>* %29
%30 = add nuw nsw i64 %9, 6
%31 = add <2 x i32> %10, <i32 6, i32 6>
%32 = sitofp <2 x i32> %31 to <2 x double>
%33 = getelementptr inbounds double, double* %5, i64 %30
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> %32, <2 x double>* %34
%35 = getelementptr inbounds double, double* %6, i64 %30
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> %32, <2 x double>* %36
%37 = add nuw nsw i64 %9, 8
%38 = add <2 x i32> %10, <i32 8, i32 8>
%39 = sitofp <2 x i32> %38 to <2 x double>
%40 = getelementptr inbounds double, double* %5, i64 %37
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %39, <2 x double>* %41
%42 = getelementptr inbounds double, double* %6, i64 %37
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> %39, <2 x double>* %43
%44 = add nuw nsw i64 %9, 10
%45 = add <2 x i32> %10, <i32 10, i32 10>
%46 = icmp eq i64 %44, 100
br i1 %46, label %47, label %8
47: ; preds = %8
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%49 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%50 = icmp eq i64 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
br label %54
54: ; preds = %53, %54
%55 = phi i32 [ %60, %54 ], [ 0, %53 ]
%56 = phi double [ %59, %54 ], [ 0.000000e+00, %53 ]
%57 = tail call i64 @foo_compute(i32 100, double* %5, double* %6, double* %7)
%58 = sitofp i64 %57 to double
%59 = fadd double %56, %58
%60 = add nuw nsw i32 %55, 1
%61 = icmp eq i32 %60, 1000000
br i1 %61, label %62, label %54
62: ; preds = %54
%63 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%64 = icmp eq i64 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %62
%66 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.5, i64 0, i64 0))
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %59)
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%73 = load i32, i32* %72
%74 = sub nsw i32 %71, %73
%75 = sitofp i32 %74 to double
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%79 = load i32, i32* %78
%80 = sub nsw i32 %77, %79
%81 = sitofp i32 %80 to double
%82 = tail call double @llvm.fmuladd.f64(double %75, double 1.000000e+06, double %81)
%83 = fdiv double %82, 1.000000e+06
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 1000000, double %83, double %83)
ret i32 0
}