#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 */
int log(float);
int random_unif();
float sqrt(int);
float random_gaussian(void) {
  float v1, v2, s, m;
  do {
    v1 = 2 * random_unif() - 1;
    v2 = 2 * random_unif() - 1;
    s = v1 * v1 + v2 * v2;
  } while (s >= 1);
  m = sqrt(-2 * log(s) / s);
  return v1 * m;
}


x86 assembly (clang, -O0):
<random_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <random_unif@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <random_unif@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2ss %eax,%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
movss  0xe6e(%rip),%xmm1
ucomiss %xmm1,%xmm0
jae    1138 <random_gaussian+0x8>
movss  -0xc(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2ss %eax,%xmm0
divss  -0xc(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1050 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_gaussian>:
push   %rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random_unif@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <random_unif@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
mulss  %xmm1,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe7d(%rip),%xmm0
jae    1140 <random_gaussian+0x10>
movss  %xmm0,0x4(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1050 <sqrt@plt>
mulss  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @random_gaussian() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
br label %5
5: ; preds = %20, %0
%6 = call i32 (...) @random_unif()
%7 = mul nsw i32 2, %6
%8 = sub nsw i32 %7, 1
%9 = sitofp i32 %8 to float
store float %9, float* %1
%10 = call i32 (...) @random_unif()
%11 = mul nsw i32 2, %10
%12 = sub nsw i32 %11, 1
%13 = sitofp i32 %12 to float
store float %13, float* %2
%14 = load float, float* %1
%15 = load float, float* %1
%16 = load float, float* %2
%17 = load float, float* %2
%18 = fmul float %16, %17
%19 = call float @llvm.fmuladd.f32(float %14, float %15, float %18)
store float %19, float* %3
br label %20
20: ; preds = %5
%21 = load float, float* %3
%22 = fcmp oge float %21, 1.000000e+00
br i1 %22, label %5, label %23
23: ; preds = %20
%24 = load float, float* %3
%25 = call i32 @log(float %24)
%26 = mul nsw i32 -2, %25
%27 = sitofp i32 %26 to float
%28 = load float, float* %3
%29 = fdiv float %27, %28
%30 = fptosi float %29 to i32
%31 = call float @sqrt(i32 %30)
store float %31, float* %4
%32 = load float, float* %1
%33 = load float, float* %4
%34 = fmul float %32, %33
ret float %34
}

LLVM IR (-O2):
define float @random_gaussian() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 (...) @random_unif()
%3 = shl nsw i32 %2, 1
%4 = add nsw i32 %3, -1
%5 = sitofp i32 %4 to float
%6 = tail call i32 (...) @random_unif()
%7 = shl nsw i32 %6, 1
%8 = add nsw i32 %7, -1
%9 = sitofp i32 %8 to float
%10 = fmul float %9, %9
%11 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %10)
%12 = fcmp ult float %11, 1.000000e+00
br i1 %12, label %13, label %1
13: ; preds = %1
%14 = tail call i32 @log(float %11)
%15 = mul nsw i32 %14, -2
%16 = sitofp i32 %15 to float
%17 = fdiv float %16, %11
%18 = fptosi float %17 to i32
%19 = tail call float @sqrt(i32 %18)
%20 = fmul float %19, %5
ret float %20
}