#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 */
float RAND_MAX;
double log(float);
scalar_t__ rand();
float sqrt(double);
float rand_gauss(void) {
  float v1, v2, s;
  do {
    v1 = 2.0 * ((float)rand() / RAND_MAX) - 1;
    v2 = 2.0 * ((float)rand() / RAND_MAX) - 1;
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.0 || s == 0.0);
  return (v1 * sqrt(-2.0 * log(s) / s));
}


x86 assembly (clang, -O0):
<rand_gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e9d(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xea1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e69(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe6d(%rip),%xmm1
addsd  %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
mov    $0x1,%al
movsd  0xe34(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0xd(%rbp)
jae    11fc <rand_gauss+0xcc>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1138 <rand_gauss+0x8>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdea(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
mulss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_gauss>:
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
divss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%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
divss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%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 <rand_gauss+0x10>
ucomiss 0xe57(%rip),%xmm0
jne    11c5 <rand_gauss+0x95>
jnp    1140 <rand_gauss+0x10>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe29(%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 float 0.000000e+00
define float @rand_gauss() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
br label %4
4: ; preds = %33, %0
%5 = call i64 (...) @rand()
%6 = sitofp i64 %5 to float
%7 = load float, float* @RAND_MAX
%8 = fdiv float %6, %7
%9 = fpext float %8 to double
%10 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %9, double -1.000000e+00)
%11 = fptrunc double %10 to float
store float %11, float* %1
%12 = call i64 (...) @rand()
%13 = sitofp i64 %12 to float
%14 = load float, float* @RAND_MAX
%15 = fdiv float %13, %14
%16 = fpext float %15 to double
%17 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %16, double -1.000000e+00)
%18 = fptrunc double %17 to float
store float %18, float* %2
%19 = load float, float* %1
%20 = load float, float* %1
%21 = load float, float* %2
%22 = load float, float* %2
%23 = fmul float %21, %22
%24 = call float @llvm.fmuladd.f32(float %19, float %20, float %23)
store float %24, float* %3
br label %25
25: ; preds = %4
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = fcmp oge double %27, 1.000000e+00
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load float, float* %3
%31 = fpext float %30 to double
%32 = fcmp oeq double %31, 0.000000e+00
br label %33
33: ; preds = %29, %25
%34 = phi i1 [ true, %25 ], [ %32, %29 ]
br i1 %34, label %4, label %35
35: ; preds = %33
%36 = load float, float* %1
%37 = load float, float* %3
%38 = call double @log(float %37)
%39 = fmul double -2.000000e+00, %38
%40 = load float, float* %3
%41 = fpext float %40 to double
%42 = fdiv double %39, %41
%43 = call float @sqrt(double %42)
%44 = fmul float %36, %43
ret float %44
}

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