#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 log(double);
double sqrt(double);
double uniformrng();
double normalrng(void) {
  static int normalrng_IR = 0;
  static double normalrng_AN;
  double c;
  double w;
  double v1;
  double v2;
  double rnd;
  if (normalrng_IR == 0) {
    do {
      v1 = 2.0 * uniformrng() - 1.0;
      v2 = 2.0 * uniformrng() - 1.0;
      w = v1 * v1 + v2 * v2;
    } while (w >= 1.0);
    c = sqrt(-2.0 * log(w) / w);
    normalrng_AN = v1 * c;
    normalrng_IR = 1;
    rnd = v2 * c;
  } else {
    normalrng_IR = 0;
    rnd = normalrng_AN;
  }
  return rnd;
}


x86 assembly (clang, -O0):
<normalrng>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2f01(%rip)
jne    1212 <normalrng+0xe2>
jmp    114a <normalrng+0x1a>
mov    $0x0,%al
call   1030 <uniformrng@plt>
addsd  %xmm0,%xmm0
movsd  0xea3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <uniformrng@plt>
addsd  %xmm0,%xmm0
movsd  0xe87(%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  0xe58(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    114a <normalrng+0x1a>
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe41(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2e54(%rip)
movl   $0x1,0x2e42(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1229 <normalrng+0xf9>
movl   $0x0,0x2e24(%rip)
movsd  0x2e24(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalrng>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <normalrng+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm1
jmp    120c <normalrng+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <uniformrng@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <uniformrng@plt>
movsd  (%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe68(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe58(%rip),%xmm3
jae    1160 <normalrng+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe41(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e5 <normalrng+0xb5>
sqrtsd %xmm0,%xmm0
jmp    11ea <normalrng+0xba>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e4d(%rip)
movb   $0x1,0x2e3e(%rip)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@normalrng.normalrng_IR = internal unnamed_addr global i1 false
@normalrng.normalrng_AN = internal unnamed_addr global double 0.000000e+00
define double @normalrng() {
%1 = load i1, i1* @normalrng.normalrng_IR
br i1 %1, label %17, label %2
2: ; preds = %0, %2
%3 = tail call double (...) @uniformrng()
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double (...) @uniformrng()
%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 ult double %8, 1.000000e+00
br i1 %9, label %10, label %2
10: ; preds = %2
%11 = tail call double @log(double %8)
%12 = fmul double %11, -2.000000e+00
%13 = fdiv double %12, %8
%14 = tail call double @sqrt(double %13)
%15 = fmul double %4, %14
store double %15, double* @normalrng.normalrng_AN
store i1 true, i1* @normalrng.normalrng_IR
%16 = fmul double %6, %14
br label %19
17: ; preds = %0
store i1 false, i1* @normalrng.normalrng_IR
%18 = load double, double* @normalrng.normalrng_AN
br label %19
19: ; preds = %17, %10
%20 = phi double [ %16, %10 ], [ %18, %17 ]
ret double %20
}