#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);
float sqrt(double);
float gasdev(long *seed) {
  float ran1(long *seed);
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1(seed) - 1.0;
      v2 = 2.0 * ran1(seed) - 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    1261 <gasdev+0x131>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe73(%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  0xe3a(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    11f6 <gasdev+0xc6>
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  0xdfa(%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,0x2dfd(%rip)
movl   $0x1,0x2def(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1278 <gasdev+0x148>
movl   $0x0,0x2dd1(%rip)
movss  0x2dcd(%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    1219 <gasdev+0xe9>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe88(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe63(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe51(%rip),%xmm0
jae    1160 <gasdev+0x30>
ucomiss 0xe4c(%rip),%xmm0
jne    11cc <gasdev+0x9c>
jnp    1160 <gasdev+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe1c(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e32(%rip)
movb   $0x1,0x2e27(%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 %52
10: ; preds = %1
br label %11
11: ; preds = %36, %10
%12 = load i64*, i64** %3
%13 = call float @ran1(i64* %12)
%14 = fpext float %13 to double
%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* %6
%17 = load i64*, i64** %3
%18 = call float @ran1(i64* %17)
%19 = fpext float %18 to double
%20 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %19, double -1.000000e+00)
%21 = fptrunc double %20 to float
store float %21, float* %7
%22 = load float, float* %6
%23 = load float, float* %6
%24 = load float, float* %7
%25 = load float, float* %7
%26 = fmul float %24, %25
%27 = call float @llvm.fmuladd.f32(float %22, float %23, float %26)
store float %27, float* %5
br label %28
28: ; preds = %11
%29 = load float, float* %5
%30 = fpext float %29 to double
%31 = fcmp oge double %30, 1.000000e+00
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load float, float* %5
%34 = fpext float %33 to double
%35 = fcmp oeq double %34, 0.000000e+00
br label %36
36: ; preds = %32, %28
%37 = phi i1 [ true, %28 ], [ %35, %32 ]
br i1 %37, label %11, label %38
38: ; preds = %36
%39 = load float, float* %5
%40 = call double @log(float %39)
%41 = fmul double -2.000000e+00, %40
%42 = load float, float* %5
%43 = fpext float %42 to double
%44 = fdiv double %41, %43
%45 = call float @sqrt(double %44)
store float %45, float* %4
%46 = load float, float* %6
%47 = load float, float* %4
%48 = fmul float %46, %47
store float %48, float* @gasdev.gset
store i32 1, i32* @gasdev.iset
%49 = load float, float* %7
%50 = load float, float* %4
%51 = fmul float %49, %50
store float %51, float* %2
br label %54
52: ; preds = %1
store i32 0, i32* @gasdev.iset
%53 = load float, float* @gasdev.gset
store float %53, float* %2
br label %54
54: ; preds = %52, %38
%55 = load float, float* %2
ret float %55
}

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