#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, ...);
scalar_t__ rand();
int randommeanvar(int N) {
  double sum_0, sum_1, mean, var, x;
  for (int i = 1, sum_0 = 0., sum_1 = 0.; i <= N; i++) {
    x = (double)rand() / (double)RAND_MAX;
    printf("\nx: %f\n", x);
    sum_0 += x;
    sum_1 += (x - 0.5) * (x - 0.5);
    printf("\nsum_0, sum_1: %f %f \n", sum_0, sum_1);
  }
  mean = sum_0 / (double)N;
  var = sum_1 / (double)N;
  printf("mean(x) = %12.10f  var(x) = %12.10f\n", mean, var);
  return 0;
}


x86 assembly (clang, -O0):
<randommeanvar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11ef <randommeanvar+0xcf>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e89(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe8f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm1
cvtsi2sdl -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xe4d(%rip),%xmm1
subsd  %xmm1,%xmm2
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x3c(%rbp)
cvtsi2sdl -0x38(%rbp),%xmm0
mov    -0x3c(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1140 <randommeanvar+0x20>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xe01(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randommeanvar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11c5 <randommeanvar+0xa5>
mov    %edi,%ebx
mov    0x2eac(%rip),%r12
lea    0xecd(%rip),%r14
lea    0xece(%rip),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
nop
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r12),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm2,%xmm0
cvttsd2si %xmm0,%r13d
addsd  0xe67(%rip),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ebp
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0xffffffff,%ebx
jne    1150 <randommeanvar+0x30>
lea    0xe63(%rip),%rdi
movsd  0xe34(%rip),%xmm0
movaps %xmm0,%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [8 x i8] c"\0Ax: %f\0A\00"
@.str.1 = [23 x i8] c"\0Asum_0, sum_1: %f %f \0A\00"
@.str.2 = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
define i32 @randommeanvar(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %40, %1
%12 = load i32, i32* %8
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %43
15: ; preds = %11
%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* %7
%21 = load double, double* %7
%22 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %21)
%23 = load double, double* %7
%24 = load i32, i32* %9
%25 = sitofp i32 %24 to double
%26 = fadd double %25, %23
%27 = fptosi double %26 to i32
store i32 %27, i32* %9
%28 = load double, double* %7
%29 = fsub double %28, 5.000000e-01
%30 = load double, double* %7
%31 = fsub double %30, 5.000000e-01
%32 = load i32, i32* %10
%33 = sitofp i32 %32 to double
%34 = call double @llvm.fmuladd.f64(double %29, double %31, double %33)
%35 = fptosi double %34 to i32
store i32 %35, i32* %10
%36 = load i32, i32* %9
%37 = sitofp i32 %36 to double
%38 = load i32, i32* %10
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %37, i32 %38)
br label %40
40: ; preds = %15
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %11
43: ; preds = %11
%44 = load double, double* %3
%45 = load i32, i32* %2
%46 = sitofp i32 %45 to double
%47 = fdiv double %44, %46
store double %47, double* %5
%48 = load double, double* %4
%49 = load i32, i32* %2
%50 = sitofp i32 %49 to double
%51 = fdiv double %48, %50
store double %51, double* %6
%52 = load double, double* %5
%53 = load double, double* %6
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double %52, double %53)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [8 x i8] c"\0Ax: %f\0A\00"
@.str.1 = [23 x i8] c"\0Asum_0, sum_1: %f %f \0A\00"
@.str.2 = [37 x i8] c"mean(x) = %12.10f var(x) = %12.10f\0A\00"
define i32 @randommeanvar(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %5
3: ; preds = %5, %1
%4 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double 0x7FF8000000000000, double 0x7FF8000000000000)
ret i32 0
5: ; preds = %1, %5
%6 = phi i32 [ %21, %5 ], [ 0, %1 ]
%7 = phi i32 [ %17, %5 ], [ 0, %1 ]
%8 = phi i32 [ %24, %5 ], [ 1, %1 ]
%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 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %13)
%15 = sitofp i32 %7 to double
%16 = fadd double %13, %15
%17 = fptosi double %16 to i32
%18 = fadd double %13, -5.000000e-01
%19 = sitofp i32 %6 to double
%20 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %19)
%21 = fptosi double %20 to i32
%22 = sitofp i32 %17 to double
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %22, i32 %21)
%24 = add nuw i32 %8, 1
%25 = icmp eq i32 %8, %0
br i1 %25, label %3, label %5
}