#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 CLOCKS_PER_SEC;
int clock();
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
double random();
int /*<<< orphan*/ test_mean1(double *, double *, int);
int /*<<< orphan*/ test_mean2(double *, double *, int);
int /*<<< orphan*/ test_mean3(double *, double *, int);
int main() {
  int i;
  int N = 1000000;
  int trials = 50;
  int tstart, tstop;
  double xymean[2];
  double *xy = (double *)malloc(2 * N * sizeof(double));
  for (i = 0; i < 2 * N; ++i)
    xy[i] = random();
  tstart = clock();
  for (i = 0; i < trials; ++i)
    test_mean1(xymean, xy, N);
  tstop = clock();
  printf("Version 1: %e\n", (double)(tstop - tstart) / trials / CLOCKS_PER_SEC);
  tstart = clock();
  for (i = 0; i < trials; ++i)
    test_mean2(xymean, xy, N);
  tstop = clock();
  printf("Version 2: %e\n", (double)(tstop - tstart) / trials / CLOCKS_PER_SEC);
  tstart = clock();
  for (i = 0; i < trials; ++i)
    test_mean3(xymean, xy, N);
  tstop = clock();
  printf("Version 3: %e\n", (double)(tstop - tstart) / trials / CLOCKS_PER_SEC);
  free(xy);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0xc(%rbp)
movl   $0x32,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    11ee <main+0x6e>
mov    $0x0,%al
call   1080 <random@plt>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bb <main+0x3b>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1229 <main+0xa9>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <test_mean1@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ff <main+0x7f>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    0x2d9b(%rip),%rax
divsd  (%rax),%xmm0
lea    0xda8(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1298 <main+0x118>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10a0 <test_mean2@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126e <main+0xee>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    0x2d2c(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd48(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1307 <main+0x187>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <test_mean3@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12dd <main+0x15d>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    0x2cbd(%rip),%rax
divsd  (%rax),%xmm0
lea    0xce8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xf42400,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <random@plt>
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    $0x1e8480,%rbp
jne    11a0 <main+0x20>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%r14d
mov    $0x32,%ebp
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xf4240,%edx
call   1070 <test_mean1@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe02(%rip),%xmm0
mov    0x2de3(%rip),%r15
divsd  (%r15),%xmm0
lea    0xdf7(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%r14d
mov    $0x32,%ebp
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xf4240,%edx
call   10a0 <test_mean2@plt>
add    $0xffffffff,%ebp
jne    1230 <main+0xb0>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xda2(%rip),%xmm0
divsd  (%r15),%xmm0
lea    0xdad(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%r14d
mov    $0x32,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xf4240,%edx
call   1050 <test_mean3@plt>
add    $0xffffffff,%ebp
jne    1290 <main+0x110>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xd42(%rip),%xmm0
divsd  (%r15),%xmm0
lea    0xd5c(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Version 1: %e\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [15 x i8] c"Version 2: %e\0A\00"
@.str.2 = [15 x i8] c"Version 3: %e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x double]
%8 = alloca double*
store i32 0, i32* %1
store i32 1000000, i32* %3
store i32 50, i32* %4
%9 = load i32, i32* %3
%10 = mul nsw i32 2, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %8
store i32 0, i32* %2
br label %16
16: ; preds = %27, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = mul nsw i32 2, %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = call double (...) @random()
%23 = load double*, double** %8
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
store double %22, double* %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %16
30: ; preds = %16
%31 = call i32 (...) @clock()
store i32 %31, i32* %5
store i32 0, i32* %2
br label %32
32: ; preds = %41, %30
%33 = load i32, i32* %2
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 0
%38 = load double*, double** %8
%39 = load i32, i32* %3
%40 = call i32 @test_mean1(double* %37, double* %38, i32 %39)
br label %41
41: ; preds = %36
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %32
44: ; preds = %32
%45 = call i32 (...) @clock()
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = load i32, i32* %5
%48 = sub nsw i32 %46, %47
%49 = sitofp i32 %48 to double
%50 = load i32, i32* %4
%51 = sitofp i32 %50 to double
%52 = fdiv double %49, %51
%53 = load double, double* @CLOCKS_PER_SEC
%54 = fdiv double %52, %53
%55 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %54)
%56 = call i32 (...) @clock()
store i32 %56, i32* %5
store i32 0, i32* %2
br label %57
57: ; preds = %66, %44
%58 = load i32, i32* %2
%59 = load i32, i32* %4
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %69
61: ; preds = %57
%62 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 0
%63 = load double*, double** %8
%64 = load i32, i32* %3
%65 = call i32 @test_mean2(double* %62, double* %63, i32 %64)
br label %66
66: ; preds = %61
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %57
69: ; preds = %57
%70 = call i32 (...) @clock()
store i32 %70, i32* %6
%71 = load i32, i32* %6
%72 = load i32, i32* %5
%73 = sub nsw i32 %71, %72
%74 = sitofp i32 %73 to double
%75 = load i32, i32* %4
%76 = sitofp i32 %75 to double
%77 = fdiv double %74, %76
%78 = load double, double* @CLOCKS_PER_SEC
%79 = fdiv double %77, %78
%80 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %79)
%81 = call i32 (...) @clock()
store i32 %81, i32* %5
store i32 0, i32* %2
br label %82
82: ; preds = %91, %69
%83 = load i32, i32* %2
%84 = load i32, i32* %4
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %94
86: ; preds = %82
%87 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 0
%88 = load double*, double** %8
%89 = load i32, i32* %3
%90 = call i32 @test_mean3(double* %87, double* %88, i32 %89)
br label %91
91: ; preds = %86
%92 = load i32, i32* %2
%93 = add nsw i32 %92, 1
store i32 %93, i32* %2
br label %82
94: ; preds = %82
%95 = call i32 (...) @clock()
store i32 %95, i32* %6
%96 = load i32, i32* %6
%97 = load i32, i32* %5
%98 = sub nsw i32 %96, %97
%99 = sitofp i32 %98 to double
%100 = load i32, i32* %4
%101 = sitofp i32 %100 to double
%102 = fdiv double %99, %101
%103 = load double, double* @CLOCKS_PER_SEC
%104 = fdiv double %102, %103
%105 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %104)
%106 = load double*, double** %8
%107 = call i32 @free(double* %106)
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@.str = [15 x i8] c"Version 1: %e\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [15 x i8] c"Version 2: %e\0A\00"
@.str.2 = [15 x i8] c"Version 3: %e\0A\00"
define i32 @main() {
%1 = alloca [2 x double]
%2 = bitcast [2 x double]* %1 to i8*
%3 = tail call i64 @malloc(i32 16000000)
%4 = inttoptr i64 %3 to double*
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %9, %5 ]
%7 = tail call double (...) @random()
%8 = getelementptr inbounds double, double* %4, i64 %6
store double %7, double* %8
%9 = add nuw nsw i64 %6, 1
%10 = icmp eq i64 %9, 2000000
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = tail call i32 (...) @clock()
%13 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
br label %14
14: ; preds = %11, %14
%15 = phi i32 [ 0, %11 ], [ %17, %14 ]
%16 = call i32 @test_mean1(double* %13, double* %4, i32 1000000)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, 50
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = call i32 (...) @clock()
%21 = sub nsw i32 %20, %12
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, 5.000000e+01
%24 = load double, double* @CLOCKS_PER_SEC
%25 = fdiv double %23, %24
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %25)
%27 = call i32 (...) @clock()
br label %28
28: ; preds = %19, %28
%29 = phi i32 [ 0, %19 ], [ %31, %28 ]
%30 = call i32 @test_mean2(double* %13, double* %4, i32 1000000)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, 50
br i1 %32, label %33, label %28
33: ; preds = %28
%34 = call i32 (...) @clock()
%35 = sub nsw i32 %34, %27
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, 5.000000e+01
%38 = load double, double* @CLOCKS_PER_SEC
%39 = fdiv double %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = call i32 (...) @clock()
br label %42
42: ; preds = %33, %42
%43 = phi i32 [ 0, %33 ], [ %45, %42 ]
%44 = call i32 @test_mean3(double* %13, double* %4, i32 1000000)
%45 = add nuw nsw i32 %43, 1
%46 = icmp eq i32 %45, 50
br i1 %46, label %47, label %42
47: ; preds = %42
%48 = call i32 (...) @clock()
%49 = sub nsw i32 %48, %41
%50 = sitofp i32 %49 to double
%51 = fdiv double %50, 5.000000e+01
%52 = load double, double* @CLOCKS_PER_SEC
%53 = fdiv double %51, %52
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %53)
%55 = call i32 @free(double* %4)
ret i32 0
}