#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 *, ...);
scalar_t__ rand();
int /*<<< orphan*/ randommeanvar(int);
int /*<<< orphan*/ srand(int);
int time(int /*<<< orphan*/ *);
int main() {
  int i, seed;
  double sum_0, sum_1, mean, var, x;
  seed = time(NULL);
  printf("\nThis is seed's value (which is time(NULL)), in decimal, string, "
         "and float, resp.:\n");
  printf("%d \n", seed);
  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);
  printf("\nN=10:\n");
  randommeanvar(10);
  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   1060 <time@plt>
mov    %eax,-0xc(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <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     1228 <main+0xd8>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e1f(%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  0xe15(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  0xe04(%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    11a9 <main+0x59>
movsd  -0x18(%rbp),%xmm0
movsd  0xdcb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe04(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <randommeanvar@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   1070 <time@plt>
mov    %eax,%ebx
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <srand@plt>
xorpd  %xmm0,%xmm0
mov    $0x989680,%ebx
mov    0x2e45(%rip),%r14
xorpd  %xmm1,%xmm1
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <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  0xe17(%rip),%xmm2
mulsd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
add    $0xffffffff,%ebx
jne    11b0 <main+0x50>
movsd  0xdf8(%rip),%xmm2
divsd  %xmm2,%xmm0
divsd  %xmm2,%xmm1
lea    0xdf6(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1040 <randommeanvar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [84 x i8] c"\0AThis is seed's value (which is time(NULL)), in decimal, string, and float, resp.:\0A\00"
@.str.1 = [5 x i8] c"%d \0A\00"
@RAND_MAX = global i64 0
@.str.2 = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
@.str.3 = [8 x i8] c"\0AN=10:\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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = call i32 @srand(i32 %13)
store i32 1, i32* %2
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
br label %15
15: ; preds = %33, %0
%16 = load i32, i32* %2
%17 = icmp sle i32 %16, 10000000
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %8
%24 = load double, double* %8
%25 = load double, double* %4
%26 = fadd double %25, %24
store double %26, double* %4
%27 = load double, double* %8
%28 = fsub double %27, 5.000000e-01
%29 = load double, double* %8
%30 = fsub double %29, 5.000000e-01
%31 = load double, double* %5
%32 = call double @llvm.fmuladd.f64(double %28, double %30, double %31)
store double %32, double* %5
br label %33
33: ; preds = %18
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %15
36: ; preds = %15
%37 = load double, double* %4
%38 = fdiv double %37, 1.000000e+07
store double %38, double* %6
%39 = load double, double* %5
%40 = fdiv double %39, 1.000000e+07
store double %40, double* %7
%41 = load double, double* %6
%42 = load double, double* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double %41, double %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @randommeanvar(i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d \0A\00"
@RAND_MAX = global i64 0
@.str.2 = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
@str = [83 x i8] c"\0AThis is seed's value (which is time(NULL)), in decimal, string, and float, resp.:\00"
@str.4 = [7 x i8] c"\0AN=10:\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%4 = tail call i32 @srand(i32 %1)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 1, %0 ], [ %17, %5 ]
%7 = phi double [ 0.000000e+00, %0 ], [ %14, %5 ]
%8 = phi double [ 0.000000e+00, %0 ], [ %16, %5 ]
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load i64, i64* @RAND_MAX
%12 = sitofp i64 %11 to double
%13 = fdiv double %10, %12
%14 = fadd double %7, %13
%15 = fadd double %13, -5.000000e-01
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %8)
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, 10000001
br i1 %18, label %19, label %5
19: ; preds = %5
%20 = fdiv double %14, 1.000000e+07
%21 = fdiv double %16, 1.000000e+07
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double %20, double %21)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0))
%24 = tail call i32 @randommeanvar(i32 10)
ret i32 0
}