#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);
int random();
double sqrt(double);
double xt_core_random_01();
double xt_core_random_gaussian(double mean, double stddev) {
  double x1;
  double x2;
  double w;
  double y1;
  double y2;
  double y;
  do {
    x1 = (2.0 * xt_core_random_01()) - 1.0;
    x2 = (2.0 * xt_core_random_01()) - 1.0;
    w = (x1 * x1) + (x2 * x2);
  } while (w >= 1.0);
  w = sqrt((-2.0 * log(w)) / w);
  y1 = x1 * w;
  y2 = x2 * w;
  y = ((random() % 2) == 0) ? y1 : y2;
  return (stddev * y) + (1.0 * mean);
}


x86 assembly (clang, -O0):
<xt_core_random_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <xt_core_random_01@plt>
addsd  %xmm0,%xmm0
movsd  0xe9b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <xt_core_random_01@plt>
addsd  %xmm0,%xmm0
movsd  0xe7f(%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  0xe50(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1152 <xt_core_random_gaussian+0x12>
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe39(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122f <xt_core_random_gaussian+0xef>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1239 <xt_core_random_gaussian+0xf9>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  0xdb3(%rip),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xt_core_random_gaussian>:
sub    $0x28,%rsp
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1030 <xt_core_random_01@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe99(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <xt_core_random_01@plt>
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe76(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe66(%rip),%xmm3
jae    1150 <xt_core_random_gaussian+0x10>
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,(%rsp)
call   1050 <log@plt>
mulsd  0xe50(%rip),%xmm0
divsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d5 <xt_core_random_gaussian+0x95>
sqrtsd %xmm0,%xmm0
jmp    11da <xt_core_random_gaussian+0x9a>
call   1060 <sqrt@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
test   $0x1,%al
movsd  0x8(%rsp),%xmm0
je     11f6 <xt_core_random_gaussian+0xb6>
movsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x18(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @xt_core_random_gaussian(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
%10 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %11
11: ; preds = %22, %2
%12 = call double (...) @xt_core_random_01()
%13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double -1.000000e+00)
store double %13, double* %5
%14 = call double (...) @xt_core_random_01()
%15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double -1.000000e+00)
store double %15, double* %6
%16 = load double, double* %5
%17 = load double, double* %5
%18 = load double, double* %6
%19 = load double, double* %6
%20 = fmul double %18, %19
%21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
store double %21, double* %7
br label %22
22: ; preds = %11
%23 = load double, double* %7
%24 = fcmp oge double %23, 1.000000e+00
br i1 %24, label %11, label %25
25: ; preds = %22
%26 = load double, double* %7
%27 = call double @log(double %26)
%28 = fmul double -2.000000e+00, %27
%29 = load double, double* %7
%30 = fdiv double %28, %29
%31 = call double @sqrt(double %30)
store double %31, double* %7
%32 = load double, double* %5
%33 = load double, double* %7
%34 = fmul double %32, %33
store double %34, double* %8
%35 = load double, double* %6
%36 = load double, double* %7
%37 = fmul double %35, %36
store double %37, double* %9
%38 = call i32 (...) @random()
%39 = srem i32 %38, 2
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %25
%42 = load double, double* %8
br label %45
43: ; preds = %25
%44 = load double, double* %9
br label %45
45: ; preds = %43, %41
%46 = phi double [ %42, %41 ], [ %44, %43 ]
store double %46, double* %10
%47 = load double, double* %4
%48 = load double, double* %10
%49 = load double, double* %3
%50 = fmul double 1.000000e+00, %49
%51 = call double @llvm.fmuladd.f64(double %47, double %48, double %50)
ret double %51
}

LLVM IR (-O2):
define double @xt_core_random_gaussian(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double (...) @xt_core_random_01()
%5 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double -1.000000e+00)
%6 = tail call double (...) @xt_core_random_01()
%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 = tail call i32 (...) @random()
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, double %5, double %7
%20 = fmul double %15, %19
%21 = tail call double @llvm.fmuladd.f64(double %1, double %20, double %0)
ret double %21
}