#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 ranf();
double sqrt(double);
double box_muller(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 * ranf() - 1.0;
      x2 = 2.0 * ranf() - 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):
<box_muller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
cmpl   $0x0,0x2eff(%rip)
je     116b <box_muller+0x3b>
movsd  0x2ee9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,0x2ee2(%rip)
jmp    1233 <box_muller+0x103>
jmp    1170 <box_muller+0x40>
mov    $0x0,%al
call   1030 <ranf@plt>
addsd  %xmm0,%xmm0
movsd  0xe7d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <ranf@plt>
addsd  %xmm0,%xmm0
movsd  0xe61(%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  0xe32(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1170 <box_muller+0x40>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe1b(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <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,0x2e17(%rip)
movl   $0x1,0x2e15(%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):
<box_muller>:
push   %rbx
sub    $0x30,%rsp
mov    0x2f0d(%rip),%bl
test   %bl,%bl
je     114c <box_muller+0x1c>
movsd  0x2ef9(%rip),%xmm2
jmp    1214 <box_muller+0xe4>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x28(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ranf@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1030 <ranf@plt>
movsd  0x10(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe66(%rip),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
ucomisd 0xe56(%rip),%xmm3
jae    1160 <box_muller+0x30>
movsd  %xmm0,0x20(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x18(%rsp)
call   1040 <log@plt>
mulsd  0xe3f(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e7 <box_muller+0xb7>
sqrtsd %xmm0,%xmm0
jmp    11ec <box_muller+0xbc>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x2e32(%rip)
movsd  0x28(%rsp),%xmm0
xor    $0x1,%bl
mov    %bl,0x2e2b(%rip)
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@box_muller.y2 = internal global double 0.000000e+00
@box_muller.use_last = internal global i32 0
define double @box_muller(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* @box_muller.use_last
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load double, double* @box_muller.y2
store double %12, double* %8
store i32 0, i32* @box_muller.use_last
br label %41
13: ; preds = %2
br label %14
14: ; preds = %25, %13
%15 = call double (...) @ranf()
%16 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %15, double -1.000000e+00)
store double %16, double* %5
%17 = call double (...) @ranf()
%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* @box_muller.y2
store i32 1, i32* @box_muller.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):
@box_muller.y2 = internal unnamed_addr global double 0.000000e+00
@box_muller.use_last = internal unnamed_addr global i1 false
define double @box_muller(double %0, double %1) {
%3 = load i1, i1* @box_muller.use_last
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load double, double* @box_muller.y2
br label %21
6: ; preds = %2, %6
%7 = tail call double (...) @ranf()
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%9 = tail call double (...) @ranf()
%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* @box_muller.y2
br label %21
21: ; preds = %14, %4
%22 = phi double [ %5, %4 ], [ %19, %14 ]
%23 = xor i1 %3, true
store i1 %23, i1* @box_muller.use_last
%24 = tail call double @llvm.fmuladd.f64(double %22, double %1, double %0)
ret double %24
}