#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);
int uniformVar();
double standardNormalVar(void) {
  double v1, v2, s = 2;
  while (s > 1) {
    v1 = 2 * uniformVar() - 1;
    v2 = 2 * uniformVar() - 1;
    s = v1 * v1 + v2 * v2;
  }
  return v1 * sqrt(-2 * log(s) / s);
}


x86 assembly (clang, -O0):
<standardNormalVar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ae <standardNormalVar+0x7e>
mov    $0x0,%al
call   1030 <uniformVar@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <uniformVar@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1145 <standardNormalVar+0x15>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<standardNormalVar>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <uniformVar@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <uniformVar@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xe7a(%rip),%xmm0
ja     1140 <standardNormalVar+0x10>
movsd  %xmm0,0x10(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @standardNormalVar() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
store double 2.000000e+00, double* %3
br label %4
4: ; preds = %7, %0
%5 = load double, double* %3
%6 = fcmp ogt double %5, 1.000000e+00
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = call i32 (...) @uniformVar()
%9 = mul nsw i32 2, %8
%10 = sub nsw i32 %9, 1
%11 = sitofp i32 %10 to double
store double %11, double* %1
%12 = call i32 (...) @uniformVar()
%13 = mul nsw i32 2, %12
%14 = sub nsw i32 %13, 1
%15 = sitofp i32 %14 to double
store double %15, double* %2
%16 = load double, double* %1
%17 = load double, double* %1
%18 = load double, double* %2
%19 = load double, double* %2
%20 = fmul double %18, %19
%21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
store double %21, double* %3
br label %4
22: ; preds = %4
%23 = load double, double* %1
%24 = load double, double* %3
%25 = call i32 @log(double %24)
%26 = mul nsw i32 -2, %25
%27 = sitofp i32 %26 to double
%28 = load double, double* %3
%29 = fdiv double %27, %28
%30 = fptosi double %29 to i32
%31 = call double @sqrt(i32 %30)
%32 = fmul double %23, %31
ret double %32
}

LLVM IR (-O2):
define double @standardNormalVar() {
br label %1
1: ; preds = %0, %1
%2 = tail call i32 (...) @uniformVar()
%3 = shl nsw i32 %2, 1
%4 = add nsw i32 %3, -1
%5 = sitofp i32 %4 to double
%6 = tail call i32 (...) @uniformVar()
%7 = shl nsw i32 %6, 1
%8 = add nsw i32 %7, -1
%9 = sitofp i32 %8 to double
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %10)
%12 = fcmp ogt double %11, 1.000000e+00
br i1 %12, label %1, label %13
13: ; preds = %1
%14 = tail call i32 @log(double %11)
%15 = mul nsw i32 %14, -2
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, %11
%18 = fptosi double %17 to i32
%19 = tail call double @sqrt(i32 %18)
%20 = fmul double %19, %5
ret double %20
}