#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 log(double);
double rand_double();
double sqrt(int);
double randn() {
  double s, vre, vim, ure, uim;
  static double next = -42;
  if (next != -42) {
    s = next;
    next = -42;
    return s;
  }
  do {
    ure = rand_double();
    uim = rand_double();
    vre = 2 * ure - 1;
    vim = 2 * uim - 1;
    s = vre * vre + vim * vim;
  } while (s >= 1);
  s = sqrt(-2 * log(s) / s);
  next = s * vre;
  return s * vim;
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0x2ef8(%rip),%xmm0
movsd  0xeb8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    115d <randn+0x2d>
jp     115d <randn+0x2d>
jmp    1189 <randn+0x59>
movsd  0x2ed3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,0x2ebe(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125a <randn+0x12a>
jmp    118e <randn+0x5e>
mov    $0x0,%al
call   1030 <rand_double@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <rand_double@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe51(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe37(%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,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe08(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    118e <randn+0x5e>
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2ded(%rip)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
sub    $0x18,%rsp
movsd  0x2efc(%rip),%xmm1
ucomisd 0xebc(%rip),%xmm1
jne    1148 <randn+0x18>
jnp    1160 <randn+0x30>
movabs $0xc045000000000000,%rax
mov    %rax,0x2edf(%rip)
jmp    11fd <randn+0xcd>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rand_double@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rand_double@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm3
addsd  %xmm3,%xmm3
movsd  0xe80(%rip),%xmm0
addsd  %xmm0,%xmm3
addsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm3,(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe5b(%rip),%xmm0
jae    1160 <randn+0x30>
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <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  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e3f(%rip)
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@randn.next = internal unnamed_addr global double -4.200000e+01
define double @randn() {
%1 = load double, double* @randn.next
%2 = fcmp une double %1, -4.200000e+01
br i1 %2, label %3, label %4
3: ; preds = %0
store double -4.200000e+01, double* @randn.next
br label %21
4: ; preds = %0, %4
%5 = tail call double (...) @rand_double()
%6 = tail call double (...) @rand_double()
%7 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%8 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
%9 = fmul double %8, %8
%10 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %9)
%11 = fcmp ult double %10, 1.000000e+00
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = tail call i32 @log(double %10)
%14 = mul nsw i32 %13, -2
%15 = sitofp i32 %14 to double
%16 = fdiv double %15, %10
%17 = fptosi double %16 to i32
%18 = tail call double @sqrt(i32 %17)
%19 = fmul double %7, %18
store double %19, double* @randn.next
%20 = fmul double %8, %18
br label %21
21: ; preds = %12, %3
%22 = phi double [ %1, %3 ], [ %20, %12 ]
ret double %22
}