#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 d_rand(double, double);
double log(double);
double sqrt(double);
double norm_rand(void) {
  static int r2 = 0;
  static double nr2;
  if (r2 == 0) {
    double v1, v2, t1, t2, r1;
    do {
      v1 = d_rand(-1.0, 1.0);
      v2 = d_rand(-1.0, 1.0);
      t1 = v1 * v1 + v2 * v2;
    } while (t1 == 0.0 || t1 >= 1.0);
    t2 = sqrt(-2.0 * log(t1) / t1);
    nr2 = v2 * t2;
    r2 = 1;
    r1 = v1 * t2;
    return r1;
  } else {
    r2 = 0;
    return nr2;
  }
}


x86 assembly (clang, -O0):
<norm_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
cmpl   $0x0,0x2f01(%rip)
jne    1245 <norm_rand+0x115>
jmp    114a <norm_rand+0x1a>
movsd  0xeae(%rip),%xmm0
movsd  0xeae(%rip),%xmm1
call   1030 <d_rand@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  0xe94(%rip),%xmm1
call   1030 <d_rand@plt>
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
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jne    11c1 <norm_rand+0x91>
jp     11c1 <norm_rand+0x91>
jmp    11d8 <norm_rand+0xa8>
movsd  -0x20(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    114a <norm_rand+0x1a>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe18(%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,0x2e2b(%rip)
movl   $0x1,0x2e19(%rip)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125c <norm_rand+0x12c>
movl   $0x0,0x2df1(%rip)
movsd  0x2df1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm_rand>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <norm_rand+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm0
add    $0x18,%rsp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0xe98(%rip),%xmm0
movsd  0xe98(%rip),%xmm1
call   1030 <d_rand@plt>
movsd  %xmm0,(%rsp)
movsd  0xe7e(%rip),%xmm0
movsd  0xe7e(%rip),%xmm1
call   1030 <d_rand@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe6c(%rip),%xmm2
jne    11b0 <norm_rand+0x80>
jnp    1160 <norm_rand+0x30>
ucomisd 0xe50(%rip),%xmm2
jae    1160 <norm_rand+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe39(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ed <norm_rand+0xbd>
sqrtsd %xmm0,%xmm0
jmp    11f2 <norm_rand+0xc2>
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e44(%rip)
movb   $0x1,0x2e35(%rip)
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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