#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(double);
double ran1(long *);
double sqrt(double);
double gasdev(long *idum) {
  static int iset = 0;
  static double gset;
  double fac, r, v1, v2;
  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);
    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,0x2efd(%rip)
jne    121a <gasdev+0xea>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe9d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe7f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    114e <gasdev+0x1e>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe39(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2e4c(%rip)
movl   $0x1,0x2e3a(%rip)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1231 <gasdev+0x101>
movl   $0x0,0x2e1c(%rip)
movsd  0x2e1c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasdev>:
push   %rbx
sub    $0x20,%rsp
cmpb   $0x0,0x2f04(%rip)
je     1152 <gasdev+0x22>
movb   $0x0,0x2efb(%rip)
movsd  0x2efb(%rip),%xmm1
jmp    1211 <gasdev+0xe1>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ran1@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe88(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <ran1@plt>
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe64(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe54(%rip),%xmm3
jae    1160 <gasdev+0x30>
movsd  %xmm0,0x18(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe3d(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e9 <gasdev+0xb9>
sqrtsd %xmm0,%xmm0
jmp    11ee <gasdev+0xbe>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e48(%rip)
movb   $0x1,0x2e39(%rip)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@gasdev.iset = internal unnamed_addr global i1 false
@gasdev.gset = internal unnamed_addr global double 0.000000e+00
define double @gasdev(i64* %0) {
%2 = load i1, i1* @gasdev.iset
br i1 %2, label %18, label %3
3: ; preds = %1, %3
%4 = tail call double @ran1(i64* %0)
%5 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double -1.000000e+00)
%6 = tail call double @ran1(i64* %0)
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
%8 = fmul double %7, %7
%9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
%10 = fcmp ult double %9, 1.000000e+00
br i1 %10, label %11, label %3
11: ; preds = %3
%12 = tail call double @log(double %9)
%13 = fmul double %12, -2.000000e+00
%14 = fdiv double %13, %9
%15 = tail call double @sqrt(double %14)
%16 = fmul double %5, %15
store double %16, double* @gasdev.gset
store i1 true, i1* @gasdev.iset
%17 = fmul double %7, %15
br label %20
18: ; preds = %1
store i1 false, i1* @gasdev.iset
%19 = load double, double* @gasdev.gset
br label %20
20: ; preds = %18, %11
%21 = phi double [ %17, %11 ], [ %19, %18 ]
ret double %21
}