#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 RAND_MAX;
int log(double);
double random();
double sqrt(int);
double normal() {
  double x, y, s;
  static double n = 0 / (double)0;
  if (n == n) {
    x = n;
    n = 0 / (double)0;
    return x;
  }
  do {
    x = random() / (double)(RAND_MAX / 2) - 1;
    y = random() / (double)(RAND_MAX / 2) - 1;
    s = x * x + y * y;
  } while (s >= 1);
  s = sqrt(-2 * log(s) / s);
  n = y * s;
  return x * s;
}


x86 assembly (clang, -O0):
<normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0x2ef8(%rip),%xmm0
ucomisd 0x2ef0(%rip),%xmm0
jne    1180 <normal+0x50>
jp     1180 <normal+0x50>
movsd  0x2edc(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,0x2ec7(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1267 <normal+0x137>
jmp    1185 <normal+0x55>
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe53(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe22(%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)
movsd  -0x20(%rbp),%xmm0
movsd  0xdeb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1185 <normal+0x55>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2de0(%rip)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normal>:
push   %rbx
sub    $0x20,%rsp
movsd  0x2efb(%rip),%xmm0
ucomisd %xmm0,%xmm0
jp     115a <normal+0x2a>
movabs $0x7ff8000000000000,%rax
mov    %rax,0x2ee4(%rip)
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e87(%rip),%rbx
xor    %eax,%eax
call   1030 <random@plt>
movapd %xmm0,%xmm1
mov    (%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
mov    (%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
divsd  %xmm1,%xmm0
addsd  0xe47(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe2f(%rip),%xmm1
jae    1161 <normal+0x31>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e22(%rip)
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    1154 <normal+0x24>

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

LLVM IR (-O2):
@normal.n = internal unnamed_addr global double 0x7FF8000000000000
@RAND_MAX = global i32 0
define double @normal() {
%1 = load double, double* @normal.n
%2 = fcmp ord double %1, 0.000000e+00
br i1 %2, label %3, label %4
3: ; preds = %0
store double 0x7FF8000000000000, double* @normal.n
br label %29
4: ; preds = %0, %4
%5 = tail call double (...) @random()
%6 = load i32, i32* @RAND_MAX
%7 = sdiv i32 %6, 2
%8 = sitofp i32 %7 to double
%9 = fdiv double %5, %8
%10 = fadd double %9, -1.000000e+00
%11 = tail call double (...) @random()
%12 = load i32, i32* @RAND_MAX
%13 = sdiv i32 %12, 2
%14 = sitofp i32 %13 to double
%15 = fdiv double %11, %14
%16 = fadd double %15, -1.000000e+00
%17 = fmul double %16, %16
%18 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %17)
%19 = fcmp ult double %18, 1.000000e+00
br i1 %19, label %20, label %4
20: ; preds = %4
%21 = tail call i32 @log(double %18)
%22 = mul nsw i32 %21, -2
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, %18
%25 = fptosi double %24 to i32
%26 = tail call double @sqrt(i32 %25)
%27 = fmul double %16, %26
store double %27, double* @normal.n
%28 = fmul double %10, %26
br label %29
29: ; preds = %20, %3
%30 = phi double [ %1, %3 ], [ %28, %20 ]
ret double %30
}