#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 */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ printf(char *, double, double);
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
int time(int /*<<< orphan*/ *);
int main() {
  int i, seed;
  double sum_0, sum_1, mean, var, x;
  seed = time(NULL);
  srand(seed);
  for (i = 1, sum_0 = 0., sum_1 = 0.; i <= 10000000; i++) {
    x = (double)rand() / (double)RAND_MAX;
    sum_0 += x;
    sum_1 += (x - 0.5) * (x - 0.5);
  }
  mean = sum_0 / (double)10000000;
  var = sum_1 / (double)10000000;
  printf("mean(x) = %12.10f  var(x) = %12.10f\n", mean, var);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <srand@plt>
movl   $0x1,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x989680,-0x8(%rbp)
jg     11f9 <main+0xb9>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e4e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe44(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  0xe33(%rip),%xmm1
subsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <main+0x3a>
movsd  -0x18(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xde4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xdda(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xorpd  %xmm0,%xmm0
mov    $0x989680,%ebx
mov    0x2e83(%rip),%r14
xorpd  %xmm1,%xmm1
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm2
movsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
addsd  0xe57(%rip),%xmm2
mulsd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
movsd  0xe38(%rip),%xmm2
divsd  %xmm2,%xmm0
divsd  %xmm2,%xmm1
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
%9 = call i32 @time(i32* null)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @srand(i32 %10)
store i32 1, i32* %2
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
br label %12
12: ; preds = %30, %0
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 10000000
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = call i64 (...) @rand()
%17 = sitofp i64 %16 to double
%18 = load i64, i64* @RAND_MAX
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %8
%21 = load double, double* %8
%22 = load double, double* %4
%23 = fadd double %22, %21
store double %23, double* %4
%24 = load double, double* %8
%25 = fsub double %24, 5.000000e-01
%26 = load double, double* %8
%27 = fsub double %26, 5.000000e-01
%28 = load double, double* %5
%29 = call double @llvm.fmuladd.f64(double %25, double %27, double %28)
store double %29, double* %5
br label %30
30: ; preds = %15
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %12
33: ; preds = %12
%34 = load double, double* %4
%35 = fdiv double %34, 1.000000e+07
store double %35, double* %6
%36 = load double, double* %5
%37 = fdiv double %36, 1.000000e+07
store double %37, double* %7
%38 = load double, double* %6
%39 = load double, double* %7
%40 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %38, double %39)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 1, %0 ], [ %15, %3 ]
%5 = phi double [ 0.000000e+00, %0 ], [ %12, %3 ]
%6 = phi double [ 0.000000e+00, %0 ], [ %14, %3 ]
%7 = tail call i64 (...) @rand()
%8 = sitofp i64 %7 to double
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to double
%11 = fdiv double %8, %10
%12 = fadd double %5, %11
%13 = fadd double %11, -5.000000e-01
%14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %6)
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 10000001
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = fdiv double %12, 1.000000e+07
%19 = fdiv double %14, 1.000000e+07
%20 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %18, double %19)
ret i32 0
}