#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 */
scalar_t__ RAND_MAX;
int log(double);
scalar_t__ rand();
double sqrt(int);
double reb_random_normal(double variance) {
  double v1, v2, rsq = 1.;
  while (rsq >= 1. || rsq < 1.0e-12) {
    v1 = 2. * ((double)rand()) / ((double)(RAND_MAX)) - 1.0;
    v2 = 2. * ((double)rand()) / ((double)(RAND_MAX)) - 1.0;
    rsq = v1 * v1 + v2 * v2;
  }
  return v1 * sqrt(-2. * log(rsq) / rsq * variance);
}


x86 assembly (clang, -O0):
<reb_random_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xebb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    1179 <reb_random_normal+0x49>
movsd  0xe9a(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1189 <reb_random_normal+0x59>
jmp    1221 <reb_random_normal+0xf1>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe7b(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e40(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe42(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e07(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe0e(%rip),%xmm1
subsd  %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)
jmp    114a <reb_random_normal+0x1a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdcf(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reb_random_normal>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
mov    0x2ea6(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
addsd  %xmm0,%xmm0
divsd  %xmm1,%xmm0
addsd  0xe58(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe46(%rip),%xmm1
jae    1150 <reb_random_normal+0x20>
movsd  0xe44(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1150 <reb_random_normal+0x20>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe24(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @reb_random_normal(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %5
br label %6
6: ; preds = %14, %1
%7 = load double, double* %5
%8 = fcmp oge double %7, 1.000000e+00
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load double, double* %5
%11 = fcmp olt double %10, 0x3D719799812DEA11
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ true, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %35
14: ; preds = %12
%15 = call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = fmul double 2.000000e+00, %16
%18 = load i64, i64* @RAND_MAX
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
%21 = fsub double %20, 1.000000e+00
store double %21, double* %3
%22 = call i64 (...) @rand()
%23 = sitofp i64 %22 to double
%24 = fmul double 2.000000e+00, %23
%25 = load i64, i64* @RAND_MAX
%26 = sitofp i64 %25 to double
%27 = fdiv double %24, %26
%28 = fsub double %27, 1.000000e+00
store double %28, double* %4
%29 = load double, double* %3
%30 = load double, double* %3
%31 = load double, double* %4
%32 = load double, double* %4
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %29, double %30, double %33)
store double %34, double* %5
br label %6
35: ; preds = %12
%36 = load double, double* %3
%37 = load double, double* %5
%38 = call i32 @log(double %37)
%39 = sitofp i32 %38 to double
%40 = fmul double -2.000000e+00, %39
%41 = load double, double* %5
%42 = fdiv double %40, %41
%43 = load double, double* %2
%44 = fmul double %42, %43
%45 = fptosi double %44 to i32
%46 = call double @sqrt(i32 %45)
%47 = fmul double %36, %46
ret double %47
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @reb_random_normal(double %0) {
br label %2
2: ; preds = %1, %2
%3 = tail call i64 (...) @rand()
%4 = sitofp i64 %3 to double
%5 = fmul double %4, 2.000000e+00
%6 = load i64, i64* @RAND_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
%9 = fadd double %8, -1.000000e+00
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = fmul double %11, 2.000000e+00
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = fadd double %15, -1.000000e+00
%17 = fmul double %16, %16
%18 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %17)
%19 = fcmp oge double %18, 1.000000e+00
%20 = fcmp olt double %18, 0x3D719799812DEA11
%21 = or i1 %19, %20
br i1 %21, label %2, label %22
22: ; preds = %2
%23 = tail call i32 @log(double %18)
%24 = sitofp i32 %23 to double
%25 = fmul double %24, -2.000000e+00
%26 = fdiv double %25, %18
%27 = fmul double %26, %0
%28 = fptosi double %27 to i32
%29 = tail call double @sqrt(i32 %28)
%30 = fmul double %9, %29
ret double %30
}