#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);
double sqrt(double);
double xrandom(double, double);
double grandom(double mean, double sdev) {
  double v1, v2, s;
  do {
    v1 = xrandom(-1.0, 1.0);
    v2 = xrandom(-1.0, 1.0);
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.0);
  return (mean + sdev * v1 * sqrt(-2.0 * log(s) / s));
}


x86 assembly (clang, -O0):
<grandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  0xeb6(%rip),%xmm1
call   1030 <xrandom@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe9c(%rip),%xmm0
movsd  0xe9c(%rip),%xmm1
call   1030 <xrandom@plt>
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  0xe64(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1142 <grandom+0x12>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe34(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grandom>:
sub    $0x18,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
nop
movsd  0xeb8(%rip),%xmm0
movsd  0xeb8(%rip),%xmm1
call   1030 <xrandom@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe9d(%rip),%xmm0
movsd  0xe9d(%rip),%xmm1
call   1030 <xrandom@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm0
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe7a(%rip),%xmm2
jae    1140 <grandom+0x10>
mulsd  (%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1040 <log@plt>
mulsd  0xe5f(%rip),%xmm0
divsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c6 <grandom+0x96>
sqrtsd %xmm0,%xmm0
jmp    11cb <grandom+0x9b>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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