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


x86 assembly (clang, -O0):
<gaussian_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2efd(%rip)
jne    1251 <gaussian_number+0x121>
jmp    114a <gaussian_number+0x1a>
mov    $0x0,%al
call   1030 <mikenet_random@plt>
addsd  %xmm0,%xmm0
movsd  0xea3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <mikenet_random@plt>
addsd  %xmm0,%xmm0
movsd  0xe83(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movss  -0x14(%rbp),%xmm1
mulss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
movsd  0xe4a(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x15(%rbp)
jae    11e6 <gaussian_number+0xb6>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    114a <gaussian_number+0x1a>
movss  -0xc(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe0a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,0x2e0d(%rip)
movl   $0x1,0x2dff(%rip)
movss  -0x14(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1268 <gaussian_number+0x138>
movl   $0x0,0x2de1(%rip)
movss  0x2ddd(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian_number>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1160 <gaussian_number+0x30>
movb   $0x0,0x2ef8(%rip)
movss  0x2ef4(%rip),%xmm2
jmp    1212 <gaussian_number+0xe2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <mikenet_random@plt>
addsd  %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <mikenet_random@plt>
addsd  %xmm0,%xmm0
addsd  0xe6c(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  0x8(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe59(%rip),%xmm0
jae    1160 <gaussian_number+0x30>
ucomiss 0xe54(%rip),%xmm0
jne    11c4 <gaussian_number+0x94>
jnp    1160 <gaussian_number+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
call   1040 <log@plt>
mulsd  0xe24(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0xc(%rsp),%xmm2
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e39(%rip)
movb   $0x1,0x2e2e(%rip)
mulss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
ret

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

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