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


x86 assembly (clang, -O0):
<gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xeb0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <drand48@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)
ja     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>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe14(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian>:
sub    $0x18,%rsp
movss  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <drand48@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
movsd  0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  %xmm0,%xmm2
addsd  0xe82(%rip),%xmm2
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe72(%rip),%xmm1
ja     1140 <gaussian+0x10>
ucomisd 0xe78(%rip),%xmm1
jne    11a4 <gaussian+0x74>
jnp    1140 <gaussian+0x10>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe41(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
mulsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @gaussian(float %0) {
%2 = alloca float
%3 = alloca double
%4 = alloca double
%5 = alloca double
store float %0, float* %2
br label %6
6: ; preds = %23, %1
%7 = call double (...) @drand48()
%8 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %7, double -1.000000e+00)
store double %8, double* %3
%9 = call double (...) @drand48()
%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 ogt 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 float, float* %2
%27 = fpext float %26 to double
%28 = load double, double* %4
%29 = fmul double %27, %28
%30 = load double, double* %5
%31 = call double @log(double %30)
%32 = fmul double -2.000000e+00, %31
%33 = load double, double* %5
%34 = fdiv double %32, %33
%35 = call float @sqrt(double %34)
%36 = fpext float %35 to double
%37 = fmul double %29, %36
%38 = fptrunc double %37 to float
ret float %38
}

LLVM IR (-O2):
define float @gaussian(float %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call double (...) @drand48()
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double (...) @drand48()
%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 ogt 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 = fpext float %0 to double
%14 = fmul double %6, %13
%15 = tail call double @log(double %8)
%16 = fmul double %15, -2.000000e+00
%17 = fdiv double %16, %8
%18 = tail call float @sqrt(double %17)
%19 = fpext float %18 to double
%20 = fmul double %14, %19
%21 = fptrunc double %20 to float
ret float %21
}