double gasdev(m, v)
double m, v;
{
  static int iset = 0;
  static float gset;
  float fac, r, v1, v2;
  double ran1();
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1() - 1.0;
      v2 = 2.0 * ran1() - 1.0;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0);
    fac = sqrt(-2.0 * log(r) / r);
    gset = v1 * fac;
    iset = 1;
    return (m + sqrt(v) * v2 * fac);
  } else {
    iset = 0;
    return (m + sqrt(v) * gset);
  }
}


x86 assembly (clang, -O0):
<gasdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cmpl   $0x0,0x2ef3(%rip)
jne    1265 <gasdev+0x135>
jmp    1154 <gasdev+0x24>
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x28(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe42(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1154 <gasdev+0x24>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe27(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,0x2e26(%rip)
movl   $0x1,0x2e18(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x30(%rbp),%xmm1
movss  -0x28(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
movss  -0x1c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a1 <gasdev+0x171>
movl   $0x0,0x2dcd(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x38(%rbp),%xmm1
movss  0x2db0(%rip),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasdev>:
sub    $0x28,%rsp
movapd %xmm0,%xmm2
cmpb   $0x0,0x2efd(%rip)
je     1162 <gasdev+0x32>
movb   $0x0,0x2ef4(%rip)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     11ff <gasdev+0xcf>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1214 <gasdev+0xe4>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x8(%rsp)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe7d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1030 <ran1@plt>
movss  0x4(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe56(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe46(%rip),%xmm0
jae    1170 <gasdev+0x40>
movss  %xmm2,0x14(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
call   1040 <log@plt>
mulsd  0xe1f(%rip),%xmm0
divsd  0x20(%rsp),%xmm0
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm0
jb     121e <gasdev+0xee>
sqrtsd %xmm0,%xmm0
jmp    1227 <gasdev+0xf7>
movapd %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movss  0x2e24(%rip),%xmm3
jmp    1286 <gasdev+0x156>
call   1050 <sqrt@plt>
xorpd  %xmm4,%xmm4
movsd  0x18(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtsd2ss %xmm0,%xmm3
mulss  %xmm3,%xmm2
movss  %xmm2,0x2dfa(%rip)
movb   $0x1,0x2def(%rip)
ucomisd %xmm4,%xmm1
jb     1259 <gasdev+0x129>
sqrtsd %xmm1,%xmm1
jmp    1272 <gasdev+0x142>
movapd %xmm1,%xmm0
movss  %xmm3,0x4(%rsp)
call   1050 <sqrt@plt>
movss  0x4(%rsp),%xmm3
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
movss  0x14(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@gasdev.iset = internal global i32 0
@gasdev.gset = internal global float 0.000000e+00
define double @gasdev(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store double %0, double* %4
store double %1, double* %5
%10 = load i32, i32* @gasdev.iset
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %52
12: ; preds = %2
br label %13
13: ; preds = %26, %12
%14 = call double (...) @ran1()
%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* %8
%17 = call double (...) @ran1()
%18 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double -1.000000e+00)
%19 = fptrunc double %18 to float
store float %19, float* %9
%20 = load float, float* %8
%21 = load float, float* %8
%22 = load float, float* %9
%23 = load float, float* %9
%24 = fmul float %22, %23
%25 = call float @llvm.fmuladd.f32(float %20, float %21, float %24)
store float %25, float* %7
br label %26
26: ; preds = %13
%27 = load float, float* %7
%28 = fpext float %27 to double
%29 = fcmp oge double %28, 1.000000e+00
br i1 %29, label %13, label %30
30: ; preds = %26
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = call double @log(double %32)
%34 = fmul double -2.000000e+00, %33
%35 = load float, float* %7
%36 = fpext float %35 to double
%37 = fdiv double %34, %36
%38 = call double @sqrt(double %37)
%39 = fptrunc double %38 to float
store float %39, float* %6
%40 = load float, float* %8
%41 = load float, float* %6
%42 = fmul float %40, %41
store float %42, float* @gasdev.gset
store i32 1, i32* @gasdev.iset
%43 = load double, double* %4
%44 = load double, double* %5
%45 = call double @sqrt(double %44)
%46 = load float, float* %9
%47 = fpext float %46 to double
%48 = fmul double %45, %47
%49 = load float, float* %6
%50 = fpext float %49 to double
%51 = call double @llvm.fmuladd.f64(double %48, double %50, double %43)
store double %51, double* %3
br label %59
52: ; preds = %2
store i32 0, i32* @gasdev.iset
%53 = load double, double* %4
%54 = load double, double* %5
%55 = call double @sqrt(double %54)
%56 = load float, float* @gasdev.gset
%57 = fpext float %56 to double
%58 = call double @llvm.fmuladd.f64(double %55, double %57, double %53)
store double %58, double* %3
br label %59
59: ; preds = %52, %30
%60 = load double, double* %3
ret double %60
}

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