#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();
double const sqrt(double);
double gaussian(const double sigma) {
  double x, y, w;
  do {
    x = 2.0 * ran() - 1.0;
    y = 2.0 * ran() - 1.0;
    w = x * x + y * y;
  } while (w >= 1.0 || w == 0);
  return sigma * y * sqrt((-2.0 * log(w)) / w);
}


x86 assembly (clang, -O0):
<gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <ran@plt>
addsd  %xmm0,%xmm0
movsd  0xeb0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <ran@plt>
addsd  %xmm0,%xmm0
movsd  0xe94(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe63(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    11c9 <gaussian+0x99>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    113d <gaussian+0xd>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe18(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian>:
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ran@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1030 <ran@plt>
addsd  %xmm0,%xmm0
addsd  0xe8c(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe76(%rip),%xmm2
jae    1140 <gaussian+0x10>
movapd %xmm2,%xmm1
ucomisd 0xe78(%rip),%xmm2
jne    11a4 <gaussian+0x74>
jnp    1140 <gaussian+0x10>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe49(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11dd <gaussian+0xad>
sqrtsd %xmm0,%xmm0
jmp    11e2 <gaussian+0xb2>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @gaussian(double %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call double (...) @ran()
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double (...) @ran()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = fcmp oge double %8, 1.000000e+00
%10 = fcmp oeq double %8, 0.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = fmul double %6, %0
%14 = tail call double @log(double %8)
%15 = fmul double %14, -2.000000e+00
%16 = fdiv double %15, %8
%17 = tail call double @sqrt(double %16)
%18 = fmul double %13, %17
ret double %18
}