#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);
float sqrt(int);
float randg() {
  float randf();
  float x1, x2, norm;
  norm = 2.;
  while (norm > 1.) {
    x1 = 2. * randf() - 1;
    x2 = 2. * randf() - 1;
    norm = x1 * x1 + x2 * x2;
  }
  if (norm < 1.e-9)
    norm = 1.e-9;
  return x1 * sqrt(-2. * log(norm) / norm);
}


x86 assembly (clang, -O0):
<randg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  0xec0(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeb2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ce <randg+0x9e>
mov    $0x0,%al
call   1030 <randf@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <randf@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe85(%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)
jmp    1145 <randg+0x15>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe31(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f6 <randg+0xc6>
movss  0xe13(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe02(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
mulss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randg>:
push   %rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <randf@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <randf@plt>
movss  (%rsp),%xmm1
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe80(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
mulss  %xmm2,%xmm2
movaps %xmm1,%xmm0
mulss  %xmm1,%xmm0
addss  %xmm2,%xmm0
ucomiss 0xe7b(%rip),%xmm0
ja     1140 <randg+0x10>
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movsd  0xe5a(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    11bc <randg+0x8c>
movss  0xe60(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe3a(%rip),%xmm0
movss  0x4(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulss  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @randg() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
store float 2.000000e+00, float* %3
br label %4
4: ; preds = %8, %0
%5 = load float, float* %3
%6 = fpext float %5 to double
%7 = fcmp ogt double %6, 1.000000e+00
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = call float (...) @randf()
%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* %1
%13 = call float (...) @randf()
%14 = fpext float %13 to double
%15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double -1.000000e+00)
%16 = fptrunc double %15 to float
store float %16, float* %2
%17 = load float, float* %1
%18 = load float, float* %1
%19 = load float, float* %2
%20 = load float, float* %2
%21 = fmul float %19, %20
%22 = call float @llvm.fmuladd.f32(float %17, float %18, float %21)
store float %22, float* %3
br label %4
23: ; preds = %4
%24 = load float, float* %3
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 1.000000e-09
br i1 %26, label %27, label %28
27: ; preds = %23
store float 0x3E112E0BE0000000, float* %3
br label %28
28: ; preds = %27, %23
%29 = load float, float* %1
%30 = load float, float* %3
%31 = call i32 @log(float %30)
%32 = sitofp i32 %31 to double
%33 = fmul double -2.000000e+00, %32
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = fdiv double %33, %35
%37 = fptosi double %36 to i32
%38 = call float @sqrt(i32 %37)
%39 = fmul float %29, %38
ret float %39
}

LLVM IR (-O2):
define float @randg() {
br label %1
1: ; preds = %0, %1
%2 = tail call float (...) @randf()
%3 = fpext float %2 to double
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = fptrunc double %4 to float
%6 = tail call float (...) @randf()
%7 = fpext float %6 to double
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%9 = fptrunc double %8 to float
%10 = fmul float %9, %9
%11 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %10)
%12 = fcmp ogt float %11, 1.000000e+00
br i1 %12, label %1, label %13
13: ; preds = %1
%14 = fpext float %11 to double
%15 = fcmp olt double %14, 1.000000e-09
%16 = select i1 %15, float 0x3E112E0BE0000000, float %11
%17 = tail call i32 @log(float %16)
%18 = sitofp i32 %17 to double
%19 = fmul double %18, -2.000000e+00
%20 = fpext float %16 to double
%21 = fdiv double %19, %20
%22 = fptosi double %21 to i32
%23 = tail call float @sqrt(i32 %22)
%24 = fmul float %23, %5
ret float %24
}