#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 /*<<< orphan*/ FILE;

/* Variables and functions */
double M_PI;
scalar_t__ RAND_MAX;
int exp(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
scalar_t__ rand();
int sqrt(double);
int main() {
  double u, y;
  double c = 2.5;
  int i = 0;
  FILE *f = fopen("rand_normal.dat", "w");
  while (i < 100000) {
    u = ((double)rand() / (double)RAND_MAX);
    y = ((double)rand() / (double)RAND_MAX) * 10.0 - 5.0;
    if (u <= ((1 / sqrt(2.0 * M_PI)) * exp(y * y / -2.0))) {
      i++;
      fprintf(f, "%.12e\n", y);
    }
  }
  fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe9e(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x186a0,-0x24(%rbp)
jge    1289 <main+0x129>
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e26(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e05(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe2c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe28(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdfd(%rip),%xmm0
mov    0x2dce(%rip),%rax
mulsd  (%rax),%xmm0
call   1070 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  -0x40(%rbp),%xmm1
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jb     1284 <main+0x124>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xdbb(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119a <main+0x3a>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea3(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
xor    %r12d,%r12d
mov    0x2e52(%rip),%rbp
mov    0x2e53(%rip),%r13
xor    %r14d,%r14d
jmp    11ad <main+0x4d>
nopw   0x0(%rax,%rax,1)
cmp    $0x186a0,%r14d
jge    1267 <main+0x107>
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
mulsd  0xe0d(%rip),%xmm1
addsd  0xe0d(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x0(%r13),%xmm0
addsd  %xmm0,%xmm0
call   1070 <sqrt@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%eax
cmp    $0x3,%eax
cmovae %r12d,%ebx
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xde2(%rip),%xmm0
call   1050 <exp@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0x10(%rsp),%xmm0
jb     11a0 <main+0x40>
add    $0x1,%r14d
mov    %r15,%rdi
lea    0xdd3(%rip),%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <fprintf@plt>
jmp    11a0 <main+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"rand_normal.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
@.str.2 = [7 x i8] c"%.12e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store double 2.500000e+00, double* %4
store i32 0, i32* %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
br label %8
8: ; preds = %42, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 100000
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = call i64 (...) @rand()
%13 = sitofp i64 %12 to double
%14 = load i64, i64* @RAND_MAX
%15 = sitofp i64 %14 to double
%16 = fdiv double %13, %15
store double %16, double* %2
%17 = call i64 (...) @rand()
%18 = sitofp i64 %17 to double
%19 = load i64, i64* @RAND_MAX
%20 = sitofp i64 %19 to double
%21 = fdiv double %18, %20
%22 = call double @llvm.fmuladd.f64(double %21, double 1.000000e+01, double -5.000000e+00)
store double %22, double* %3
%23 = load double, double* %2
%24 = load double, double* @M_PI
%25 = fmul double 2.000000e+00, %24
%26 = call i32 @sqrt(double %25)
%27 = sdiv i32 1, %26
%28 = load double, double* %3
%29 = load double, double* %3
%30 = fmul double %28, %29
%31 = fdiv double %30, -2.000000e+00
%32 = call i32 @exp(double %31)
%33 = mul nsw i32 %27, %32
%34 = sitofp i32 %33 to double
%35 = fcmp ole double %23, %34
br i1 %35, label %36, label %42
36: ; preds = %11
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
%39 = load i32*, i32** %6
%40 = load double, double* %3
%41 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %36, %11
br label %8
43: ; preds = %8
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
ret i32 -1
}

LLVM IR (-O2):
@.str = [16 x i8] c"rand_normal.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
@.str.2 = [7 x i8] c"%.12e\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %30
%3 = phi i32 [ 0, %0 ], [ %31, %30 ]
%4 = tail call i64 (...) @rand()
%5 = sitofp i64 %4 to double
%6 = load i64, i64* @RAND_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
%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 double @llvm.fmuladd.f64(double %13, double 1.000000e+01, double -5.000000e+00)
%15 = load double, double* @M_PI
%16 = fmul double %15, 2.000000e+00
%17 = tail call i32 @sqrt(double %16)
%18 = add i32 %17, 1
%19 = icmp ult i32 %18, 3
%20 = select i1 %19, i32 %17, i32 0
%21 = fmul double %14, %14
%22 = fmul double %21, -5.000000e-01
%23 = tail call i32 @exp(double %22)
%24 = mul nsw i32 %20, %23
%25 = sitofp i32 %24 to double
%26 = fcmp ugt double %8, %25
br i1 %26, label %30, label %27
27: ; preds = %2
%28 = add nsw i32 %3, 1
%29 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %30
30: ; preds = %27, %2
%31 = phi i32 [ %28, %27 ], [ %3, %2 ]
%32 = icmp slt i32 %31, 100000
br i1 %32, label %2, label %33
33: ; preds = %30
%34 = tail call i32 @fclose(i32* %1)
ret i32 -1
}