#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 genrand_real1();
double log(float);
float sqrt(double);
double rnorm() {
  float x1, x2, w, y1;
  do {
    x1 = 2.0 * genrand_real1() - 1.0;
    x2 = 2.0 * genrand_real1() - 1.0;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1.0);
  w = sqrt((-2.0 * log(w)) / w);
  y1 = x1 * w;
  return y1;
}


x86 assembly (clang, -O0):
<rnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <genrand_real1@plt>
addsd  %xmm0,%xmm0
movsd  0xeb5(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <genrand_real1@plt>
addsd  %xmm0,%xmm0
movsd  0xe95(%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
movsd  0xe5e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <rnorm+0x8>
movss  -0xc(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe47(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnorm>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <genrand_real1@plt>
addsd  %xmm0,%xmm0
movsd  0xead(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1050 <genrand_real1@plt>
addsd  %xmm0,%xmm0
addsd  0xe8c(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
mulss  %xmm1,%xmm1
movss  0xc(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe7c(%rip),%xmm0
jae    1140 <rnorm+0x10>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe58(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <sqrt@plt>
mulss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @rnorm() {
br label %1
1: ; preds = %1, %0
%2 = tail call double (...) @genrand_real1()
%3 = tail call double @llvm.fmuladd.f64(double %2, double 2.000000e+00, double -1.000000e+00)
%4 = fptrunc double %3 to float
%5 = tail call double (...) @genrand_real1()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fptrunc double %6 to float
%8 = fmul float %7, %7
%9 = tail call float @llvm.fmuladd.f32(float %4, float %4, float %8)
%10 = fcmp ult float %9, 1.000000e+00
br i1 %10, label %11, label %1
11: ; preds = %1
%12 = fpext float %9 to double
%13 = tail call double @log(float %9)
%14 = fmul double %13, -2.000000e+00
%15 = fdiv double %14, %12
%16 = tail call float @sqrt(double %15)
%17 = fmul float %16, %4
%18 = fpext float %17 to double
ret double %18
}