#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 RandomUniform();
double fabs(double);
double log(double);
double RandomGaussian(double mean, double stddev) {
  double q, u, v, x, y;
  do {
    u = RandomUniform();
    v = RandomUniform();
    if (u <= 0.0 || v <= 0.0) {
      u = 1.0;
      v = 1.0;
    }
    v = 1.7156 * (v - 0.5);
    x = u - 0.449871;
    y = fabs(v) + 0.386595;
    q = x * x + y * (0.19600 * y - 0.25472 * x);
    if (q < 0.27597)
      break;
  } while ((q > 0.27846) || (v * v > -4.0 * log(u) * u * u));
  return (mean + stddev * v / u);
}


x86 assembly (clang, -O0):
<RandomGaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <RandomUniform@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <RandomUniform@plt>
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jae    1166 <RandomGaussian+0x46>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     1180 <RandomGaussian+0x60>
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xeab(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe97(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xe8c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe50(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm3
movsd  0xe23(%rip),%xmm4
mulsd  -0x30(%rbp),%xmm4
movq   %xmm4,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm4
movsd  0xdf7(%rip),%xmm5
mulsd  %xmm5,%xmm3
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xdce(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    124a <RandomGaussian+0x12a>
jmp    12b7 <RandomGaussian+0x197>
jmp    124f <RandomGaussian+0x12f>
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%al
movsd  0xde2(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
ja     12ac <RandomGaussian+0x18c>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  0xdb4(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1132 <RandomGaussian+0x12>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RandomGaussian>:
sub    $0x48,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1030 <RandomUniform@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <RandomUniform@plt>
movsd  0x8(%rsp),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
setae  %al
ucomisd %xmm0,%xmm1
setae  %cl
or     %al,%cl
movsd  0xe9a(%rip),%xmm4
test   %cl,%cl
jne    116e <RandomGaussian+0x4e>
movapd %xmm2,%xmm4
addsd  0xe92(%rip),%xmm0
mulsd  0xe92(%rip),%xmm0
movsd  0xe92(%rip),%xmm5
jne    118c <RandomGaussian+0x6c>
movapd %xmm0,%xmm5
movapd %xmm4,%xmm0
addsd  0xe88(%rip),%xmm0
movapd %xmm5,%xmm1
andpd  0xebc(%rip),%xmm1
addsd  0xe7c(%rip),%xmm1
movapd %xmm0,%xmm2
mulsd  0xe78(%rip),%xmm2
movapd %xmm1,%xmm3
mulsd  0xe74(%rip),%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
movsd  0xe64(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     123f <RandomGaussian+0x11f>
ucomisd 0xe5e(%rip),%xmm0
ja     1130 <RandomGaussian+0x10>
movapd %xmm5,%xmm0
mulsd  %xmm5,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm4,%xmm0
movsd  %xmm4,0x8(%rsp)
movapd %xmm5,0x30(%rsp)
call   1040 <log@plt>
movapd 0x30(%rsp),%xmm5
movsd  0x8(%rsp),%xmm4
mulsd  0xe29(%rip),%xmm0
mulsd  %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd 0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1130 <RandomGaussian+0x10>
mulsd  0x10(%rsp),%xmm5
divsd  %xmm4,%xmm5
addsd  0x18(%rsp),%xmm5
movapd %xmm5,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @RandomGaussian(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %10
10: ; preds = %57, %2
%11 = call double (...) @RandomUniform()
store double %11, double* %6
%12 = call double (...) @RandomUniform()
store double %12, double* %7
%13 = load double, double* %6
%14 = fcmp ole double %13, 0.000000e+00
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load double, double* %7
%17 = fcmp ole double %16, 0.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %15, %10
store double 1.000000e+00, double* %6
store double 1.000000e+00, double* %7
br label %19
19: ; preds = %18, %15
%20 = load double, double* %7
%21 = fsub double %20, 5.000000e-01
%22 = fmul double 1.715600e+00, %21
store double %22, double* %7
%23 = load double, double* %6
%24 = fsub double %23, 4.498710e-01
store double %24, double* %8
%25 = load double, double* %7
%26 = call double @llvm.fabs.f64(double %25)
%27 = fadd double %26, 3.865950e-01
store double %27, double* %9
%28 = load double, double* %8
%29 = load double, double* %8
%30 = load double, double* %9
%31 = load double, double* %9
%32 = load double, double* %8
%33 = fmul double 2.547200e-01, %32
%34 = fneg double %33
%35 = call double @llvm.fmuladd.f64(double 1.960000e-01, double %31, double %34)
%36 = fmul double %30, %35
%37 = call double @llvm.fmuladd.f64(double %28, double %29, double %36)
store double %37, double* %5
%38 = load double, double* %5
%39 = fcmp olt double %38, 2.759700e-01
br i1 %39, label %40, label %41
40: ; preds = %19
br label %59
41: ; preds = %19
br label %42
42: ; preds = %41
%43 = load double, double* %5
%44 = fcmp ogt double %43, 2.784600e-01
br i1 %44, label %57, label %45
45: ; preds = %42
%46 = load double, double* %7
%47 = load double, double* %7
%48 = fmul double %46, %47
%49 = load double, double* %6
%50 = call double @log(double %49)
%51 = fmul double -4.000000e+00, %50
%52 = load double, double* %6
%53 = fmul double %51, %52
%54 = load double, double* %6
%55 = fmul double %53, %54
%56 = fcmp ogt double %48, %55
br label %57
57: ; preds = %45, %42
%58 = phi i1 [ true, %42 ], [ %56, %45 ]
br i1 %58, label %10, label %59
59: ; preds = %57, %40
%60 = load double, double* %3
%61 = load double, double* %4
%62 = load double, double* %7
%63 = fmul double %61, %62
%64 = load double, double* %6
%65 = fdiv double %63, %64
%66 = fadd double %60, %65
ret double %66
}

LLVM IR (-O2):
define double @RandomGaussian(double %0, double %1) {
br label %3
3: ; preds = %30, %2
%4 = tail call double (...) @RandomUniform()
%5 = tail call double (...) @RandomUniform()
%6 = fcmp ole double %4, 0.000000e+00
%7 = fcmp ole double %5, 0.000000e+00
%8 = select i1 %6, i1 true, i1 %7
%9 = select i1 %8, double 1.000000e+00, double %4
%10 = fadd double %5, -5.000000e-01
%11 = fmul double %10, 1.715600e+00
%12 = select i1 %8, double 8.578000e-01, double %11
%13 = fadd double %9, -4.498710e-01
%14 = tail call double @llvm.fabs.f64(double %12)
%15 = fadd double %14, 3.865950e-01
%16 = fmul double %13, -2.547200e-01
%17 = tail call double @llvm.fmuladd.f64(double %15, double 1.960000e-01, double %16)
%18 = fmul double %15, %17
%19 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %18)
%20 = fcmp olt double %19, 2.759700e-01
br i1 %20, label %31, label %21
21: ; preds = %3
%22 = fcmp ogt double %19, 2.784600e-01
br i1 %22, label %30, label %23
23: ; preds = %21
%24 = fmul double %12, %12
%25 = tail call double @log(double %9)
%26 = fmul double %25, -4.000000e+00
%27 = fmul double %9, %26
%28 = fmul double %9, %27
%29 = fcmp ogt double %24, %28
br i1 %29, label %30, label %31
30: ; preds = %23, %21
br label %3
31: ; preds = %3, %23
%32 = fmul double %12, %1
%33 = fdiv double %32, %9
%34 = fadd double %33, %0
ret double %34
}