double gasdev(m, v)
double m, v;
{
  static float gset;
  float fac, r, v1, v2;
  double ran1();
  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;
  return (m + sqrt(v) * v2 * fac);
}


x86 assembly (clang, -O0):
<gasdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xeab(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe8b(%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  0xe54(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1142 <gasdev+0x12>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe39(%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,0x2e34(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x28(%rbp),%xmm1
movss  -0x20(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
movss  -0x14(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasdev>:
sub    $0x28,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xead(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
addsd  0xe8c(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movaps %xmm1,%xmm0
mulss  %xmm1,%xmm0
movss  0xc(%rsp),%xmm2
mulss  %xmm2,%xmm2
addss  %xmm0,%xmm2
ucomiss 0xe79(%rip),%xmm2
jae    1140 <gasdev+0x10>
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
call   1040 <log@plt>
mulsd  0xe4f(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ce <gasdev+0x9e>
sqrtsd %xmm0,%xmm0
jmp    11d6 <gasdev+0xa6>
call   1050 <sqrt@plt>
xorps  %xmm1,%xmm1
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jb     11ef <gasdev+0xbf>
sqrtsd %xmm0,%xmm0
jmp    1200 <gasdev+0xd0>
movss  %xmm2,0x10(%rsp)
call   1050 <sqrt@plt>
movss  0x10(%rsp),%xmm2
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
addsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@gasdev.gset = internal global float 0.000000e+00
define double @gasdev(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store double %0, double* %3
store double %1, double* %4
br label %9
9: ; preds = %22, %2
%10 = call double (...) @ran1()
%11 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %10, double -1.000000e+00)
%12 = fptrunc double %11 to float
store float %12, float* %7
%13 = call double (...) @ran1()
%14 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %13, double -1.000000e+00)
%15 = fptrunc double %14 to float
store float %15, float* %8
%16 = load float, float* %7
%17 = load float, float* %7
%18 = load float, float* %8
%19 = load float, float* %8
%20 = fmul float %18, %19
%21 = call float @llvm.fmuladd.f32(float %16, float %17, float %20)
store float %21, float* %6
br label %22
22: ; preds = %9
%23 = load float, float* %6
%24 = fpext float %23 to double
%25 = fcmp oge double %24, 1.000000e+00
br i1 %25, label %9, label %26
26: ; preds = %22
%27 = load float, float* %6
%28 = fpext float %27 to double
%29 = call double @log(double %28)
%30 = fmul double -2.000000e+00, %29
%31 = load float, float* %6
%32 = fpext float %31 to double
%33 = fdiv double %30, %32
%34 = call double @sqrt(double %33)
%35 = fptrunc double %34 to float
store float %35, float* %5
%36 = load float, float* %7
%37 = load float, float* %5
%38 = fmul float %36, %37
store float %38, float* @gasdev.gset
%39 = load double, double* %3
%40 = load double, double* %4
%41 = call double @sqrt(double %40)
%42 = load float, float* %8
%43 = fpext float %42 to double
%44 = fmul double %41, %43
%45 = load float, float* %5
%46 = fpext float %45 to double
%47 = call double @llvm.fmuladd.f64(double %44, double %46, double %39)
ret double %47
}

LLVM IR (-O2):
define double @gasdev(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double (...) @ran1()
%5 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double -1.000000e+00)
%6 = fptrunc double %5 to float
%7 = tail call double (...) @ran1()
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%9 = fptrunc double %8 to float
%10 = fmul float %9, %9
%11 = tail call float @llvm.fmuladd.f32(float %6, float %6, float %10)
%12 = fcmp ult float %11, 1.000000e+00
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = fpext float %11 to double
%15 = tail call double @log(double %14)
%16 = fmul double %15, -2.000000e+00
%17 = fdiv double %16, %14
%18 = tail call double @sqrt(double %17)
%19 = fptrunc double %18 to float
%20 = tail call double @sqrt(double %1)
%21 = fpext float %9 to double
%22 = fmul double %20, %21
%23 = fpext float %19 to double
%24 = tail call double @llvm.fmuladd.f64(double %22, double %23, double %0)
ret double %24
}