#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 */
int log(double);
double sqrt(int);
double unitrand(double randfn(void)) {
  static double b;
  double x, y, r;
  if (b != 0.0) {
    x = b;
    b = 0;
    return x;
  }
  do {
    x = 2.0 * randfn() - 1.0;
    y = 2.0 * randfn() - 1.0;
    r = x * x + y * y;
  } while ((r > 1) || (r == 0));
  r = sqrt(-2 * log(r) / r);
  b = x * r;
  return y * r;
}


x86 assembly (clang, -O0):
<unitrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  0x2f04(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114c <unitrand+0x2c>
jp     114c <unitrand+0x2c>
jmp    1173 <unitrand+0x53>
movsd  0x2ee4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2ed4(%rip)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124f <unitrand+0x12f>
jmp    1178 <unitrand+0x58>
call   *-0x10(%rbp)
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
call   *-0x10(%rbp)
addsd  %xmm0,%xmm0
movsd  0xe61(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe30(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
ja     11fc <unitrand+0xdc>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1178 <unitrand+0x58>
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2df8(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unitrand>:
push   %rbx
sub    $0x20,%rsp
movsd  0x2f0b(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1139 <unitrand+0x19>
jnp    1149 <unitrand+0x29>
movq   $0x0,0x2ef4(%rip)
jmp    11f1 <unitrand+0xd1>
mov    %rdi,%rbx
nopl   0x0(%rax)
call   *%rbx
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe9e(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   *%rbx
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  0xe82(%rip),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe6c(%rip),%xmm0
ja     1150 <unitrand+0x30>
ucomisd 0xe6a(%rip),%xmm0
jne    11aa <unitrand+0x8a>
jnp    1150 <unitrand+0x30>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e4b(%rip)
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@unitrand.b = internal unnamed_addr global double 0.000000e+00
define double @unitrand(double ()* nocapture %0) {
%2 = load double, double* @unitrand.b
%3 = fcmp une double %2, 0.000000e+00
br i1 %3, label %4, label %5
4: ; preds = %1
store double 0.000000e+00, double* @unitrand.b
br label %24
5: ; preds = %1, %5
%6 = tail call double %0()
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
%8 = tail call double %0()
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %10)
%12 = fcmp ogt double %11, 1.000000e+00
%13 = fcmp oeq double %11, 0.000000e+00
%14 = or i1 %12, %13
br i1 %14, label %5, label %15
15: ; preds = %5
%16 = tail call i32 @log(double %11)
%17 = mul nsw i32 %16, -2
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, %11
%20 = fptosi double %19 to i32
%21 = tail call double @sqrt(i32 %20)
%22 = fmul double %7, %21
store double %22, double* @unitrand.b
%23 = fmul double %9, %21
br label %24
24: ; preds = %15, %4
%25 = phi double [ %2, %4 ], [ %23, %15 ]
ret double %25
}