#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 */
scalar_t__ RAND_MAX;
double log(double);
scalar_t__ rand();
double sqrt(double);
double rq_random_normal() {
  static double v2;
  static double fac;
  static int flipflop = 0;
  double r;
  if (flipflop)
    r = v2 * fac;
  else {
    double s;
    double v1;
    do {
      double u1 = (double)rand() / (double)RAND_MAX;
      double u2 = (double)rand() / (double)RAND_MAX;
      v1 = 2.0 * u1 - 1.0;
      v2 = 2.0 * u2 - 1.0;
      s = (v1 * v1) + (v2 * v2);
    } while (s >= 1.0);
    fac = sqrt(-2.0 * log(s) / s);
    r = v1 * fac;
  }
  flipflop = !flipflop;
  return r;
}


x86 assembly (clang, -O0):
<rq_random_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2f11(%rip)
je     115f <rq_random_normal+0x2f>
movsd  0x2ef3(%rip),%xmm0
mulsd  0x2ef3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <rq_random_normal+0x128>
jmp    1164 <rq_random_normal+0x34>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e71(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e50(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe49(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe2f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e63(%rip)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  0x2e51(%rip),%xmm1
mulsd  0x2e49(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1164 <rq_random_normal+0x34>
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xde0(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,0x2e02(%rip)
movsd  -0x18(%rbp),%xmm0
mulsd  0x2df5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,0x2df1(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2de1(%rip)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_random_normal>:
push   %rbx
sub    $0x10,%rsp
cmpl   $0x0,0x2f14(%rip)
je     1155 <rq_random_normal+0x25>
movsd  0x2efa(%rip),%xmm0
mulsd  0x2efa(%rip),%xmm0
xor    %eax,%eax
jmp    122e <rq_random_normal+0xfe>
mov    0x2e8c(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm3,%xmm3
cvtsi2sd %rax,%xmm3
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm3
movsd  (%rsp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe54(%rip),%xmm1
addsd  %xmm1,%xmm2
addsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,0x2e80(%rip)
mulsd  %xmm3,%xmm3
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xe30(%rip),%xmm0
jae    1160 <rq_random_normal+0x30>
movsd  %xmm2,(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe1e(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1208 <rq_random_normal+0xd8>
sqrtsd %xmm0,%xmm0
jmp    120d <rq_random_normal+0xdd>
call   1040 <sqrt@plt>
movsd  %xmm0,0x2e33(%rip)
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
xor    %eax,%eax
cmpl   $0x0,0x2e25(%rip)
sete   %al
mov    %eax,0x2e1c(%rip)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@rq_random_normal.v2 = internal global double 0.000000e+00
@rq_random_normal.fac = internal global double 0.000000e+00
@rq_random_normal.flipflop = internal global i32 0
@RAND_MAX = global i64 0
define double @rq_random_normal() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = load i32, i32* @rq_random_normal.flipflop
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load double, double* @rq_random_normal.v2
%10 = load double, double* @rq_random_normal.fac
%11 = fmul double %9, %10
store double %11, double* %1
br label %47
12: ; preds = %0
br label %13
13: ; preds = %34, %12
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
store double %18, double* %4
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %5
%24 = load double, double* %4
%25 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %24, double -1.000000e+00)
store double %25, double* %3
%26 = load double, double* %5
%27 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %26, double -1.000000e+00)
store double %27, double* @rq_random_normal.v2
%28 = load double, double* %3
%29 = load double, double* %3
%30 = load double, double* @rq_random_normal.v2
%31 = load double, double* @rq_random_normal.v2
%32 = fmul double %30, %31
%33 = call double @llvm.fmuladd.f64(double %28, double %29, double %32)
store double %33, double* %2
br label %34
34: ; preds = %13
%35 = load double, double* %2
%36 = fcmp oge double %35, 1.000000e+00
br i1 %36, label %13, label %37
37: ; preds = %34
%38 = load double, double* %2
%39 = call double @log(double %38)
%40 = fmul double -2.000000e+00, %39
%41 = load double, double* %2
%42 = fdiv double %40, %41
%43 = call double @sqrt(double %42)
store double %43, double* @rq_random_normal.fac
%44 = load double, double* %3
%45 = load double, double* @rq_random_normal.fac
%46 = fmul double %44, %45
store double %46, double* %1
br label %47
47: ; preds = %37, %8
%48 = load i32, i32* @rq_random_normal.flipflop
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
%51 = zext i1 %50 to i32
store i32 %51, i32* @rq_random_normal.flipflop
%52 = load double, double* %1
ret double %52
}

LLVM IR (-O2):
@rq_random_normal.v2 = internal unnamed_addr global double 0.000000e+00
@rq_random_normal.fac = internal unnamed_addr global double 0.000000e+00
@rq_random_normal.flipflop = internal unnamed_addr global i32 0
@RAND_MAX = global i64 0
define double @rq_random_normal() {
%1 = load i32, i32* @rq_random_normal.flipflop
%2 = icmp eq i32 %1, 0
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = load double, double* @rq_random_normal.v2
%5 = load double, double* @rq_random_normal.fac
%6 = fmul double %4, %5
br label %32
7: ; preds = %0, %7
%8 = tail call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = tail call double @llvm.fmuladd.f64(double %12, double 2.000000e+00, double -1.000000e+00)
%19 = tail call double @llvm.fmuladd.f64(double %17, double 2.000000e+00, double -1.000000e+00)
store double %19, double* @rq_random_normal.v2
%20 = fmul double %19, %19
%21 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %20)
%22 = fcmp ult double %21, 1.000000e+00
br i1 %22, label %23, label %7
23: ; preds = %7
%24 = tail call double @log(double %21)
%25 = fmul double %24, -2.000000e+00
%26 = fdiv double %25, %21
%27 = tail call double @sqrt(double %26)
store double %27, double* @rq_random_normal.fac
%28 = fmul double %18, %27
%29 = load i32, i32* @rq_random_normal.flipflop
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %23, %3
%33 = phi i32 [ 0, %3 ], [ %31, %23 ]
%34 = phi double [ %6, %3 ], [ %28, %23 ]
store i32 %33, i32* @rq_random_normal.flipflop
ret double %34
}