#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);
int ran2(long *);
double sqrt(int);
double gaussian_deviate(long *idum) {
  static int iset = 0;
  static double gset;
  double fac, rsq, v1, v2;
  if (idum < 0)
    iset = 0;
  if (iset == 0) {
    do {
      v1 = 2. * ran2(idum) - 1.0;
      v2 = 2. * ran2(idum) - 1.0;
      rsq = v1 * v1 + v2 * v2;
    } while (rsq >= 1.0 || rsq == 0.);
    fac = sqrt(-2. * log(rsq) / rsq);
    gset = v1 * fac;
    iset = 1;
    return v2 * fac;
  } else {
    iset = 0;
    return gset;
  }
}


x86 assembly (clang, -O0):
<gaussian_deviate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jae    1151 <gaussian_deviate+0x21>
movl   $0x0,0x2eef(%rip)
cmpl   $0x0,0x2ee8(%rip)
jne    1263 <gaussian_deviate+0x133>
jmp    1163 <gaussian_deviate+0x33>
mov    -0x10(%rbp),%rdi
call   1030 <ran2@plt>
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe84(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran2@plt>
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe31(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11fb <gaussian_deviate+0xcb>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1163 <gaussian_deviate+0x33>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdf4(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2e03(%rip)
movl   $0x1,0x2df1(%rip)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127a <gaussian_deviate+0x14a>
movl   $0x0,0x2dd3(%rip)
movsd  0x2dd3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian_deviate>:
push   %rbx
sub    $0x20,%rsp
cmpb   $0x0,0x2f04(%rip)
je     1152 <gaussian_deviate+0x22>
movb   $0x0,0x2efb(%rip)
movsd  0x2efb(%rip),%xmm1
jmp    121e <gaussian_deviate+0xee>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ran2@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe85(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <ran2@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm1
addsd  0xe60(%rip),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe4a(%rip),%xmm0
jae    1160 <gaussian_deviate+0x30>
ucomisd 0xe50(%rip),%xmm0
jne    11cc <gaussian_deviate+0x9c>
jnp    1160 <gaussian_deviate+0x30>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe24(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e3b(%rip)
movsd  0x18(%rsp),%xmm1
movb   $0x1,0x2e26(%rip)
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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