#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 RAND_MAX;
double log(float);
scalar_t__ random();
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 * ((double)random() / RAND_MAX) - 1.0;
      x2 = 2.0 * ((double)random() / RAND_MAX) - 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,0x2efb(%rip)
je     116b <box_muller+0x3b>
movss  0x2ee9(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,0x2ede(%rip)
jmp    1267 <box_muller+0x137>
jmp    1170 <box_muller+0x40>
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e65(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe6d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e35(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe3d(%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  0xe06(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1170 <box_muller+0x40>
movss  -0x14(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdef(%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,0x2de3(%rip)
movl   $0x1,0x2ddd(%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   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2f07(%rip),%bpl
test   %bpl,%bpl
je     114f <box_muller+0x1f>
movss  0x2ef6(%rip),%xmm2
jmp    1234 <box_muller+0x104>
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
mov    0x2e86(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe71(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
movss  (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
addsd  0xe40(%rip),%xmm0
xorps  %xmm3,%xmm3
cvtsd2ss %xmm0,%xmm3
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe30(%rip),%xmm0
jae    1170 <box_muller+0x40>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm3,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe06(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  (%rsp),%xmm2
mulss  %xmm0,%xmm2
movss  0x4(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e18(%rip)
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
xor    $0x1,%bpl
mov    %bpl,0x2e05(%rip)
mulss  %xmm1,%xmm2
addss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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