#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 log(float);
double ran1(long *, int);
float sqrt(double);
float randn_internal(long *idum, int reset) {
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (reset) {
    iset = 0;
  }
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1(idum, reset) - 1.0;
      v2 = 2.0 * ran1(idum, reset) - 1.0;
      rsq = v1 * v1 + v2 * v2;
    } while (rsq >= 1.0 || rsq == 0.0);
    fac = sqrt(-2.0 * log(rsq) / rsq);
    gset = v1 * fac;
    iset = 1;
    return v2 * fac;
  } else {
    iset = 0;
    return gset;
  }
}


x86 assembly (clang, -O0):
<randn_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1153 <randn_internal+0x23>
movl   $0x0,0x2ee9(%rip)
cmpl   $0x0,0x2ee2(%rip)
jne    1276 <randn_internal+0x146>
jmp    1165 <randn_internal+0x35>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe83(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe5e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
movsd  0xe25(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x25(%rbp)
jae    120b <randn_internal+0xdb>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1165 <randn_internal+0x35>
movss  -0x1c(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xde5(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x20(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,0x2de8(%rip)
movl   $0x1,0x2dda(%rip)
movss  -0x24(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    128d <randn_internal+0x15d>
movl   $0x0,0x2dbc(%rip)
movss  0x2db8(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn_internal>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
test   %esi,%esi
je     1149 <randn_internal+0x19>
movb   $0x0,0x2ef5(%rip)
jmp    1170 <randn_internal+0x40>
cmpb   $0x0,0x2eec(%rip)
je     1170 <randn_internal+0x40>
movb   $0x0,0x2ee3(%rip)
movss  0x2edf(%rip),%xmm2
jmp    1228 <randn_internal+0xf8>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe7a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
addsd  0xe56(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  0x8(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe43(%rip),%xmm0
jae    1170 <randn_internal+0x40>
ucomiss 0xe3e(%rip),%xmm0
jne    11da <randn_internal+0xaa>
jnp    1170 <randn_internal+0x40>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
call   1040 <log@plt>
mulsd  0xe0e(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0xc(%rsp),%xmm2
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e23(%rip)
movb   $0x1,0x2e18(%rip)
mulss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@randn_internal.iset = internal global i32 0
@randn_internal.gset = internal global float 0.000000e+00
define float @randn_internal(i64* %0, i32 %1) {
%3 = alloca float
%4 = alloca i64*
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store i64* %0, i64** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* @randn_internal.iset
br label %13
13: ; preds = %12, %2
%14 = load i32, i32* @randn_internal.iset
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %58
16: ; preds = %13
br label %17
17: ; preds = %42, %16
%18 = load i64*, i64** %4
%19 = load i32, i32* %5
%20 = call double @ran1(i64* %18, i32 %19)
%21 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %20, double -1.000000e+00)
%22 = fptrunc double %21 to float
store float %22, float* %8
%23 = load i64*, i64** %4
%24 = load i32, i32* %5
%25 = call double @ran1(i64* %23, i32 %24)
%26 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %25, double -1.000000e+00)
%27 = fptrunc double %26 to float
store float %27, float* %9
%28 = load float, float* %8
%29 = load float, float* %8
%30 = load float, float* %9
%31 = load float, float* %9
%32 = fmul float %30, %31
%33 = call float @llvm.fmuladd.f32(float %28, float %29, float %32)
store float %33, float* %7
br label %34
34: ; preds = %17
%35 = load float, float* %7
%36 = fpext float %35 to double
%37 = fcmp oge double %36, 1.000000e+00
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load float, float* %7
%40 = fpext float %39 to double
%41 = fcmp oeq double %40, 0.000000e+00
br label %42
42: ; preds = %38, %34
%43 = phi i1 [ true, %34 ], [ %41, %38 ]
br i1 %43, label %17, label %44
44: ; preds = %42
%45 = load float, float* %7
%46 = call double @log(float %45)
%47 = fmul double -2.000000e+00, %46
%48 = load float, float* %7
%49 = fpext float %48 to double
%50 = fdiv double %47, %49
%51 = call float @sqrt(double %50)
store float %51, float* %6
%52 = load float, float* %8
%53 = load float, float* %6
%54 = fmul float %52, %53
store float %54, float* @randn_internal.gset
store i32 1, i32* @randn_internal.iset
%55 = load float, float* %9
%56 = load float, float* %6
%57 = fmul float %55, %56
store float %57, float* %3
br label %60
58: ; preds = %13
store i32 0, i32* @randn_internal.iset
%59 = load float, float* @randn_internal.gset
store float %59, float* %3
br label %60
60: ; preds = %58, %44
%61 = load float, float* %3
ret float %61
}

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