float gasdev(idum)
long *idum;
{
  float ran3();
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2.0 * ran3(idum) - 1.0;
      v2 = 2.0 * ran3(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    126d <gasdev+0x13d>
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
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
cvtss2sd %xmm0,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdf2(%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,0x2df1(%rip)
movl   $0x1,0x2de3(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1284 <gasdev+0x154>
movl   $0x0,0x2dc5(%rip)
movss  0x2dc1(%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),%xmm0
jmp    1230 <gasdev+0x100>
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>
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>
movss  %xmm2,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe1b(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1202 <gasdev+0xd2>
sqrtsd %xmm0,%xmm0
jmp    1207 <gasdev+0xd7>
call   1050 <sqrt@plt>
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movss  (%rsp),%xmm1
mulss  %xmm2,%xmm1
movss  %xmm1,0x2e21(%rip)
movb   $0x1,0x2e16(%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(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 %54
10: ; preds = %1
br label %11
11: ; preds = %36, %10
%12 = load i64*, i64** %3
%13 = call float (i64*, ...) bitcast (float (...)* @ran3 to float (i64*, ...)*)(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 (i64*, ...) bitcast (float (...)* @ran3 to float (i64*, ...)*)(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 = fpext float %39 to double
%41 = call double @log(double %40)
%42 = fmul double -2.000000e+00, %41
%43 = load float, float* %5
%44 = fpext float %43 to double
%45 = fdiv double %42, %44
%46 = call double @sqrt(double %45)
%47 = fptrunc double %46 to float
store float %47, float* %4
%48 = load float, float* %6
%49 = load float, float* %4
%50 = fmul float %48, %49
store float %50, float* @gasdev.gset
store i32 1, i32* @gasdev.iset
%51 = load float, float* %7
%52 = load float, float* %4
%53 = fmul float %51, %52
store float %53, float* %2
br label %56
54: ; preds = %1
store i32 0, i32* @gasdev.iset
%55 = load float, float* @gasdev.gset
store float %55, float* %2
br label %56
56: ; preds = %54, %38
%57 = load float, float* %2
ret float %57
}

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