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


x86 assembly (clang, -O0):
<random_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random_unit_uniform@plt>
movaps %xmm0,%xmm1
movsd  0xeec(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <random_unit_uniform@plt>
movsd  0xecc(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xeb8(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xecd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe71(%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  0xe44(%rip),%xmm4
mulsd  -0x30(%rbp),%xmm4
movq   %xmm4,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm4
movsd  0xe18(%rip),%xmm5
mulsd  %xmm5,%xmm3
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
movsd  0xe28(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jb     1280 <random_gaussian+0x160>
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe14(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x3a(%rbp)
ja     127a <random_gaussian+0x15a>
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  0xde6(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1132 <random_gaussian+0x12>
movsd  -0x8(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_gaussian>:
sub    $0x48,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <random_unit_uniform@plt>
movsd  0xec1(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random_unit_uniform@plt>
movsd  0xeb0(%rip),%xmm4
subsd  %xmm0,%xmm4
mulsd  0xeac(%rip),%xmm4
movsd  0x8(%rsp),%xmm0
addsd  0xea6(%rip),%xmm0
movapd %xmm4,%xmm1
andpd  0xed2(%rip),%xmm1
addsd  0xe9a(%rip),%xmm1
movapd %xmm0,%xmm2
mulsd  0xe96(%rip),%xmm2
movapd %xmm1,%xmm3
mulsd  0xe92(%rip),%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xe82(%rip),%xmm0
jb     1211 <random_gaussian+0xf1>
ucomisd 0xe80(%rip),%xmm0
ja     1130 <random_gaussian+0x10>
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movapd %xmm4,0x30(%rsp)
call   1040 <log@plt>
movapd 0x30(%rsp),%xmm4
mulsd  0xe55(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movapd 0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1130 <random_gaussian+0x10>
movsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm4,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x48,%rsp
ret

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

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