#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__ drand48();
double log(double);
double sqrt(double);
float GaussDeviate(float mu, float sigma) {
  double fac, r, v1, v2, x;
  static int gaussSaved = 0;
  static float gaussSave;
  if (gaussSaved) {
    x = gaussSave;
    gaussSaved = 0;
  } else {
    do {
      v1 = 2.0 * (float)drand48() - 1.0;
      v2 = 2.0 * (float)drand48() - 1.0;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0);
    fac = sqrt(-2.0 * log(r) / r);
    gaussSaved = 1;
    gaussSave = v1 * fac;
    x = v2 * fac;
  }
  return x * sigma + mu;
}


x86 assembly (clang, -O0):
<GaussDeviate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
cmpl   $0x0,0x2ef3(%rip)
je     116f <GaussDeviate+0x3f>
movss  0x2ee9(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,0x2ed2(%rip)
jmp    124d <GaussDeviate+0x11d>
jmp    1174 <GaussDeviate+0x44>
mov    $0x0,%al
call   1050 <drand48@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1174 <GaussDeviate+0x44>
movsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe05(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,0x2e14(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x2e02(%rip)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movss  -0x4(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussDeviate>:
sub    $0x28,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1155 <GaussDeviate+0x25>
movss  0x2efb(%rip),%xmm2
cvtss2sd %xmm2,%xmm3
movb   $0x0,0x2eec(%rip)
jmp    1249 <GaussDeviate+0x119>
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <drand48@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe6e(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
movsd  0x10(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addsd  %xmm1,%xmm1
addsd  0xe3c(%rip),%xmm1
movapd %xmm1,%xmm3
mulsd  %xmm1,%xmm3
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xe28(%rip),%xmm0
jae    1170 <GaussDeviate+0x40>
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
call   1030 <log@plt>
mulsd  0xe15(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1211 <GaussDeviate+0xe1>
sqrtsd %xmm0,%xmm0
jmp    1216 <GaussDeviate+0xe6>
call   1040 <sqrt@plt>
movss  0x8(%rsp),%xmm1
movb   $0x1,0x2e19(%rip)
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
cvtsd2ss %xmm2,%xmm2
movss  %xmm2,0x2e07(%rip)
movsd  0x20(%rsp),%xmm3
mulsd  %xmm0,%xmm3
movss  0xc(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm1,%xmm2
mulsd  %xmm3,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x28,%rsp
ret

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

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