#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 log(double);
double rand_uint32();
double sqrt(double);
double rand_norm(void) {
  static int iset = 0;
  static double gset = 0.0;
  if (iset) {
    iset = 0;
    return gset;
  } else {
    double v1, v2, rsq, fac;
    do {
      v1 = (rand_uint32() + 0.5) / 2147483649.0 - 1.0;
      v2 = (rand_uint32() + 0.5) / 2147483649.0 - 1.0;
      rsq = v1 * v1 + v2 * v2;
    } while (rsq == 0.0 || rsq >= 1.0);
    fac = sqrt(-2.0 * log(rsq) / rsq);
    gset = v1 * fac;
    iset = 1;
    return v2 * fac;
  }
}


x86 assembly (clang, -O0):
<rand_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1161 <rand_norm+0x31>
movl   $0x0,0x2ef1(%rip)
movsd  0x2ef1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127e <rand_norm+0x14e>
jmp    1166 <rand_norm+0x36>
mov    $0x0,%al
call   1040 <rand_uint32@plt>
movsd  0xe9b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe87(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe73(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand_uint32@plt>
movsd  0xe6b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe57(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe43(%rip),%xmm1
subsd  %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
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jne    1209 <rand_norm+0xd9>
jp     1209 <rand_norm+0xd9>
jmp    1220 <rand_norm+0xf0>
movsd  -0x20(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1166 <rand_norm+0x36>
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdd8(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2de3(%rip)
movl   $0x1,0x2dd1(%rip)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_norm>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <rand_norm+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm1
jmp    1238 <rand_norm+0x108>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_uint32@plt>
movapd %xmm0,%xmm1
movsd  0xe8d(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe85(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <rand_uint32@plt>
addsd  0xe5d(%rip),%xmm0
divsd  0xe5d(%rip),%xmm0
addsd  0xe5d(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe58(%rip),%xmm2
jne    11d4 <rand_norm+0xa4>
jnp    1160 <rand_norm+0x30>
ucomisd 0xe3c(%rip),%xmm2
jae    1160 <rand_norm+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe25(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1211 <rand_norm+0xe1>
sqrtsd %xmm0,%xmm0
jmp    1216 <rand_norm+0xe6>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e21(%rip)
movb   $0x1,0x2e12(%rip)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@rand_norm.iset = internal global i32 0
@rand_norm.gset = internal global double 0.000000e+00
define double @rand_norm() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = load i32, i32* @rand_norm.iset
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
store i32 0, i32* @rand_norm.iset
%9 = load double, double* @rand_norm.gset
store double %9, double* %1
br label %47
10: ; preds = %0
br label %11
11: ; preds = %32, %10
%12 = call double (...) @rand_uint32()
%13 = fadd double %12, 5.000000e-01
%14 = fdiv double %13, 0x41E0000000200000
%15 = fsub double %14, 1.000000e+00
store double %15, double* %2
%16 = call double (...) @rand_uint32()
%17 = fadd double %16, 5.000000e-01
%18 = fdiv double %17, 0x41E0000000200000
%19 = fsub double %18, 1.000000e+00
store double %19, double* %3
%20 = load double, double* %2
%21 = load double, double* %2
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fmul double %22, %23
%25 = call double @llvm.fmuladd.f64(double %20, double %21, double %24)
store double %25, double* %4
br label %26
26: ; preds = %11
%27 = load double, double* %4
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load double, double* %4
%31 = fcmp oge double %30, 1.000000e+00
br label %32
32: ; preds = %29, %26
%33 = phi i1 [ true, %26 ], [ %31, %29 ]
br i1 %33, label %11, label %34
34: ; preds = %32
%35 = load double, double* %4
%36 = call double @log(double %35)
%37 = fmul double -2.000000e+00, %36
%38 = load double, double* %4
%39 = fdiv double %37, %38
%40 = call double @sqrt(double %39)
store double %40, double* %5
%41 = load double, double* %2
%42 = load double, double* %5
%43 = fmul double %41, %42
store double %43, double* @rand_norm.gset
store i32 1, i32* @rand_norm.iset
%44 = load double, double* %3
%45 = load double, double* %5
%46 = fmul double %44, %45
store double %46, double* %1
br label %47
47: ; preds = %34, %8
%48 = load double, double* %1
ret double %48
}

LLVM IR (-O2):
@rand_norm.iset = internal unnamed_addr global i1 false
@rand_norm.gset = internal unnamed_addr global double 0.000000e+00
define double @rand_norm() {
%1 = load i1, i1* @rand_norm.iset
br i1 %1, label %2, label %4
2: ; preds = %0
store i1 false, i1* @rand_norm.iset
%3 = load double, double* @rand_norm.gset
br label %25
4: ; preds = %0, %4
%5 = tail call double (...) @rand_uint32()
%6 = fadd double %5, 5.000000e-01
%7 = fdiv double %6, 0x41E0000000200000
%8 = fadd double %7, -1.000000e+00
%9 = tail call double (...) @rand_uint32()
%10 = fadd double %9, 5.000000e-01
%11 = fdiv double %10, 0x41E0000000200000
%12 = fadd double %11, -1.000000e+00
%13 = fmul double %12, %12
%14 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %13)
%15 = fcmp oeq double %14, 0.000000e+00
%16 = fcmp oge double %14, 1.000000e+00
%17 = or i1 %15, %16
br i1 %17, label %4, label %18
18: ; preds = %4
%19 = tail call double @log(double %14)
%20 = fmul double %19, -2.000000e+00
%21 = fdiv double %20, %14
%22 = tail call double @sqrt(double %21)
%23 = fmul double %8, %22
store double %23, double* @rand_norm.gset
store i1 true, i1* @rand_norm.iset
%24 = fmul double %12, %22
br label %25
25: ; preds = %18, %2
%26 = phi double [ %3, %2 ], [ %24, %18 ]
ret double %26
}