#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 log(float);
double rand_uniform();
float normalvariate(float mu, float sigma) {
  float u1, u2, z, zz;
  do {
    u1 = rand_uniform();
    u2 = 1.0 - rand_uniform();
    z = 1.7155277699214135 * (u1 - 0.5) / u2;
    zz = z * z / 4.0;
  } while (zz > -log(u2));
  return mu + z * sigma;
}


x86 assembly (clang, -O0):
<normalvariate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand_uniform@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <rand_uniform@plt>
movaps %xmm0,%xmm1
movsd  0xec4(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe9e(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe52(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
ucomiss %xmm1,%xmm0
ja     1132 <normalvariate+0x12>
movss  -0x4(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalvariate>:
sub    $0x18,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <rand_uniform@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <rand_uniform@plt>
movsd  0xeb0(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  0xe9b(%rip),%xmm1
mulsd  0xe9b(%rip),%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
divsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x14(%rsp)
mulss  %xmm1,%xmm1
mulss  0xe82(%rip),%xmm1
movss  %xmm1,0x8(%rsp)
call   1030 <log@plt>
xorps  0xe78(%rip),%xmm0
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
ja     1130 <normalvariate+0x10>
movss  0x14(%rsp),%xmm0
mulss  0xc(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @normalvariate(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %3
store float %1, float* %4
br label %9
9: ; preds = %29, %2
%10 = call double (...) @rand_uniform()
%11 = fptrunc double %10 to float
store float %11, float* %5
%12 = call double (...) @rand_uniform()
%13 = fsub double 1.000000e+00, %12
%14 = fptrunc double %13 to float
store float %14, float* %6
%15 = load float, float* %5
%16 = fpext float %15 to double
%17 = fsub double %16, 5.000000e-01
%18 = fmul double 0x3FFB72CD3F331398, %17
%19 = load float, float* %6
%20 = fpext float %19 to double
%21 = fdiv double %18, %20
%22 = fptrunc double %21 to float
store float %22, float* %7
%23 = load float, float* %7
%24 = load float, float* %7
%25 = fmul float %23, %24
%26 = fpext float %25 to double
%27 = fdiv double %26, 4.000000e+00
%28 = fptrunc double %27 to float
store float %28, float* %8
br label %29
29: ; preds = %9
%30 = load float, float* %8
%31 = load float, float* %6
%32 = call float @log(float %31)
%33 = fneg float %32
%34 = fcmp ogt float %30, %33
br i1 %34, label %9, label %35
35: ; preds = %29
%36 = load float, float* %3
%37 = load float, float* %7
%38 = load float, float* %4
%39 = call float @llvm.fmuladd.f32(float %37, float %38, float %36)
ret float %39
}

LLVM IR (-O2):
define float @normalvariate(float %0, float %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double (...) @rand_uniform()
%5 = fptrunc double %4 to float
%6 = tail call double (...) @rand_uniform()
%7 = fsub double 1.000000e+00, %6
%8 = fptrunc double %7 to float
%9 = fpext float %5 to double
%10 = fadd double %9, -5.000000e-01
%11 = fmul double %10, 0x3FFB72CD3F331398
%12 = fpext float %8 to double
%13 = fdiv double %11, %12
%14 = fptrunc double %13 to float
%15 = fmul float %14, %14
%16 = fmul float %15, 2.500000e-01
%17 = tail call float @log(float %8)
%18 = fneg float %17
%19 = fcmp ogt float %16, %18
br i1 %19, label %3, label %20
20: ; preds = %3
%21 = tail call float @llvm.fmuladd.f32(float %14, float %1, float %0)
ret float %21
}