#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 eqdist();
double log(double);
double sqrt(double);
double normdist() {
  static int have_number = 0;
  static double nd2 = 0.0;
  double x1 = 0.0;
  double x2 = 0.0;
  double sqr = 0.0;
  if (!have_number) {
    do {
      x1 = 2.0 * eqdist() - 1.0;
      x2 = 2.0 * eqdist() - 1.0;
      sqr = x1 * x1 + x2 * x2;
    } while (sqr >= 1.0 || sqr == 0);
    double cnst = sqrt(-2.0 * log(sqr) / sqr);
    nd2 = x2 * cnst;
    have_number = 1;
    return x1 * cnst;
  } else {
    have_number = 0;
    return nd2;
  }
}


x86 assembly (clang, -O0):
<normdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,0x2ee9(%rip)
jne    1251 <normdist+0x121>
jmp    1162 <normdist+0x32>
mov    $0x0,%al
call   1030 <eqdist@plt>
addsd  %xmm0,%xmm0
movsd  0xe8b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <eqdist@plt>
addsd  %xmm0,%xmm0
movsd  0xe6f(%rip),%xmm1
addsd  %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
mov    $0x1,%al
movsd  0xe3e(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    11ee <normdist+0xbe>
movsd  -0x20(%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    1162 <normdist+0x32>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe02(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2e15(%rip)
movl   $0x1,0x2e03(%rip)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1268 <normdist+0x138>
movl   $0x0,0x2de5(%rip)
movsd  0x2de5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normdist>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <normdist+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm0
add    $0x18,%rsp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <eqdist@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <eqdist@plt>
addsd  %xmm0,%xmm0
addsd  0xe6d(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe58(%rip),%xmm2
jae    1160 <normdist+0x30>
ucomisd 0xe5e(%rip),%xmm2
jne    11be <normdist+0x8e>
jnp    1160 <normdist+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe35(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11f1 <normdist+0xc1>
sqrtsd %xmm0,%xmm0
jmp    11f6 <normdist+0xc6>
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e40(%rip)
movb   $0x1,0x2e31(%rip)
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@normdist.have_number = internal unnamed_addr global i1 false
@normdist.nd2 = internal unnamed_addr global double 0.000000e+00
define double @normdist() {
%1 = load i1, i1* @normdist.have_number
br i1 %1, label %19, label %2
2: ; preds = %0, %2
%3 = tail call double (...) @eqdist()
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double (...) @eqdist()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = fcmp oge double %8, 1.000000e+00
%10 = fcmp oeq double %8, 0.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = tail call double @log(double %8)
%14 = fmul double %13, -2.000000e+00
%15 = fdiv double %14, %8
%16 = tail call double @sqrt(double %15)
%17 = fmul double %6, %16
store double %17, double* @normdist.nd2
store i1 true, i1* @normdist.have_number
%18 = fmul double %4, %16
br label %21
19: ; preds = %0
store i1 false, i1* @normdist.have_number
%20 = load double, double* @normdist.nd2
br label %21
21: ; preds = %19, %12
%22 = phi double [ %20, %19 ], [ %18, %12 ]
ret double %22
}