#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 RAND_MAX;
int log(double);
scalar_t__ rand();
double sqrt(int);
double GetNormal(int mu, int sigma) {
  double U1, U2, W, mult;
  static double X1, X2;
  static int call = 0;
  if (call) {
    call = 0;
    return (mu + sigma * (double)X2);
  }
  do {
    U1 = -1 + ((double)rand() / RAND_MAX) * 2;
    U2 = -1 + ((double)rand() / RAND_MAX) * 2;
    W = U1 * U1 + U2 * U2;
  } while (W >= 1 || W == 0);
  mult = sqrt((-2 * log(W)) / W);
  X1 = U1 * mult;
  X2 = U2 * mult;
  call = 1;
  return (mu + sigma * (double)X1);
}


x86 assembly (clang, -O0):
<GetNormal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,0x2f0b(%rip)
je     1179 <GetNormal+0x49>
movl   $0x0,0x2efb(%rip)
cvtsi2sdl -0xc(%rbp),%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0x2ee1(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a9 <GetNormal+0x179>
jmp    117e <GetNormal+0x4e>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e57(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe5f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e2b(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe33(%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,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe02(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    122a <GetNormal+0xfa>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117e <GetNormal+0x4e>
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2dd2(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2dc8(%rip)
movl   $0x1,0x2dc6(%rip)
cvtsi2sdl -0xc(%rbp),%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0x2da4(%rip),%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):
<GetNormal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
cmpb   $0x0,0x2f04(%rip)
je     1163 <GetNormal+0x33>
cvtsi2sd %ebp,%xmm1
cvtsi2sd %r14d,%xmm0
movb   $0x0,0x2ef2(%rip)
mulsd  0x2ee2(%rip),%xmm0
jmp    1245 <GetNormal+0x115>
mov    0x2e7e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe71(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
addsd  0xe48(%rip),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe32(%rip),%xmm0
jae    1170 <GetNormal+0x40>
ucomisd 0xe30(%rip),%xmm0
jne    11e4 <GetNormal+0xb4>
jnp    1170 <GetNormal+0x40>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e15(%rip)
movb   $0x1,0x2e16(%rip)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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