#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 */
double RAND_MAX;
int log(double);
scalar_t__ rand();
double sqrt(int);
double randn() {
  static bool reserve_ready = false;
  static double reserve;
  if (reserve_ready) {
    reserve_ready = false;
    return reserve;
  }
  double u1, u2, w;
  do {
    u1 = ((double)rand() / RAND_MAX) * 2. - 1.;
    u2 = ((double)rand() / RAND_MAX) * 2. - 1.;
    w = u1 * u1 + u2 * u2;
  } while (w >= 1 || w == 0);
  reserve = u1 * sqrt((-2 * log(w)) / w);
  reserve_ready = true;
  return u2 * sqrt(-2 * log(w) / w);
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1161 <randn+0x31>
movl   $0x0,0x2ef1(%rip)
movsd  0x2ef1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a4 <randn+0x174>
jmp    1166 <randn+0x36>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e6f(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe77(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e43(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe1a(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    1212 <randn+0xe2>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1166 <randn+0x36>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2deb(%rip)
movl   $0x1,0x2dd9(%rip)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
push   %rbx
sub    $0x20,%rsp
cmpb   $0x0,0x2f04(%rip)
je     1152 <randn+0x22>
movb   $0x0,0x2efb(%rip)
movsd  0x2efb(%rip),%xmm1
jmp    1247 <randn+0x117>
mov    0x2e8f(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe81(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
addsd  0xe58(%rip),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe42(%rip),%xmm0
jae    1160 <randn+0x30>
ucomisd 0xe40(%rip),%xmm0
jne    11d4 <randn+0xa4>
jnp    1160 <randn+0x30>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e37(%rip)
movb   $0x1,0x2e28(%rip)
movsd  0x8(%rsp),%xmm0
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@randn.reserve_ready = internal global i32 0
@randn.reserve = internal global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
define double @randn() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = load i32, i32* @randn.reserve_ready
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
store i32 0, i32* @randn.reserve_ready
%8 = load double, double* @randn.reserve
store double %8, double* %1
br label %56
9: ; preds = %0
br label %10
10: ; preds = %33, %9
%11 = call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
%15 = call double @llvm.fmuladd.f64(double %14, double 2.000000e+00, double -1.000000e+00)
store double %15, double* %2
%16 = call i64 (...) @rand()
%17 = sitofp i64 %16 to double
%18 = load double, double* @RAND_MAX
%19 = fdiv double %17, %18
%20 = call double @llvm.fmuladd.f64(double %19, double 2.000000e+00, double -1.000000e+00)
store double %20, double* %3
%21 = load double, double* %2
%22 = load double, double* %2
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fmul double %23, %24
%26 = call double @llvm.fmuladd.f64(double %21, double %22, double %25)
store double %26, double* %4
br label %27
27: ; preds = %10
%28 = load double, double* %4
%29 = fcmp oge double %28, 1.000000e+00
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load double, double* %4
%32 = fcmp oeq double %31, 0.000000e+00
br label %33
33: ; preds = %30, %27
%34 = phi i1 [ true, %27 ], [ %32, %30 ]
br i1 %34, label %10, label %35
35: ; preds = %33
%36 = load double, double* %2
%37 = load double, double* %4
%38 = call i32 @log(double %37)
%39 = mul nsw i32 -2, %38
%40 = sitofp i32 %39 to double
%41 = load double, double* %4
%42 = fdiv double %40, %41
%43 = fptosi double %42 to i32
%44 = call double @sqrt(i32 %43)
%45 = fmul double %36, %44
store double %45, double* @randn.reserve
store i32 1, i32* @randn.reserve_ready
%46 = load double, double* %3
%47 = load double, double* %4
%48 = call i32 @log(double %47)
%49 = mul nsw i32 -2, %48
%50 = sitofp i32 %49 to double
%51 = load double, double* %4
%52 = fdiv double %50, %51
%53 = fptosi double %52 to i32
%54 = call double @sqrt(i32 %53)
%55 = fmul double %46, %54
store double %55, double* %1
br label %56
56: ; preds = %35, %7
%57 = load double, double* %1
ret double %57
}

LLVM IR (-O2):
@randn.reserve_ready = internal unnamed_addr global i1 false
@randn.reserve = internal unnamed_addr global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
define double @randn() {
%1 = load i1, i1* @randn.reserve_ready
br i1 %1, label %2, label %4
2: ; preds = %0
store i1 false, i1* @randn.reserve_ready
%3 = load double, double* @randn.reserve
br label %35
4: ; preds = %0, %4
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+00, double -1.000000e+00)
%15 = fmul double %14, %14
%16 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %15)
%17 = fcmp oge double %16, 1.000000e+00
%18 = fcmp oeq double %16, 0.000000e+00
%19 = or i1 %17, %18
br i1 %19, label %4, label %20
20: ; preds = %4
%21 = tail call i32 @log(double %16)
%22 = mul nsw i32 %21, -2
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, %16
%25 = fptosi double %24 to i32
%26 = tail call double @sqrt(i32 %25)
%27 = fmul double %9, %26
store double %27, double* @randn.reserve
store i1 true, i1* @randn.reserve_ready
%28 = tail call i32 @log(double %16)
%29 = mul nsw i32 %28, -2
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, %16
%32 = fptosi double %31 to i32
%33 = tail call double @sqrt(i32 %32)
%34 = fmul double %14, %33
br label %35
35: ; preds = %20, %2
%36 = phi double [ %3, %2 ], [ %34, %20 ]
ret double %36
}