float gasdev(idum)
int *idum;
{
  static int iset = 0;
  static float gset;
  float fac, r, v1, v2;
  float ran3();
  if (iset == 0) {
    do {
      v1 = 2.0 * ran3(idum) - 1.0;
      v2 = 2.0 * ran3(idum) - 1.0;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.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    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2ef9(%rip)
jne    1242 <gasdev+0x112>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <ran3@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 <ran3@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
movsd  0xe38(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    114e <gasdev+0x1e>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe1d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,0x2e1c(%rip)
movl   $0x1,0x2e0e(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1259 <gasdev+0x129>
movl   $0x0,0x2df0(%rip)
movss  0x2dec(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%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),%xmm0
jmp    1228 <gasdev+0xf8>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <ran3@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 <ran3@plt>
movss  (%rsp),%xmm3
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe5a(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe4a(%rip),%xmm0
jae    1160 <gasdev+0x30>
movss  %xmm2,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe23(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11fa <gasdev+0xca>
sqrtsd %xmm0,%xmm0
jmp    11ff <gasdev+0xcf>
call   1050 <sqrt@plt>
movss  (%rsp),%xmm1
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
mulss  %xmm2,%xmm1
movss  %xmm1,0x2e29(%rip)
movb   $0x1,0x2e1e(%rip)
movss  0x4(%rsp),%xmm0
mulss  %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 %48
10: ; preds = %1
br label %11
11: ; preds = %28, %10
%12 = load i32*, i32** %3
%13 = call float (i32*, ...) bitcast (float (...)* @ran3 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 (...)* @ran3 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 %11, label %32
32: ; preds = %28
%33 = load float, float* %5
%34 = fpext float %33 to double
%35 = call double @log(double %34)
%36 = fmul double -2.000000e+00, %35
%37 = load float, float* %5
%38 = fpext float %37 to double
%39 = fdiv double %36, %38
%40 = call double @sqrt(double %39)
%41 = fptrunc double %40 to float
store float %41, float* %4
%42 = load float, float* %6
%43 = load float, float* %4
%44 = fmul float %42, %43
store float %44, float* @gasdev.gset
store i32 1, i32* @gasdev.iset
%45 = load float, float* %7
%46 = load float, float* %4
%47 = fmul float %45, %46
store float %47, float* %2
br label %50
48: ; preds = %1
store i32 0, i32* @gasdev.iset
%49 = load float, float* @gasdev.gset
store float %49, float* %2
br label %50
50: ; preds = %48, %32
%51 = load float, float* %2
ret float %51
}

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 %24, label %3
3: ; preds = %1, %3
%4 = tail call float (i32*, ...) bitcast (float (...)* @ran3 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 (...)* @ran3 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 ult float %13, 1.000000e+00
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = fpext float %13 to double
%17 = tail call double @log(double %16)
%18 = fmul double %17, -2.000000e+00
%19 = fdiv double %18, %16
%20 = tail call double @sqrt(double %19)
%21 = fptrunc double %20 to float
%22 = fmul float %7, %21
store float %22, float* @gasdev.gset
store i1 true, i1* @gasdev.iset
%23 = fmul float %11, %21
br label %26
24: ; preds = %1
store i1 false, i1* @gasdev.iset
%25 = load float, float* @gasdev.gset
br label %26
26: ; preds = %24, %15
%27 = phi float [ %23, %15 ], [ %25, %24 ]
ret float %27
}