#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 ran_get();
double sqrt(double);
double ran_gaussian(const double sigma) {
  static int stored = 0;
  static double y;
  double x1, x2, w;
  if (!stored) {
    do {
      x1 = 2.0 * ran_get() - 1.0;
      x2 = 2.0 * ran_get() - 1.0;
      w = x1 * x1 + x2 * x2;
    } while (w >= 1.0);
    w = sqrt(-2.0 * log(w) / w);
    y = x1 * w;
    stored = 1;
    return x2 * w * sigma;
  } else {
    stored = 0;
    return y * sigma;
  }
}


x86 assembly (clang, -O0):
<ran_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,0x2efc(%rip)
jne    121c <ran_gaussian+0xec>
jmp    114f <ran_gaussian+0x1f>
mov    $0x0,%al
call   1030 <ran_get@plt>
addsd  %xmm0,%xmm0
movsd  0xe9e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <ran_get@plt>
addsd  %xmm0,%xmm0
movsd  0xe82(%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
movsd  0xe53(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    114f <ran_gaussian+0x1f>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe3c(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2e4f(%rip)
movl   $0x1,0x2e3d(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1238 <ran_gaussian+0x108>
movl   $0x0,0x2e1a(%rip)
movsd  0x2e1a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ran_gaussian>:
sub    $0x28,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1151 <ran_gaussian+0x21>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm1
jmp    1215 <ran_gaussian+0xe5>
movsd  %xmm0,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ran_get@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <ran_get@plt>
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe66(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe56(%rip),%xmm3
jae    1160 <ran_gaussian+0x30>
movsd  %xmm0,0x18(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe3f(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e7 <ran_gaussian+0xb7>
sqrtsd %xmm0,%xmm0
jmp    11ec <ran_gaussian+0xbc>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e4a(%rip)
movb   $0x1,0x2e3b(%rip)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

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

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