#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 *);
float sqrt(double);
float gasdev(long *idum) {
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1(idum) - 1.0;
      v2 = 2.0 * ran1(idum) - 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):
<gasdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2ef9(%rip)
jne    1259 <gasdev+0x129>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe9d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe7b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movss  -0x20(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
movsd  0xe42(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    11ee <gasdev+0xbe>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    114e <gasdev+0x1e>
movss  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe02(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,0x2e05(%rip)
movl   $0x1,0x2df7(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1270 <gasdev+0x140>
movl   $0x0,0x2dd9(%rip)
movss  0x2dd5(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasdev>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,0x2f00(%rip)
je     1152 <gasdev+0x22>
movb   $0x0,0x2ef7(%rip)
movss  0x2ef3(%rip),%xmm2
jmp    1211 <gasdev+0xe1>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe8c(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
addsd  0xe6b(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe59(%rip),%xmm0
jae    1160 <gasdev+0x30>
ucomiss 0xe54(%rip),%xmm0
jne    11c4 <gasdev+0x94>
jnp    1160 <gasdev+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe24(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e3a(%rip)
movb   $0x1,0x2e2f(%rip)
mulss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

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