#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);
scalar_t__ random();
double sqrt(double);
double normal_rand(double mean, double std_dev) {
  double fac, rsq, v1, v2;
  static double gset;
  static int iset;
  if (iset) {
    iset = 0;
    return mean + std_dev * gset;
  }
  do {
    v1 = 2.0 * (double)random() / 0x7fffffff - 1;
    v2 = 2.0 * (double)random() / 0x7fffffff - 1;
    rsq = v1 * v1 + v2 * v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  gset = v1 * fac;
  iset++;
  return mean + std_dev * v2 * fac;
}


x86 assembly (clang, -O0):
<normal_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cmpl   $0x0,0x2eff(%rip)
je     117d <normal_rand+0x4d>
movl   $0x0,0x2eef(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0x2ed5(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b5 <normal_rand+0x185>
jmp    1182 <normal_rand+0x52>
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe7a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe52(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe45(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe31(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe1d(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
movsd  0xde4(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jae    1240 <normal_rand+0x110>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1182 <normal_rand+0x52>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdb8(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2dbb(%rip)
mov    0x2dbd(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2db4(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normal_rand>:
sub    $0x28,%rsp
cmpl   $0x0,0x2f0d(%rip)
je     115c <normal_rand+0x2c>
movl   $0x0,0x2f01(%rip)
mulsd  0x2ef1(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe75(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe71(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
divsd  0xe44(%rip),%xmm1
addsd  0xe44(%rip),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe2e(%rip),%xmm0
jae    1170 <normal_rand+0x40>
ucomisd 0xe34(%rip),%xmm0
jne    11f0 <normal_rand+0xc0>
jnp    1170 <normal_rand+0x40>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe0f(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     121f <normal_rand+0xef>
sqrtsd %xmm0,%xmm0
jmp    1224 <normal_rand+0xf4>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addl   $0x1,0x2e0e(%rip)
movsd  %xmm2,0x2dfe(%rip)
movsd  0x18(%rsp),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
addsd  0x20(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@normal_rand.gset = internal global double 0.000000e+00
@normal_rand.iset = internal global i32 0
define double @normal_rand(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %4
store double %1, double* %5
%10 = load i32, i32* @normal_rand.iset
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
store i32 0, i32* @normal_rand.iset
%13 = load double, double* %4
%14 = load double, double* %5
%15 = load double, double* @normal_rand.gset
%16 = call double @llvm.fmuladd.f64(double %14, double %15, double %13)
store double %16, double* %3
br label %61
17: ; preds = %2
br label %18
18: ; preds = %41, %17
%19 = call i64 (...) @random()
%20 = sitofp i64 %19 to double
%21 = fmul double 2.000000e+00, %20
%22 = fdiv double %21, 0x41DFFFFFFFC00000
%23 = fsub double %22, 1.000000e+00
store double %23, double* %8
%24 = call i64 (...) @random()
%25 = sitofp i64 %24 to double
%26 = fmul double 2.000000e+00, %25
%27 = fdiv double %26, 0x41DFFFFFFFC00000
%28 = fsub double %27, 1.000000e+00
store double %28, double* %9
%29 = load double, double* %8
%30 = load double, double* %8
%31 = load double, double* %9
%32 = load double, double* %9
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %29, double %30, double %33)
store double %34, double* %7
br label %35
35: ; preds = %18
%36 = load double, double* %7
%37 = fcmp oge double %36, 1.000000e+00
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load double, double* %7
%40 = fcmp oeq double %39, 0.000000e+00
br label %41
41: ; preds = %38, %35
%42 = phi i1 [ true, %35 ], [ %40, %38 ]
br i1 %42, label %18, label %43
43: ; preds = %41
%44 = load double, double* %7
%45 = call double @log(double %44)
%46 = fmul double -2.000000e+00, %45
%47 = load double, double* %7
%48 = fdiv double %46, %47
%49 = call double @sqrt(double %48)
store double %49, double* %6
%50 = load double, double* %8
%51 = load double, double* %6
%52 = fmul double %50, %51
store double %52, double* @normal_rand.gset
%53 = load i32, i32* @normal_rand.iset
%54 = add nsw i32 %53, 1
store i32 %54, i32* @normal_rand.iset
%55 = load double, double* %4
%56 = load double, double* %5
%57 = load double, double* %9
%58 = fmul double %56, %57
%59 = load double, double* %6
%60 = call double @llvm.fmuladd.f64(double %58, double %59, double %55)
store double %60, double* %3
br label %61
61: ; preds = %43, %12
%62 = load double, double* %3
ret double %62
}

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