#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 DBL_MIN;
double M_PI;
double RAND_MAX;
double cos(double const);
double log(double);
double rand();
double sin(double const);
double sqrt(double);
double gauss(double mean, double stddev) {
  const double two_pi = 2.0 * M_PI;
  static double z0, z1;
  static bool generate = false;
  generate = !generate;
  if (!generate) {
    return z1 * stddev + mean;
  }
  double u1, u2;
  do {
    u1 = rand() * (1.0 / RAND_MAX);
    u2 = rand() * (1.0 / RAND_MAX);
  } while (u1 <= DBL_MIN);
  z0 = sqrt(-2.0 * log(u1)) * cos(two_pi * u2);
  z1 = sqrt(-2.0 * log(u1)) * sin(two_pi * u2);
  return z0 * stddev + mean;
}


x86 assembly (clang, -O0):
<gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xe96(%rip),%xmm0
mov    0x2e77(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,0x2ee7(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2ed7(%rip)
cmpl   $0x0,0x2ed0(%rip)
jne    11c2 <gauss+0x72>
movsd  0x2eba(%rip),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d2 <gauss+0x182>
jmp    11c7 <gauss+0x77>
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe32(%rip),%xmm1
mov    0x2e03(%rip),%rax
divsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe0f(%rip),%xmm1
mov    0x2de0(%rip),%rax
divsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    0x2db7(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jae    11c7 <gauss+0x77>
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdd4(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2deb(%rip)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xd8e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2dad(%rip)
movsd  0x2d9d(%rip),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e8a(%rip),%rax
movsd  (%rax),%xmm2
xor    %eax,%eax
cmpl   $0x0,0x2efd(%rip)
sete   %al
mov    %eax,0x2ef4(%rip)
je     1182 <gauss+0x32>
lea    0x2ee3(%rip),%rax
jmp    12ab <gauss+0x15b>
movsd  %xmm0,0x28(%rsp)
movsd  %xmm1,0x30(%rsp)
addsd  %xmm2,%xmm2
movsd  %xmm2,0x10(%rsp)
mov    0x2e41(%rip),%r14
mov    0x2e2a(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
movsd  0xe41(%rip),%xmm1
divsd  (%r14),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movsd  (%rbx),%xmm1
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm1
jae    11b0 <gauss+0x60>
movapd %xmm2,%xmm1
movsd  0xe0f(%rip),%xmm2
divsd  (%r14),%xmm2
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
movapd %xmm1,%xmm0
call   1050 <log@plt>
mulsd  0xdf7(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1221 <gauss+0xd1>
sqrtsd %xmm0,%xmm0
jmp    1226 <gauss+0xd6>
call   1060 <sqrt@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <cos@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x2e07(%rip)
movsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
mulsd  0xda4(%rip),%xmm0
ucomisd 0xda4(%rip),%xmm0
jb     1274 <gauss+0x124>
sqrtsd %xmm0,%xmm0
jmp    1279 <gauss+0x129>
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x2dc8(%rip)
lea    0x2db9(%rip),%rax
movsd  0x30(%rsp),%xmm1
movsd  0x28(%rsp),%xmm0
mulsd  (%rax),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@gauss.z0 = internal global double 0.000000e+00
@gauss.z1 = internal global double 0.000000e+00
@gauss.generate = internal global i32 0
@RAND_MAX = global double 0.000000e+00
@DBL_MIN = global double 0.000000e+00
define double @gauss(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* %4
store double %1, double* %5
%9 = load double, double* @M_PI
%10 = fmul double 2.000000e+00, %9
store double %10, double* %6
%11 = load i32, i32* @gauss.generate
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
store i32 %14, i32* @gauss.generate
%15 = load i32, i32* @gauss.generate
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load double, double* @gauss.z1
%19 = load double, double* %5
%20 = load double, double* %4
%21 = call double @llvm.fmuladd.f64(double %18, double %19, double %20)
store double %21, double* %3
br label %59
22: ; preds = %2
br label %23
23: ; preds = %32, %22
%24 = call double (...) @rand()
%25 = load double, double* @RAND_MAX
%26 = fdiv double 1.000000e+00, %25
%27 = fmul double %24, %26
store double %27, double* %7
%28 = call double (...) @rand()
%29 = load double, double* @RAND_MAX
%30 = fdiv double 1.000000e+00, %29
%31 = fmul double %28, %30
store double %31, double* %8
br label %32
32: ; preds = %23
%33 = load double, double* %7
%34 = load double, double* @DBL_MIN
%35 = fcmp ole double %33, %34
br i1 %35, label %23, label %36
36: ; preds = %32
%37 = load double, double* %7
%38 = call double @log(double %37)
%39 = fmul double -2.000000e+00, %38
%40 = call double @sqrt(double %39)
%41 = load double, double* %6
%42 = load double, double* %8
%43 = fmul double %41, %42
%44 = call double @cos(double %43)
%45 = fmul double %40, %44
store double %45, double* @gauss.z0
%46 = load double, double* %7
%47 = call double @log(double %46)
%48 = fmul double -2.000000e+00, %47
%49 = call double @sqrt(double %48)
%50 = load double, double* %6
%51 = load double, double* %8
%52 = fmul double %50, %51
%53 = call double @sin(double %52)
%54 = fmul double %49, %53
store double %54, double* @gauss.z1
%55 = load double, double* @gauss.z0
%56 = load double, double* %5
%57 = load double, double* %4
%58 = call double @llvm.fmuladd.f64(double %55, double %56, double %57)
store double %58, double* %3
br label %59
59: ; preds = %36, %17
%60 = load double, double* %3
ret double %60
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@gauss.z0 = internal unnamed_addr global double 0.000000e+00
@gauss.z1 = internal unnamed_addr global double 0.000000e+00
@gauss.generate = internal unnamed_addr global i32 0
@RAND_MAX = global double 0.000000e+00
@DBL_MIN = global double 0.000000e+00
define double @gauss(double %0, double %1) {
%3 = load double, double* @M_PI
%4 = fmul double %3, 2.000000e+00
%5 = load i32, i32* @gauss.generate
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
store i32 %7, i32* @gauss.generate
br i1 %6, label %8, label %31
8: ; preds = %2, %8
%9 = tail call double (...) @rand()
%10 = load double, double* @RAND_MAX
%11 = fdiv double 1.000000e+00, %10
%12 = fmul double %9, %11
%13 = tail call double (...) @rand()
%14 = load double, double* @DBL_MIN
%15 = fcmp ugt double %12, %14
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = load double, double* @RAND_MAX
%18 = fdiv double 1.000000e+00, %17
%19 = fmul double %13, %18
%20 = tail call double @log(double %12)
%21 = fmul double %20, -2.000000e+00
%22 = tail call double @sqrt(double %21)
%23 = fmul double %4, %19
%24 = tail call double @cos(double %23)
%25 = fmul double %22, %24
store double %25, double* @gauss.z0
%26 = tail call double @log(double %12)
%27 = fmul double %26, -2.000000e+00
%28 = tail call double @sqrt(double %27)
%29 = tail call double @sin(double %23)
%30 = fmul double %28, %29
store double %30, double* @gauss.z1
br label %31
31: ; preds = %2, %16
%32 = phi double* [ @gauss.z0, %16 ], [ @gauss.z1, %2 ]
%33 = load double, double* %32
%34 = tail call double @llvm.fmuladd.f64(double %33, double %1, double %0)
ret double %34
}