#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 *idum) {
  float ran1(long *idum);
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (*idum < 0)
    iset = 0;
  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)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1154 <gasdev+0x24>
movl   $0x0,0x2ee8(%rip)
cmpl   $0x0,0x2ee1(%rip)
jne    1279 <gasdev+0x149>
jmp    1166 <gasdev+0x36>
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe81(%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  0xe5b(%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  0xe22(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    120e <gasdev+0xde>
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    1166 <gasdev+0x36>
movss  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xde2(%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,0x2de5(%rip)
movl   $0x1,0x2dd7(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1290 <gasdev+0x160>
movl   $0x0,0x2db9(%rip)
movss  0x2db5(%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
mov    %rdi,%rbx
cmpq   $0x0,(%rdi)
js     115b <gasdev+0x2b>
cmpb   $0x0,0x2ef7(%rip)
je     1170 <gasdev+0x40>
movb   $0x0,0x2eee(%rip)
movss  0x2eea(%rip),%xmm2
jmp    1229 <gasdev+0xf9>
movb   $0x0,0x2eda(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe78(%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  0xe53(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe41(%rip),%xmm0
jae    1170 <gasdev+0x40>
ucomiss 0xe3c(%rip),%xmm0
jne    11dc <gasdev+0xac>
jnp    1170 <gasdev+0x40>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe0c(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e22(%rip)
movb   $0x1,0x2e17(%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 i64*, i64** %3
%9 = load i64, i64* %8
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* @gasdev.iset
br label %12
12: ; preds = %11, %1
%13 = load i32, i32* @gasdev.iset
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %57
15: ; preds = %12
br label %16
16: ; preds = %41, %15
%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* %6
%22 = load i64*, i64** %3
%23 = call float @ran1(i64* %22)
%24 = fpext float %23 to double
%25 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %24, double -1.000000e+00)
%26 = fptrunc double %25 to float
store float %26, float* %7
%27 = load float, float* %6
%28 = load float, float* %6
%29 = load float, float* %7
%30 = load float, float* %7
%31 = fmul float %29, %30
%32 = call float @llvm.fmuladd.f32(float %27, float %28, float %31)
store float %32, float* %5
br label %33
33: ; preds = %16
%34 = load float, float* %5
%35 = fpext float %34 to double
%36 = fcmp oge double %35, 1.000000e+00
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load float, float* %5
%39 = fpext float %38 to double
%40 = fcmp oeq double %39, 0.000000e+00
br label %41
41: ; preds = %37, %33
%42 = phi i1 [ true, %33 ], [ %40, %37 ]
br i1 %42, label %16, label %43
43: ; preds = %41
%44 = load float, float* %5
%45 = call double @log(float %44)
%46 = fmul double -2.000000e+00, %45
%47 = load float, float* %5
%48 = fpext float %47 to double
%49 = fdiv double %46, %48
%50 = call float @sqrt(double %49)
store float %50, float* %4
%51 = load float, float* %6
%52 = load float, float* %4
%53 = fmul float %51, %52
store float %53, float* @gasdev.gset
store i32 1, i32* @gasdev.iset
%54 = load float, float* %7
%55 = load float, float* %4
%56 = fmul float %54, %55
store float %56, float* %2
br label %59
57: ; preds = %12
store i32 0, i32* @gasdev.iset
%58 = load float, float* @gasdev.gset
store float %58, float* %2
br label %59
59: ; preds = %57, %43
%60 = load float, float* %2
ret float %60
}

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