#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 *xarr = (double *)malloc(sizeof(double) * (1000000));
  double *yarr = (double *)malloc(sizeof(double) * (1000000));
  for (i = 0; i < 1000000; i++) {
    xarr[i] = (double)rand() / RAND_MAX;
    yarr[i] = (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 < 1000000; i++) {
    centerX += xarr[i];
  }
  for (i = 0; i < 1000000; i++) {
    centerY += yarr[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    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    11fd <main+0xad>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e2e(%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    0x2e0a(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x4a>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    126c <main+0x11c>
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    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    123a <main+0xea>
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    12a5 <main+0x155>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1273 <main+0x123>
movsd  0xd53(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd41(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x20(%rbp)
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xd35(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
sub    -0x1c(%rbp),%esi
lea    0xd28(%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   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
call   1060 <srand@plt>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7a1200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    $0x7a1200,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    0x2e47(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    11b0 <main+0x50>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%r14d
xorpd  %xmm1,%xmm1
mov    $0x7,%eax
nopl   0x0(%rax)
addsd  -0x38(%rbp,%rax,8),%xmm1
addsd  -0x30(%rbp,%rax,8),%xmm1
addsd  -0x28(%rbp,%rax,8),%xmm1
addsd  -0x20(%rbp,%rax,8),%xmm1
addsd  -0x18(%rbp,%rax,8),%xmm1
addsd  -0x10(%rbp,%rax,8),%xmm1
addsd  -0x8(%rbp,%rax,8),%xmm1
addsd  0x0(%rbp,%rax,8),%xmm1
add    $0x8,%rax
cmp    $0xf4247,%rax
jne    1220 <main+0xc0>
xorpd  %xmm2,%xmm2
mov    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
nop
addsd  -0x38(%r15,%rax,8),%xmm2
addsd  -0x30(%r15,%rax,8),%xmm2
addsd  -0x28(%r15,%rax,8),%xmm2
addsd  -0x20(%r15,%rax,8),%xmm2
addsd  -0x18(%r15,%rax,8),%xmm2
addsd  -0x10(%r15,%rax,8),%xmm2
addsd  -0x8(%r15,%rax,8),%xmm2
addsd  (%r15,%rax,8),%xmm2
add    $0x8,%rax
cmp    $0xf4247,%rax
jne    1270 <main+0x110>
movsd  0xd45(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebx
lea    0xd4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xd1d(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
sub    %r14d,%ebx
lea    0xd07(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
%9 = call i32 @srand(i32 1)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = call i64 @malloc(i32 8000000)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %3
%13 = call i64 @malloc(i32 8000000)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %4
store i32 0, i32* %2
br label %15
15: ; preds = %35, %0
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 1000000
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load double, double* @RAND_MAX
%22 = fdiv double %20, %21
%23 = load double*, double** %3
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
store double %22, double* %26
%27 = call i64 (...) @rand()
%28 = sitofp i64 %27 to double
%29 = load double, double* @RAND_MAX
%30 = fdiv double %28, %29
%31 = load double*, double** %4
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
br label %35
35: ; preds = %18
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %15
38: ; preds = %15
%39 = 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* %7
store double 0.000000e+00, double* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 (...) @clock()
store i32 %41, i32* %5
store i32 0, i32* %2
br label %42
42: ; preds = %53, %38
%43 = load i32, i32* %2
%44 = icmp slt i32 %43, 1000000
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load double*, double** %3
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double, double* %7
%52 = fadd double %51, %50
store double %52, double* %7
br label %53
53: ; preds = %45
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %42
56: ; preds = %42
store i32 0, i32* %2
br label %57
57: ; preds = %68, %56
%58 = load i32, i32* %2
%59 = icmp slt i32 %58, 1000000
br i1 %59, label %60, label %71
60: ; preds = %57
%61 = load double*, double** %4
%62 = load i32, i32* %2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = load double, double* %8
%67 = fadd double %66, %65
store double %67, double* %8
br label %68
68: ; preds = %60
%69 = load i32, i32* %2
%70 = add nsw i32 %69, 1
store i32 %70, i32* %2
br label %57
71: ; preds = %57
%72 = load double, double* %7
%73 = fmul double %72, 0x3EB0C6F7A0B5ED8D
store double %73, double* %7
%74 = load double, double* %8
%75 = fmul double %74, 0x3EB0C6F7A0B5ED8D
store double %75, double* %8
%76 = call i32 (...) @clock()
store i32 %76, i32* %6
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%78 = load double, double* %7
%79 = load double, double* %8
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %78, double %79)
%81 = load i32, i32* %6
%82 = load i32, i32* %5
%83 = sub nsw i32 %81, %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %1
ret i32 %85
}

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