#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(float);
double ranf();
float sqrt(double);
float box_muller(float m, float s) {
  float x1, x2, w, y1;
  static float 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    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
cmpl   $0x0,0x2ef7(%rip)
je     116b <box_muller+0x3b>
movss  0x2ee5(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,0x2eda(%rip)
jmp    1247 <box_muller+0x117>
jmp    1170 <box_muller+0x40>
mov    $0x0,%al
call   1030 <ranf@plt>
addsd  %xmm0,%xmm0
movsd  0xe7d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <ranf@plt>
addsd  %xmm0,%xmm0
movsd  0xe5d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe26(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1170 <box_muller+0x40>
movss  -0x14(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,0x2dff(%rip)
movl   $0x1,0x2df9(%rip)
movss  -0x4(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<box_muller>:
push   %rbx
sub    $0x20,%rsp
mov    0x2f05(%rip),%bl
test   %bl,%bl
je     114c <box_muller+0x1c>
movss  0x2ef5(%rip),%xmm2
jmp    120f <box_muller+0xdf>
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0x14(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ranf@plt>
addsd  %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <ranf@plt>
movss  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm0
addsd  0xe66(%rip),%xmm0
xorps  %xmm3,%xmm3
cvtsd2ss %xmm0,%xmm3
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe56(%rip),%xmm0
jae    1160 <box_muller+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movss  %xmm3,0xc(%rsp)
call   1040 <log@plt>
mulsd  0xe2c(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x8(%rsp),%xmm2
mulss  %xmm0,%xmm2
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e39(%rip)
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
xor    $0x1,%bl
mov    %bl,0x2e28(%rip)
mulss  %xmm1,%xmm2
addss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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