#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 */
int dran_sign();
double log(double);
double sqrt(double);
double ran_gaussian(double sigma) {
  double x, y, r2, gauss;
  do {
    x = -1 + 2 * dran_sign();
    y = -1 + 2 * dran_sign();
    r2 = x * x + y * y;
  } while (r2 > 1.0 || r2 == 0);
  gauss = sigma * y * sqrt(-2.0 * log(r2) / r2);
  return gauss;
}


x86 assembly (clang, -O0):
<ran_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <dran_sign@plt>
shl    $0x1,%eax
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dran_sign@plt>
shl    $0x1,%eax
add    $0xffffffff,%eax
cvtsi2sd %eax,%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,-0x29(%rbp)
ja     11c1 <ran_gaussian+0x91>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    113d <ran_gaussian+0xd>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%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  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ran_gaussian>:
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <dran_sign@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <dran_sign@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe76(%rip),%xmm2
ja     1140 <ran_gaussian+0x10>
movapd %xmm2,%xmm0
ucomisd 0xe78(%rip),%xmm2
jne    119c <ran_gaussian+0x6c>
jnp    1140 <ran_gaussian+0x10>
mulsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe4d(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d1 <ran_gaussian+0xa1>
sqrtsd %xmm0,%xmm0
jmp    11d6 <ran_gaussian+0xa6>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
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* %2
br label %7
7: ; preds = %28, %1
%8 = call i32 (...) @dran_sign()
%9 = mul nsw i32 2, %8
%10 = add nsw i32 -1, %9
%11 = sitofp i32 %10 to double
store double %11, double* %3
%12 = call i32 (...) @dran_sign()
%13 = mul nsw i32 2, %12
%14 = add nsw i32 -1, %13
%15 = sitofp i32 %14 to double
store double %15, double* %4
%16 = load double, double* %3
%17 = load double, double* %3
%18 = load double, double* %4
%19 = load double, double* %4
%20 = fmul double %18, %19
%21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
store double %21, double* %5
br label %22
22: ; preds = %7
%23 = load double, double* %5
%24 = fcmp ogt double %23, 1.000000e+00
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* %5
%27 = fcmp oeq double %26, 0.000000e+00
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ true, %22 ], [ %27, %25 ]
br i1 %29, label %7, label %30
30: ; preds = %28
%31 = load double, double* %2
%32 = load double, double* %4
%33 = fmul double %31, %32
%34 = load double, double* %5
%35 = call double @log(double %34)
%36 = fmul double -2.000000e+00, %35
%37 = load double, double* %5
%38 = fdiv double %36, %37
%39 = call double @sqrt(double %38)
%40 = fmul double %33, %39
store double %40, double* %6
%41 = load double, double* %6
ret double %41
}

LLVM IR (-O2):
define double @ran_gaussian(double %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call i32 (...) @dran_sign()
%4 = shl nsw i32 %3, 1
%5 = add nsw i32 %4, -1
%6 = sitofp i32 %5 to double
%7 = tail call i32 (...) @dran_sign()
%8 = shl nsw i32 %7, 1
%9 = add nsw i32 %8, -1
%10 = sitofp i32 %9 to double
%11 = fmul double %10, %10
%12 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %11)
%13 = fcmp ogt double %12, 1.000000e+00
%14 = fcmp oeq double %12, 0.000000e+00
%15 = or i1 %13, %14
br i1 %15, label %2, label %16
16: ; preds = %2
%17 = fmul double %10, %0
%18 = tail call double @log(double %12)
%19 = fmul double %18, -2.000000e+00
%20 = fdiv double %19, %12
%21 = tail call double @sqrt(double %20)
%22 = fmul double %17, %21
ret double %22
}