#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 random_range(double, double);
double sqrt(double);
double random_gauss(void) {
  static int holding = 0;
  static double hold;
  double factor, r, v1, v2;
  if (holding) {
    holding = 0;
    return (hold);
  } else {
    do {
      v1 = random_range(-1.0, 1.0);
      v2 = random_range(-1.0, 1.0);
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0);
    factor = sqrt(-2.0 * log(r) / r);
    hold = v1 * factor;
    holding = 1;
    return (v2 * factor);
  }
}


x86 assembly (clang, -O0):
<random_gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1161 <random_gauss+0x31>
movl   $0x0,0x2ef1(%rip)
movsd  0x2ef1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <random_gauss+0xf5>
jmp    1166 <random_gauss+0x36>
movsd  0xe92(%rip),%xmm0
movsd  0xe92(%rip),%xmm1
call   1030 <random_range@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe78(%rip),%xmm0
movsd  0xe78(%rip),%xmm1
call   1030 <random_range@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1166 <random_gauss+0x36>
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe29(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2e3c(%rip)
movl   $0x1,0x2e2a(%rip)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_gauss>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <random_gauss+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm1
jmp    1208 <random_gauss+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0xe98(%rip),%xmm0
movsd  0xe98(%rip),%xmm1
call   1030 <random_range@plt>
movsd  %xmm0,(%rsp)
movsd  0xe7e(%rip),%xmm0
movsd  0xe7e(%rip),%xmm1
call   1030 <random_range@plt>
movsd  (%rsp),%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe5c(%rip),%xmm3
jae    1160 <random_gauss+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe45(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e1 <random_gauss+0xb1>
sqrtsd %xmm0,%xmm0
jmp    11e6 <random_gauss+0xb6>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e51(%rip)
movb   $0x1,0x2e42(%rip)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@random_gauss.holding = internal global i32 0
@random_gauss.hold = internal global double 0.000000e+00
define double @random_gauss() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = load i32, i32* @random_gauss.holding
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
store i32 0, i32* @random_gauss.holding
%9 = load double, double* @random_gauss.hold
store double %9, double* %1
br label %36
10: ; preds = %0
br label %11
11: ; preds = %20, %10
%12 = call double @random_range(double -1.000000e+00, double 1.000000e+00)
store double %12, double* %4
%13 = call double @random_range(double -1.000000e+00, double 1.000000e+00)
store double %13, double* %5
%14 = load double, double* %4
%15 = load double, double* %4
%16 = load double, double* %5
%17 = load double, double* %5
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
store double %19, double* %3
br label %20
20: ; preds = %11
%21 = load double, double* %3
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %11, label %23
23: ; preds = %20
%24 = load double, double* %3
%25 = call double @log(double %24)
%26 = fmul double -2.000000e+00, %25
%27 = load double, double* %3
%28 = fdiv double %26, %27
%29 = call double @sqrt(double %28)
store double %29, double* %2
%30 = load double, double* %4
%31 = load double, double* %2
%32 = fmul double %30, %31
store double %32, double* @random_gauss.hold
store i32 1, i32* @random_gauss.holding
%33 = load double, double* %5
%34 = load double, double* %2
%35 = fmul double %33, %34
store double %35, double* %1
br label %36
36: ; preds = %23, %8
%37 = load double, double* %1
ret double %37
}

LLVM IR (-O2):
@random_gauss.holding = internal unnamed_addr global i1 false
@random_gauss.hold = internal unnamed_addr global double 0.000000e+00
define double @random_gauss() {
%1 = load i1, i1* @random_gauss.holding
br i1 %1, label %2, label %4
2: ; preds = %0
store i1 false, i1* @random_gauss.holding
%3 = load double, double* @random_gauss.hold
br label %17
4: ; preds = %0, %4
%5 = tail call double @random_range(double -1.000000e+00, double 1.000000e+00)
%6 = tail call double @random_range(double -1.000000e+00, double 1.000000e+00)
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %7)
%9 = fcmp ult double %8, 1.000000e+00
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = tail call double @log(double %8)
%12 = fmul double %11, -2.000000e+00
%13 = fdiv double %12, %8
%14 = tail call double @sqrt(double %13)
%15 = fmul double %5, %14
store double %15, double* @random_gauss.hold
store i1 true, i1* @random_gauss.holding
%16 = fmul double %6, %14
br label %17
17: ; preds = %10, %2
%18 = phi double [ %3, %2 ], [ %16, %10 ]
ret double %18
}