#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 int clock_t;

/* Variables and functions */
double RAND_MAX;
int 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];
  }
  for (i = 1; i < 2000000; i += 2) {
    centerY += xy[i];
  }
  centerX *= 0.000001;
  centerY *= 0.000001;
  end = clock();
  printf("Done\n");
  printf("%f %f\n", centerX, centerY);
  printf("%d\n", end - start);
}


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    0x2e3c(%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    0x2e18(%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,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1e8480,-0x8(%rbp)
jge    1263 <main+0x113>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1231 <main+0xe1>
movl   $0x1,-0x8(%rbp)
cmpl   $0x1e8480,-0x8(%rbp)
jge    129c <main+0x14c>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    126a <main+0x11a>
movsd  0xd5c(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd4a(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x18(%rbp)
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xd3e(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
sub    -0x14(%rbp),%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
call   1060 <srand@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xf42400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0xfffffffffffffffe,%rbp
mov    0x2e4f(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x10(%rbx,%rbp,8)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x18(%rbx,%rbp,8)
add    $0x2,%rbp
cmp    $0x1e847e,%rbp
jb     11a0 <main+0x40>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebp
xorpd  %xmm1,%xmm1
mov    $0xfffffffffffffffe,%rax
nopl   (%rax)
addsd  0x10(%rbx,%rax,8),%xmm1
addsd  0x20(%rbx,%rax,8),%xmm1
addsd  0x30(%rbx,%rax,8),%xmm1
addsd  0x40(%rbx,%rax,8),%xmm1
addsd  0x50(%rbx,%rax,8),%xmm1
addsd  0x60(%rbx,%rax,8),%xmm1
addsd  0x70(%rbx,%rax,8),%xmm1
addsd  0x80(%rbx,%rax,8),%xmm1
add    $0x10,%rax
cmp    $0x1e847e,%rax
jb     1210 <main+0xb0>
xorpd  %xmm2,%xmm2
mov    $0xfffffffffffffff1,%rax
nopw   0x0(%rax,%rax,1)
addsd  0x80(%rbx,%rax,8),%xmm2
addsd  0x90(%rbx,%rax,8),%xmm2
addsd  0xa0(%rbx,%rax,8),%xmm2
addsd  0xb0(%rbx,%rax,8),%xmm2
addsd  0xc0(%rbx,%rax,8),%xmm2
addsd  0xd0(%rbx,%rax,8),%xmm2
addsd  0xe0(%rbx,%rax,8),%xmm2
addsd  0xf0(%rbx,%rax,8),%xmm2
add    $0x10,%rax
cmp    $0x1e8470,%rax
jb     1260 <main+0x100>
movsd  0xd44(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebx
lea    0xd4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xd1d(%rip),%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
sub    %ebp,%ebx
lea    0xd09(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%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 i32 (...) @clock()
store i32 %39, i32* %4
store i32 0, i32* %2
br label %40
40: ; preds = %51, %36
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 2000000
br i1 %42, label %43, label %54
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
br label %51
51: ; preds = %43
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 2
store i32 %53, i32* %2
br label %40
54: ; preds = %40
store i32 1, i32* %2
br label %55
55: ; preds = %66, %54
%56 = load i32, i32* %2
%57 = icmp slt i32 %56, 2000000
br i1 %57, label %58, label %69
58: ; preds = %55
%59 = load double*, double** %3
%60 = load i32, i32* %2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = load double, double* %7
%65 = fadd double %64, %63
store double %65, double* %7
br label %66
66: ; preds = %58
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 2
store i32 %68, i32* %2
br label %55
69: ; preds = %55
%70 = load double, double* %6
%71 = fmul double %70, 0x3EB0C6F7A0B5ED8D
store double %71, double* %6
%72 = load double, double* %7
%73 = fmul double %72, 0x3EB0C6F7A0B5ED8D
store double %73, double* %7
%74 = call i32 (...) @clock()
store i32 %74, i32* %5
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%76 = load double, double* %6
%77 = load double, double* %7
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %76, double %77)
%79 = load i32, i32* %5
%80 = load i32, i32* %4
%81 = sub nsw i32 %79, %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %1
ret i32 %83
}

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"%d\0A\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 i32 (...) @clock()
br label %24
24: ; preds = %24, %20
%25 = phi i64 [ 0, %20 ], [ %58, %24 ]
%26 = phi double [ 0.000000e+00, %20 ], [ %57, %24 ]
%27 = getelementptr inbounds double, double* %4, i64 %25
%28 = load double, double* %27
%29 = fadd double %26, %28
%30 = or i64 %25, 2
%31 = getelementptr inbounds double, double* %4, i64 %30
%32 = load double, double* %31
%33 = fadd double %29, %32
%34 = or i64 %25, 4
%35 = getelementptr inbounds double, double* %4, i64 %34
%36 = load double, double* %35
%37 = fadd double %33, %36
%38 = or i64 %25, 6
%39 = getelementptr inbounds double, double* %4, i64 %38
%40 = load double, double* %39
%41 = fadd double %37, %40
%42 = or i64 %25, 8
%43 = getelementptr inbounds double, double* %4, i64 %42
%44 = load double, double* %43
%45 = fadd double %41, %44
%46 = or i64 %25, 10
%47 = getelementptr inbounds double, double* %4, i64 %46
%48 = load double, double* %47
%49 = fadd double %45, %48
%50 = or i64 %25, 12
%51 = getelementptr inbounds double, double* %4, i64 %50
%52 = load double, double* %51
%53 = fadd double %49, %52
%54 = or i64 %25, 14
%55 = getelementptr inbounds double, double* %4, i64 %54
%56 = load double, double* %55
%57 = fadd double %53, %56
%58 = add nuw nsw i64 %25, 16
%59 = icmp ult i64 %54, 1999998
br i1 %59, label %24, label %60
60: ; preds = %24, %60
%61 = phi i64 [ %94, %60 ], [ 1, %24 ]
%62 = phi double [ %93, %60 ], [ 0.000000e+00, %24 ]
%63 = getelementptr inbounds double, double* %4, i64 %61
%64 = load double, double* %63
%65 = fadd double %62, %64
%66 = add nuw nsw i64 %61, 2
%67 = getelementptr inbounds double, double* %4, i64 %66
%68 = load double, double* %67
%69 = fadd double %65, %68
%70 = add nuw nsw i64 %61, 4
%71 = getelementptr inbounds double, double* %4, i64 %70
%72 = load double, double* %71
%73 = fadd double %69, %72
%74 = add nuw nsw i64 %61, 6
%75 = getelementptr inbounds double, double* %4, i64 %74
%76 = load double, double* %75
%77 = fadd double %73, %76
%78 = add nuw nsw i64 %61, 8
%79 = getelementptr inbounds double, double* %4, i64 %78
%80 = load double, double* %79
%81 = fadd double %77, %80
%82 = add nuw nsw i64 %61, 10
%83 = getelementptr inbounds double, double* %4, i64 %82
%84 = load double, double* %83
%85 = fadd double %81, %84
%86 = add nuw nsw i64 %61, 12
%87 = getelementptr inbounds double, double* %4, i64 %86
%88 = load double, double* %87
%89 = fadd double %85, %88
%90 = add nuw nsw i64 %61, 14
%91 = getelementptr inbounds double, double* %4, i64 %90
%92 = load double, double* %91
%93 = fadd double %89, %92
%94 = add nuw nsw i64 %61, 16
%95 = icmp ult i64 %61, 1999984
br i1 %95, label %60, label %96
96: ; preds = %60
%97 = fmul double %57, 0x3EB0C6F7A0B5ED8D
%98 = fmul double %93, 0x3EB0C6F7A0B5ED8D
%99 = tail call i32 (...) @clock()
%100 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.8, i64 0, i64 0))
%101 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %97, double %98)
%102 = sub nsw i32 %99, %23
%103 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %102)
ret i32 0
}