#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;
double RAND_MAX;
scalar_t__ clock();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
int main() {
  int i;
  srand((unsigned)1);
  printf("Start\n");
  double *xy = (double *)malloc(sizeof(double) * (1000000 * 2));
  for (i = 0; i < 2000000; i += 2) {
    xy[i] = (double)rand() / RAND_MAX;
    xy[i + 1] = (double)rand() / RAND_MAX;
  }
  printf("Numbers\n");
  clock_t start, end;
  double centerX = 0.0;
  double centerY = 0.0;
  printf("Average\n");
  start = clock();
  for (i = 0; i < 2000000; i += 2) {
    centerX += xy[i];
    centerY += xy[i + 1];
  }
  centerX *= 0.000001;
  centerY *= 0.000001;
  end = clock();
  printf("Done\n");
  printf("%f %f\n", centerX, centerY);
  printf("%f\n", (double)(end - start) / CLOCKS_PER_SEC);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
call   1050 <srand@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xf42400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1e8480,-0x8(%rbp)
jge    11f4 <main+0xa4>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e34(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e10(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    118c <main+0x3c>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1e8480,-0x8(%rbp)
jge    1280 <main+0x130>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1232 <main+0xe2>
movsd  0xd78(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd66(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xd59(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cff(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd36(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x1,%edi
call   1060 <srand@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    $0xf42400,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0xfffffffffffffffe,%rbx
mov    0x2e46(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x10(%r15,%rbx,8)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x18(%r15,%rbx,8)
add    $0x2,%rbx
cmp    $0x1e847e,%rbx
jb     11a0 <main+0x40>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
xorpd  %xmm1,%xmm1
mov    $0xfffffffffffffffe,%rax
movupd 0x10(%r15,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x20(%r15,%rax,8),%xmm1
addpd  %xmm0,%xmm1
movupd 0x30(%r15,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x40(%r15,%rax,8),%xmm1
addpd  %xmm0,%xmm1
movupd 0x50(%r15,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x60(%r15,%rax,8),%xmm1
addpd  %xmm0,%xmm1
movupd 0x70(%r15,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x80(%r15,%rax,8),%xmm1
addpd  %xmm0,%xmm1
add    $0x10,%rax
cmp    $0x1e847e,%rax
jb     1210 <main+0xb0>
movsd  0xd81(%rip),%xmm0
movapd %xmm1,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
lea    0xd7a(%rip),%rdi
call   1030 <puts@plt>
lea    0xd51(%rip),%rdi
movaps 0x10(%rsp),%xmm0
movaps (%rsp),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    0x2d0f(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd27(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Start\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [9 x i8] c"Numbers\0A\00"
@.str.2 = [9 x i8] c"Average\0A\00"
@.str.3 = [6 x i8] c"Done\0A\00"
@.str.4 = [7 x i8] c"%f %f\0A\00"
@.str.5 = [4 x i8] c"%f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double*
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
%8 = call i32 @srand(i32 1)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @malloc(i32 16000000)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %3
store i32 0, i32* %2
br label %12
12: ; preds = %33, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 2000000
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = call i64 (...) @rand()
%17 = sitofp i64 %16 to double
%18 = load double, double* @RAND_MAX
%19 = fdiv double %17, %18
%20 = load double*, double** %3
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double %19, double* %23
%24 = call i64 (...) @rand()
%25 = sitofp i64 %24 to double
%26 = load double, double* @RAND_MAX
%27 = fdiv double %25, %26
%28 = load double*, double** %3
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %28, i64 %31
store double %27, double* %32
br label %33
33: ; preds = %15
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 2
store i32 %35, i32* %2
br label %12
36: ; preds = %12
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%39 = call i64 (...) @clock()
store i64 %39, i64* %4
store i32 0, i32* %2
br label %40
40: ; preds = %59, %36
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 2000000
br i1 %42, label %43, label %62
43: ; preds = %40
%44 = load double*, double** %3
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double, double* %6
%50 = fadd double %49, %48
store double %50, double* %6
%51 = load double*, double** %3
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = load double, double* %7
%58 = fadd double %57, %56
store double %58, double* %7
br label %59
59: ; preds = %43
%60 = load i32, i32* %2
%61 = add nsw i32 %60, 2
store i32 %61, i32* %2
br label %40
62: ; preds = %40
%63 = load double, double* %6
%64 = fmul double %63, 0x3EB0C6F7A0B5ED8D
store double %64, double* %6
%65 = load double, double* %7
%66 = fmul double %65, 0x3EB0C6F7A0B5ED8D
store double %66, double* %7
%67 = call i64 (...) @clock()
store i64 %67, i64* %5
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%69 = load double, double* %6
%70 = load double, double* %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %69, double %70)
%72 = load i64, i64* %5
%73 = load i64, i64* %4
%74 = sub nsw i64 %72, %73
%75 = sitofp i64 %74 to double
%76 = load double, double* @CLOCKS_PER_SEC
%77 = fdiv double %75, %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %77)
%79 = load i32, i32* %1
ret i32 %79
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@.str.4 = [7 x i8] c"%f %f\0A\00"
@.str.5 = [4 x i8] c"%f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [6 x i8] c"Start\00"
@str.6 = [8 x i8] c"Numbers\00"
@str.7 = [8 x i8] c"Average\00"
@str.8 = [5 x i8] c"Done\00"
define i32 @main() {
%1 = tail call i32 @srand(i32 1)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%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 ], [ %18, %5 ]
%7 = tail call i64 (...) @rand()
%8 = sitofp i64 %7 to double
%9 = load double, double* @RAND_MAX
%10 = fdiv double %8, %9
%11 = getelementptr inbounds double, double* %4, i64 %6
store double %10, double* %11
%12 = tail call i64 (...) @rand()
%13 = sitofp i64 %12 to double
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
%16 = or i64 %6, 1
%17 = getelementptr inbounds double, double* %4, i64 %16
store double %15, double* %17
%18 = add nuw nsw i64 %6, 2
%19 = icmp ult i64 %6, 1999998
br i1 %19, label %5, label %20
20: ; preds = %5
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0))
%23 = tail call i64 (...) @clock()
br label %24
24: ; preds = %24, %20
%25 = phi i64 [ 0, %20 ], [ %66, %24 ]
%26 = phi <2 x double> [ zeroinitializer, %20 ], [ %65, %24 ]
%27 = getelementptr inbounds double, double* %4, i64 %25
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fadd <2 x double> %26, %29
%31 = or i64 %25, 2
%32 = getelementptr inbounds double, double* %4, i64 %31
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = fadd <2 x double> %30, %34
%36 = or i64 %25, 4
%37 = getelementptr inbounds double, double* %4, i64 %36
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fadd <2 x double> %35, %39
%41 = or i64 %25, 6
%42 = getelementptr inbounds double, double* %4, i64 %41
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = fadd <2 x double> %40, %44
%46 = or i64 %25, 8
%47 = getelementptr inbounds double, double* %4, i64 %46
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = fadd <2 x double> %45, %49
%51 = or i64 %25, 10
%52 = getelementptr inbounds double, double* %4, i64 %51
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = fadd <2 x double> %50, %54
%56 = or i64 %25, 12
%57 = getelementptr inbounds double, double* %4, i64 %56
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = fadd <2 x double> %55, %59
%61 = or i64 %25, 14
%62 = getelementptr inbounds double, double* %4, i64 %61
%63 = bitcast double* %62 to <2 x double>*
%64 = load <2 x double>, <2 x double>* %63
%65 = fadd <2 x double> %60, %64
%66 = add nuw nsw i64 %25, 16
%67 = icmp ult i64 %61, 1999998
br i1 %67, label %24, label %68
68: ; preds = %24
%69 = extractelement <2 x double> %65, i64 0
%70 = fmul double %69, 0x3EB0C6F7A0B5ED8D
%71 = extractelement <2 x double> %65, i64 1
%72 = fmul double %71, 0x3EB0C6F7A0B5ED8D
%73 = tail call i64 (...) @clock()
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.8, i64 0, i64 0))
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %70, double %72)
%76 = sub nsw i64 %73, %23
%77 = sitofp i64 %76 to double
%78 = load double, double* @CLOCKS_PER_SEC
%79 = fdiv double %77, %78
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %79)
ret i32 0
}