#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 unirand(double, double);
double gauss_rand(double m, double s) {
  double x1, x2, w, y1;
  static double y2;
  static int use_last = 0;
  if (use_last) {
    y1 = y2;
    use_last = 0;
  } else {
    do {
      x1 = 2.0 * unirand(0.0, 1.0) - 1.0;
      x2 = 2.0 * unirand(0.0, 1.0) - 1.0;
      w = x1 * x1 + x2 * x2;
    } while (w >= 1.0);
    w = sqrt((-2.0 * log(w)) / w);
    y1 = x1 * w;
    y2 = x2 * w;
    use_last = 1;
  }
  return (m + y1 * s);
}


x86 assembly (clang, -O0):
<gauss_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
cmpl   $0x0,0x2eff(%rip)
je     116b <gauss_rand+0x3b>
movsd  0x2ee9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,0x2ee2(%rip)
jmp    1245 <gauss_rand+0x115>
jmp    1170 <gauss_rand+0x40>
xorps  %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
call   1050 <unirand@plt>
addsd  %xmm0,%xmm0
movsd  0xe74(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  0xe68(%rip),%xmm1
call   1050 <unirand@plt>
addsd  %xmm0,%xmm0
movsd  0xe4f(%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  0xe20(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1170 <gauss_rand+0x40>
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe09(%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  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2e05(%rip)
movl   $0x1,0x2e03(%rip)
movsd  -0x8(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss_rand>:
push   %rbx
sub    $0x30,%rsp
mov    0x2f0d(%rip),%bl
test   %bl,%bl
je     114c <gauss_rand+0x1c>
movsd  0x2ef9(%rip),%xmm2
jmp    1228 <gauss_rand+0xf8>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x28(%rsp)
nopl   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
movsd  0xe94(%rip),%xmm1
call   1050 <unirand@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe87(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xe69(%rip),%xmm1
call   1050 <unirand@plt>
movsd  0x10(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe5a(%rip),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
ucomisd 0xe3a(%rip),%xmm3
jae    1160 <gauss_rand+0x30>
movsd  %xmm0,0x20(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x18(%rsp)
call   1030 <log@plt>
mulsd  0xe2b(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11fb <gauss_rand+0xcb>
sqrtsd %xmm0,%xmm0
jmp    1200 <gauss_rand+0xd0>
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x2e1e(%rip)
movsd  0x28(%rsp),%xmm0
xor    $0x1,%bl
mov    %bl,0x2e17(%rip)
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@gauss_rand.y2 = internal unnamed_addr global double 0.000000e+00
@gauss_rand.use_last = internal unnamed_addr global i1 false
define double @gauss_rand(double %0, double %1) {
%3 = load i1, i1* @gauss_rand.use_last
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load double, double* @gauss_rand.y2
br label %21
6: ; preds = %2, %6
%7 = tail call double @unirand(double 0.000000e+00, double 1.000000e+00)
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%9 = tail call double @unirand(double 0.000000e+00, double 1.000000e+00)
%10 = tail call double @llvm.fmuladd.f64(double %9, double 2.000000e+00, double -1.000000e+00)
%11 = fmul double %10, %10
%12 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %11)
%13 = fcmp ult double %12, 1.000000e+00
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = tail call double @log(double %12)
%16 = fmul double %15, -2.000000e+00
%17 = fdiv double %16, %12
%18 = tail call double @sqrt(double %17)
%19 = fmul double %8, %18
%20 = fmul double %10, %18
store double %20, double* @gauss_rand.y2
br label %21
21: ; preds = %14, %4
%22 = phi double [ %5, %4 ], [ %19, %14 ]
%23 = xor i1 %3, true
store i1 %23, i1* @gauss_rand.use_last
%24 = tail call double @llvm.fmuladd.f64(double %22, double %1, double %0)
ret double %24
}