#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 drand48();
double log(double);
double sqrt(double);
double gaussRNG(double avg, double var) {
  double x1, x2, w, y;
  do {
    x1 = 2.0 * drand48() - 1.0;
    x2 = 2.0 * drand48() - 1.0;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1.0);
  w = sqrt((-2.0 * log(w)) / w);
  y = x1 * w * var + avg;
  return y;
}


x86 assembly (clang, -O0):
<gaussRNG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xeab(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xe8f(%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
movsd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1142 <gaussRNG+0x12>
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe49(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussRNG>:
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
movsd  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm0
addsd  0xe86(%rip),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe7a(%rip),%xmm2
jae    1140 <gaussRNG+0x10>
movapd %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe69(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11bd <gaussRNG+0x8d>
sqrtsd %xmm0,%xmm0
jmp    11c2 <gaussRNG+0x92>
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @gaussRNG(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %9
9: ; preds = %20, %2
%10 = call double (...) @drand48()
%11 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %10, double -1.000000e+00)
store double %11, double* %5
%12 = call double (...) @drand48()
%13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double -1.000000e+00)
store double %13, double* %6
%14 = load double, double* %5
%15 = load double, double* %5
%16 = load double, double* %6
%17 = load double, double* %6
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
store double %19, double* %7
br label %20
20: ; preds = %9
%21 = load double, double* %7
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %9, label %23
23: ; preds = %20
%24 = load double, double* %7
%25 = call double @log(double %24)
%26 = fmul double -2.000000e+00, %25
%27 = load double, double* %7
%28 = fdiv double %26, %27
%29 = call double @sqrt(double %28)
store double %29, double* %7
%30 = load double, double* %5
%31 = load double, double* %7
%32 = fmul double %30, %31
%33 = load double, double* %4
%34 = load double, double* %3
%35 = call double @llvm.fmuladd.f64(double %32, double %33, double %34)
store double %35, double* %8
%36 = load double, double* %8
ret double %36
}

LLVM IR (-O2):
define double @gaussRNG(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double (...) @drand48()
%5 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double -1.000000e+00)
%6 = tail call double (...) @drand48()
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
%8 = fmul double %7, %7
%9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
%10 = fcmp ult double %9, 1.000000e+00
br i1 %10, label %11, label %3
11: ; preds = %3
%12 = tail call double @log(double %9)
%13 = fmul double %12, -2.000000e+00
%14 = fdiv double %13, %9
%15 = tail call double @sqrt(double %14)
%16 = fmul double %5, %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double %1, double %0)
ret double %17
}