#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 RAND_MAX;
int log(double);
double pow(double, int);
scalar_t__ rand();
double sqrt(int);
double randn(double mu, double sigma) {
  double U1, U2, W, mult;
  static double X1, X2;
  static int call = 0;
  if (call == 1) {
    call = !call;
    return (mu + sigma * (double)X2);
  }
  do {
    U1 = -1 + ((double)rand() / RAND_MAX) * 2;
    U2 = -1 + ((double)rand() / RAND_MAX) * 2;
    W = pow(U1, 2) + pow(U2, 2);
  } while (W >= 1 || W == 0);
  mult = sqrt((-2 * log(W)) / W);
  X1 = U1 * mult;
  X2 = U2 * mult;
  call = !call;
  return (mu + sigma * (double)X1);
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cmpl   $0x1,0x2eff(%rip)
jne    119a <randn+0x5a>
cmpl   $0x0,0x2ef2(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2ee2(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0x2ec8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ea <randn+0x1aa>
jmp    119f <randn+0x5f>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e36(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe3e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e0a(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe12(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
movsd  0xdce(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x41(%rbp)
jae    125e <randn+0x11e>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    119f <randn+0x5f>
movsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,0x2da6(%rip)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,0x2d9c(%rip)
cmpl   $0x0,0x2d9d(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2d8d(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0x2d6b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
push   %rbx
sub    $0x30,%rsp
cmpl   $0x1,0x2f04(%rip)
jne    1165 <randn+0x25>
movl   $0x0,0x2ef8(%rip)
movsd  0x2ee8(%rip),%xmm2
jmp    1277 <randn+0x137>
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
mov    0x2e70(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe61(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
addsd  0xe38(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
addsd  0x8(%rsp),%xmm0
ucomisd 0xe06(%rip),%xmm0
jae    1180 <randn+0x40>
ucomisd 0xe00(%rip),%xmm0
jne    1218 <randn+0xd8>
jnp    1180 <randn+0x40>
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2def(%rip)
xor    %eax,%eax
cmpl   $0x0,0x2dee(%rip)
sete   %al
mov    %eax,0x2de5(%rip)
movsd  0x28(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@randn.X1 = internal global double 0.000000e+00
@randn.X2 = internal global double 0.000000e+00
@randn.call = internal global i32 0
@RAND_MAX = global double 0.000000e+00
define double @randn(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %4
store double %1, double* %5
%10 = load i32, i32* @randn.call
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i32, i32* @randn.call
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
%16 = zext i1 %15 to i32
store i32 %16, i32* @randn.call
%17 = load double, double* %4
%18 = load double, double* %5
%19 = load double, double* @randn.X2
%20 = call double @llvm.fmuladd.f64(double %18, double %19, double %17)
store double %20, double* %3
br label %69
21: ; preds = %2
br label %22
22: ; preds = %44, %21
%23 = call i64 (...) @rand()
%24 = sitofp i64 %23 to double
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
%27 = call double @llvm.fmuladd.f64(double %26, double 2.000000e+00, double -1.000000e+00)
store double %27, double* %6
%28 = call i64 (...) @rand()
%29 = sitofp i64 %28 to double
%30 = load double, double* @RAND_MAX
%31 = fdiv double %29, %30
%32 = call double @llvm.fmuladd.f64(double %31, double 2.000000e+00, double -1.000000e+00)
store double %32, double* %7
%33 = load double, double* %6
%34 = call double @pow(double %33, i32 2)
%35 = load double, double* %7
%36 = call double @pow(double %35, i32 2)
%37 = fadd double %34, %36
store double %37, double* %8
br label %38
38: ; preds = %22
%39 = load double, double* %8
%40 = fcmp oge double %39, 1.000000e+00
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load double, double* %8
%43 = fcmp oeq double %42, 0.000000e+00
br label %44
44: ; preds = %41, %38
%45 = phi i1 [ true, %38 ], [ %43, %41 ]
br i1 %45, label %22, label %46
46: ; preds = %44
%47 = load double, double* %8
%48 = call i32 @log(double %47)
%49 = mul nsw i32 -2, %48
%50 = sitofp i32 %49 to double
%51 = load double, double* %8
%52 = fdiv double %50, %51
%53 = fptosi double %52 to i32
%54 = call double @sqrt(i32 %53)
store double %54, double* %9
%55 = load double, double* %6
%56 = load double, double* %9
%57 = fmul double %55, %56
store double %57, double* @randn.X1
%58 = load double, double* %7
%59 = load double, double* %9
%60 = fmul double %58, %59
store double %60, double* @randn.X2
%61 = load i32, i32* @randn.call
%62 = icmp ne i32 %61, 0
%63 = xor i1 %62, true
%64 = zext i1 %63 to i32
store i32 %64, i32* @randn.call
%65 = load double, double* %4
%66 = load double, double* %5
%67 = load double, double* @randn.X1
%68 = call double @llvm.fmuladd.f64(double %66, double %67, double %65)
store double %68, double* %3
br label %69
69: ; preds = %46, %12
%70 = load double, double* %3
ret double %70
}

LLVM IR (-O2):
@randn.X2 = internal unnamed_addr global double 0.000000e+00
@randn.call = internal unnamed_addr global i32 0
@RAND_MAX = global double 0.000000e+00
define double @randn(double %0, double %1) {
%3 = load i32, i32* @randn.call
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %2
store i32 0, i32* @randn.call
%6 = load double, double* @randn.X2
br label %36
7: ; preds = %2, %7
%8 = tail call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load double, double* @RAND_MAX
%11 = fdiv double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double 2.000000e+00, double -1.000000e+00)
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double 2.000000e+00, double -1.000000e+00)
%18 = tail call double @pow(double %12, i32 2)
%19 = tail call double @pow(double %17, i32 2)
%20 = fadd double %18, %19
%21 = fcmp oge double %20, 1.000000e+00
%22 = fcmp oeq double %20, 0.000000e+00
%23 = or i1 %21, %22
br i1 %23, label %7, label %24
24: ; preds = %7
%25 = tail call i32 @log(double %20)
%26 = mul nsw i32 %25, -2
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, %20
%29 = fptosi double %28 to i32
%30 = tail call double @sqrt(i32 %29)
%31 = fmul double %12, %30
%32 = fmul double %17, %30
store double %32, double* @randn.X2
%33 = load i32, i32* @randn.call
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
store i32 %35, i32* @randn.call
br label %36
36: ; preds = %24, %5
%37 = phi double [ %31, %24 ], [ %6, %5 ]
%38 = tail call double @llvm.fmuladd.f64(double %1, double %37, double %0)
ret double %38
}