#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(int *idum) {
  static int iset = 0;
  static float gset;
  float fac, r, v1, v2;
  float ran1();
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1(idum) - 1.0;
      v2 = 2.0 * ran1(idum) - 1.0;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0 || r == 0.0);
    fac = sqrt(-2.0 * log(r) / r);
    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    1265 <gasdev+0x135>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe97(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe6f(%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  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    11fa <gasdev+0xca>
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  0xdf6(%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,0x2df9(%rip)
movl   $0x1,0x2deb(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    127c <gasdev+0x14c>
movl   $0x0,0x2dcd(%rip)
movss  0x2dc9(%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    121d <gasdev+0xed>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe86(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe5f(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe4d(%rip),%xmm0
jae    1160 <gasdev+0x30>
ucomiss 0xe48(%rip),%xmm0
jne    11d0 <gasdev+0xa0>
jnp    1160 <gasdev+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
call   1040 <log@plt>
mulsd  0xe18(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e2e(%rip)
movb   $0x1,0x2e23(%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(i32* %0) {
%2 = alloca float
%3 = alloca i32*
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32* %0, i32** %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 i32*, i32** %3
%13 = call float (i32*, ...) bitcast (float (...)* @ran1 to float (i32*, ...)*)(i32* %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 i32*, i32** %3
%18 = call float (i32*, ...) bitcast (float (...)* @ran1 to float (i32*, ...)*)(i32* %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(i32* %0) {
%2 = load i1, i1* @gasdev.iset
br i1 %2, label %25, label %3
3: ; preds = %1, %3
%4 = tail call float (i32*, ...) bitcast (float (...)* @ran1 to float (i32*, ...)*)(i32* %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 (i32*, ...) bitcast (float (...)* @ran1 to float (i32*, ...)*)(i32* %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
}