#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__ rand();
float sqrt(double);
float randn_boxmuller(void) {
  float x1, x2, w;
  do {
    x1 = 2.0 * ((float)rand()) / RAND_MAX - 1.0;
    x2 = 2.0 * ((float)rand()) / RAND_MAX - 1.0;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1.0);
  w = sqrt((-2.0 * log(w)) / w);
  x1 *= w;
  return x1;
}


x86 assembly (clang, -O0):
<randn_boxmuller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xeb8(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e8d(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe99(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe7c(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e51(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe5d(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <randn_boxmuller+0x8>
movss  -0xc(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn_boxmuller>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
divsd  (%rbx),%xmm0
movsd  0xe9d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
divsd  (%rbx),%xmm0
addsd  0xe6c(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
mulss  %xmm1,%xmm1
movss  0x4(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe5c(%rip),%xmm0
jae    1140 <randn_boxmuller+0x10>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe38(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <sqrt@plt>
mulss  0x4(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define float @randn_boxmuller() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
br label %4
4: ; preds = %27, %0
%5 = call i64 (...) @rand()
%6 = sitofp i64 %5 to float
%7 = fpext float %6 to double
%8 = fmul double 2.000000e+00, %7
%9 = load double, double* @RAND_MAX
%10 = fdiv double %8, %9
%11 = fsub double %10, 1.000000e+00
%12 = fptrunc double %11 to float
store float %12, float* %1
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to float
%15 = fpext float %14 to double
%16 = fmul double 2.000000e+00, %15
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
%19 = fsub double %18, 1.000000e+00
%20 = fptrunc double %19 to float
store float %20, float* %2
%21 = load float, float* %1
%22 = load float, float* %1
%23 = load float, float* %2
%24 = load float, float* %2
%25 = fmul float %23, %24
%26 = call float @llvm.fmuladd.f32(float %21, float %22, float %25)
store float %26, float* %3
br label %27
27: ; preds = %4
%28 = load float, float* %3
%29 = fpext float %28 to double
%30 = fcmp oge double %29, 1.000000e+00
br i1 %30, label %4, label %31
31: ; preds = %27
%32 = load float, float* %3
%33 = call double @log(float %32)
%34 = fmul double -2.000000e+00, %33
%35 = load float, float* %3
%36 = fpext float %35 to double
%37 = fdiv double %34, %36
%38 = call float @sqrt(double %37)
store float %38, float* %3
%39 = load float, float* %3
%40 = load float, float* %1
%41 = fmul float %40, %39
store float %41, float* %1
%42 = load float, float* %1
ret float %42
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define float @randn_boxmuller() {
br label %1
1: ; preds = %1, %0
%2 = tail call i64 (...) @rand()
%3 = sitofp i64 %2 to float
%4 = fpext float %3 to double
%5 = fmul double %4, 2.000000e+00
%6 = load double, double* @RAND_MAX
%7 = fdiv double %5, %6
%8 = fadd double %7, -1.000000e+00
%9 = fptrunc double %8 to float
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to float
%12 = fpext float %11 to double
%13 = fmul double %12, 2.000000e+00
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
%16 = fadd double %15, -1.000000e+00
%17 = fptrunc double %16 to float
%18 = fmul float %17, %17
%19 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %18)
%20 = fcmp ult float %19, 1.000000e+00
br i1 %20, label %21, label %1
21: ; preds = %1
%22 = fpext float %19 to double
%23 = tail call double @log(float %19)
%24 = fmul double %23, -2.000000e+00
%25 = fdiv double %24, %22
%26 = tail call float @sqrt(double %25)
%27 = fmul float %26, %9
ret float %27
}