#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);
  if (s == 0.0)
    return 0.0;
  else
    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,-0x8(%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,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <rand_gauss+0x8>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1205 <rand_gauss+0xd5>
jp     1205 <rand_gauss+0xd5>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    124b <rand_gauss+0x11b>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdec(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%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>
movss  0x4(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe66(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
mulss  %xmm1,%xmm1
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe59(%rip),%xmm0
jae    1140 <rand_gauss+0x10>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c3 <rand_gauss+0x93>
jnp    11f2 <rand_gauss+0xc2>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe2b(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <sqrt@plt>
movapd %xmm0,%xmm1
mulss  0x4(%rsp),%xmm1
movaps %xmm1,%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
%4 = alloca float
br label %5
5: ; preds = %26, %0
%6 = call i64 (...) @rand()
%7 = sitofp i64 %6 to float
%8 = load float, float* @RAND_MAX
%9 = fdiv float %7, %8
%10 = fpext float %9 to double
%11 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %10, double -1.000000e+00)
%12 = fptrunc double %11 to float
store float %12, float* %2
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to float
%15 = load float, float* @RAND_MAX
%16 = fdiv float %14, %15
%17 = fpext float %16 to double
%18 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double -1.000000e+00)
%19 = fptrunc double %18 to float
store float %19, float* %3
%20 = load float, float* %2
%21 = load float, float* %2
%22 = load float, float* %3
%23 = load float, float* %3
%24 = fmul float %22, %23
%25 = call float @llvm.fmuladd.f32(float %20, float %21, float %24)
store float %25, float* %4
br label %26
26: ; preds = %5
%27 = load float, float* %4
%28 = fpext float %27 to double
%29 = fcmp oge double %28, 1.000000e+00
br i1 %29, label %5, label %30
30: ; preds = %26
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = fcmp oeq double %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %30
store float 0.000000e+00, float* %1
br label %45
35: ; preds = %30
%36 = load float, float* %2
%37 = load float, float* %4
%38 = call double @log(float %37)
%39 = fmul double -2.000000e+00, %38
%40 = load float, float* %4
%41 = fpext float %40 to double
%42 = fdiv double %39, %41
%43 = call float @sqrt(double %42)
%44 = fmul float %36, %43
store float %44, float* %1
br label %45
45: ; preds = %35, %34
%46 = load float, float* %1
ret float %46
}

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 ult float %17, 1.000000e+00
br i1 %18, label %19, label %1
19: ; preds = %1
%20 = fcmp oeq float %17, 0.000000e+00
br i1 %20, label %28, label %21
21: ; preds = %19
%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
br label %28
28: ; preds = %19, %21
%29 = phi float [ %27, %21 ], [ 0.000000e+00, %19 ]
ret float %29
}