#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 frand();
double log(float);
float sqrt(double);
float rand_norm(float m, float s) {
  static int iset = 0;
  static float gset;
  float fac, r, v1, v2, nrv;
  if (iset == 0) {
    do {
      v1 = 2.0 * frand() - 1.0;
      v2 = 2.0 * frand() - 1.0;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0);
    fac = sqrt(-2.0 * log(r) / r);
    gset = v1 * fac;
    iset = 1;
    nrv = v2 * fac;
  } else {
    iset = 0;
    nrv = gset;
  }
  return nrv * s + m;
}


x86 assembly (clang, -O0):
<rand_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
cmpl   $0x0,0x2ef3(%rip)
jne    1230 <rand_norm+0x100>
jmp    1154 <rand_norm+0x24>
mov    $0x0,%al
call   1030 <frand@plt>
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <frand@plt>
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe42(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1154 <rand_norm+0x24>
movss  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe2b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,0x2e2e(%rip)
movl   $0x1,0x2e20(%rip)
movss  -0x18(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1247 <rand_norm+0x117>
movl   $0x0,0x2e02(%rip)
movss  0x2dfe(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0x4(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_norm>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1151 <rand_norm+0x21>
movb   $0x0,0x2ef8(%rip)
movss  0x2ef4(%rip),%xmm2
jmp    1210 <rand_norm+0xe0>
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
nopl   (%rax)
xor    %eax,%eax
call   1030 <frand@plt>
addsd  %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <frand@plt>
addsd  %xmm0,%xmm0
addsd  0xe6d(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe5b(%rip),%xmm0
jae    1160 <rand_norm+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm2,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe31(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e47(%rip)
movb   $0x1,0x2e3c(%rip)
mulss  %xmm0,%xmm2
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm2
addss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@rand_norm.iset = internal global i32 0
@rand_norm.gset = internal global float 0.000000e+00
define float @rand_norm(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %3
store float %1, float* %4
%10 = load i32, i32* @rand_norm.iset
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %44
12: ; preds = %2
br label %13
13: ; preds = %26, %12
%14 = call double (...) @frand()
%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* %7
%17 = call double (...) @frand()
%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* %8
%20 = load float, float* %7
%21 = load float, float* %7
%22 = load float, float* %8
%23 = load float, float* %8
%24 = fmul float %22, %23
%25 = call float @llvm.fmuladd.f32(float %20, float %21, float %24)
store float %25, float* %6
br label %26
26: ; preds = %13
%27 = load float, float* %6
%28 = fpext float %27 to double
%29 = fcmp oge double %28, 1.000000e+00
br i1 %29, label %13, label %30
30: ; preds = %26
%31 = load float, float* %6
%32 = call double @log(float %31)
%33 = fmul double -2.000000e+00, %32
%34 = load float, float* %6
%35 = fpext float %34 to double
%36 = fdiv double %33, %35
%37 = call float @sqrt(double %36)
store float %37, float* %5
%38 = load float, float* %7
%39 = load float, float* %5
%40 = fmul float %38, %39
store float %40, float* @rand_norm.gset
store i32 1, i32* @rand_norm.iset
%41 = load float, float* %8
%42 = load float, float* %5
%43 = fmul float %41, %42
store float %43, float* %9
br label %46
44: ; preds = %2
store i32 0, i32* @rand_norm.iset
%45 = load float, float* @rand_norm.gset
store float %45, float* %9
br label %46
46: ; preds = %44, %30
%47 = load float, float* %9
%48 = load float, float* %4
%49 = load float, float* %3
%50 = call float @llvm.fmuladd.f32(float %47, float %48, float %49)
ret float %50
}

LLVM IR (-O2):
@rand_norm.iset = internal unnamed_addr global i1 false
@rand_norm.gset = internal unnamed_addr global float 0.000000e+00
define float @rand_norm(float %0, float %1) {
%3 = load i1, i1* @rand_norm.iset
br i1 %3, label %22, label %4
4: ; preds = %2, %4
%5 = tail call double (...) @frand()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fptrunc double %6 to float
%8 = tail call double (...) @frand()
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = fptrunc double %9 to float
%11 = fmul float %10, %10
%12 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %11)
%13 = fcmp ult float %12, 1.000000e+00
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = fpext float %12 to double
%16 = tail call double @log(float %12)
%17 = fmul double %16, -2.000000e+00
%18 = fdiv double %17, %15
%19 = tail call float @sqrt(double %18)
%20 = fmul float %19, %7
store float %20, float* @rand_norm.gset
store i1 true, i1* @rand_norm.iset
%21 = fmul float %19, %10
br label %24
22: ; preds = %2
store i1 false, i1* @rand_norm.iset
%23 = load float, float* @rand_norm.gset
br label %24
24: ; preds = %22, %14
%25 = phi float [ %21, %14 ], [ %23, %22 ]
%26 = tail call float @llvm.fmuladd.f32(float %25, float %1, float %0)
ret float %26
}