#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 M_PI;
double cos(double);
double log(double);
double randbl();
double sqrt(double);
double randn() {
  double x1, x2;
  do {
    x1 = randbl();
  } while (x1 == 0);
  x2 = randbl();
  double z = sqrt(-2.0 * log(x1)) * cos(2.0 * M_PI * x2);
  return z;
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <randbl@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <randn+0x31>
jp     1171 <randn+0x31>
jmp    1148 <randn+0x8>
mov    $0x0,%al
call   1030 <randbl@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe58(%rip),%xmm0
mov    0x2e39(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <randbl@plt>
ucomisd 0xea9(%rip),%xmm0
jne    1163 <randn+0x23>
jnp    1150 <randn+0x10>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1030 <randbl@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
mulsd  0xe77(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1199 <randn+0x59>
sqrtsd %xmm0,%xmm0
jmp    119e <randn+0x5e>
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x2e3d(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @randn() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
br label %4
4: ; preds = %6, %0
%5 = call double (...) @randbl()
store double %5, double* %1
br label %6
6: ; preds = %4
%7 = load double, double* %1
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %4, label %9
9: ; preds = %6
%10 = call double (...) @randbl()
store double %10, double* %2
%11 = load double, double* %1
%12 = call double @log(double %11)
%13 = fmul double -2.000000e+00, %12
%14 = call double @sqrt(double %13)
%15 = load double, double* @M_PI
%16 = fmul double 2.000000e+00, %15
%17 = load double, double* %2
%18 = fmul double %16, %17
%19 = call double @cos(double %18)
%20 = fmul double %14, %19
store double %20, double* %3
%21 = load double, double* %3
ret double %21
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @randn() {
br label %1
1: ; preds = %1, %0
%2 = tail call double (...) @randbl()
%3 = fcmp oeq double %2, 0.000000e+00
br i1 %3, label %1, label %4
4: ; preds = %1
%5 = tail call double (...) @randbl()
%6 = tail call double @log(double %2)
%7 = fmul double %6, -2.000000e+00
%8 = tail call double @sqrt(double %7)
%9 = load double, double* @M_PI
%10 = fmul double %9, 2.000000e+00
%11 = fmul double %5, %10
%12 = tail call double @cos(double %11)
%13 = fmul double %8, %12
ret double %13
}