#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 random_double_uniform();
double sqrt(double);
double random_double_normal(double mu, double sigma) {
  double v1, v2, s;
  do {
    v1 = 2.0 * random_double_uniform() - 1.0;
    v2 = 2.0 * random_double_uniform() - 1.0;
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.0 || s == 0.0);
  return mu + sigma * v1 * sqrt(-2.0 * log(s) / s);
}


x86 assembly (clang, -O0):
<random_double_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random_double_uniform@plt>
addsd  %xmm0,%xmm0
movsd  0xeab(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <random_double_uniform@plt>
addsd  %xmm0,%xmm0
movsd  0xe8f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe5e(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    11ce <random_double_normal+0x9e>
movsd  -0x28(%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    1142 <random_double_normal+0x12>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe09(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_double_normal>:
sub    $0x18,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
nop
xor    %eax,%eax
call   1030 <random_double_uniform@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random_double_uniform@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm0
addsd  0xe86(%rip),%xmm0
mulsd  %xmm0,%xmm0
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe76(%rip),%xmm2
jae    1140 <random_double_normal+0x10>
ucomisd 0xe7c(%rip),%xmm2
jne    11a0 <random_double_normal+0x70>
jnp    1140 <random_double_normal+0x10>
mulsd  (%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1040 <log@plt>
mulsd  0xe4f(%rip),%xmm0
divsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <random_double_normal+0xa6>
sqrtsd %xmm0,%xmm0
jmp    11db <random_double_normal+0xab>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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