#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 */
int log(double);
int ran3(long *);
double sqrt(int);
double gasdev(long *idum) {
  static int iset = 0;
  static double gset;
  double fac, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2 * ran3(idum) - 1;
      v2 = 2 * ran3(idum) - 1;
      rsq = v1 * v1 + v2 * v2;
    } while (rsq >= 1 || rsq == 0);
    fac = sqrt(-2 * 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    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2efd(%rip)
jne    1234 <gasdev+0x104>
jmp    114e <gasdev+0x1e>
mov    -0x10(%rbp),%rdi
call   1030 <ran3@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran3@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%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
mov    $0x1,%al
movsd  0xe52(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11d2 <gasdev+0xa2>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    114e <gasdev+0x1e>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2e32(%rip)
movl   $0x1,0x2e20(%rip)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124b <gasdev+0x11b>
movl   $0x0,0x2e02(%rip)
movsd  0x2e02(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%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    1208 <gasdev+0xd8>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ran3@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <ran3@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe54(%rip),%xmm0
jae    1160 <gasdev+0x30>
ucomisd 0xe52(%rip),%xmm0
jne    11ba <gasdev+0x8a>
jnp    1160 <gasdev+0x30>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e4b(%rip)
movb   $0x1,0x2e3c(%rip)
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 %51
10: ; preds = %1
br label %11
11: ; preds = %34, %10
%12 = load i64*, i64** %3
%13 = call i32 @ran3(i64* %12)
%14 = mul nsw i32 2, %13
%15 = sub nsw i32 %14, 1
%16 = sitofp i32 %15 to double
store double %16, double* %6
%17 = load i64*, i64** %3
%18 = call i32 @ran3(i64* %17)
%19 = mul nsw i32 2, %18
%20 = sub nsw i32 %19, 1
%21 = sitofp i32 %20 to double
store double %21, double* %7
%22 = load double, double* %6
%23 = load double, double* %6
%24 = load double, double* %7
%25 = load double, double* %7
%26 = fmul double %24, %25
%27 = call double @llvm.fmuladd.f64(double %22, double %23, double %26)
store double %27, double* %5
br label %28
28: ; preds = %11
%29 = load double, double* %5
%30 = fcmp oge double %29, 1.000000e+00
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load double, double* %5
%33 = fcmp oeq double %32, 0.000000e+00
br label %34
34: ; preds = %31, %28
%35 = phi i1 [ true, %28 ], [ %33, %31 ]
br i1 %35, label %11, label %36
36: ; preds = %34
%37 = load double, double* %5
%38 = call i32 @log(double %37)
%39 = mul nsw i32 -2, %38
%40 = sitofp i32 %39 to double
%41 = load double, double* %5
%42 = fdiv double %40, %41
%43 = fptosi double %42 to i32
%44 = call double @sqrt(i32 %43)
store double %44, double* %4
%45 = load double, double* %6
%46 = load double, double* %4
%47 = fmul double %45, %46
store double %47, double* @gasdev.gset
store i32 1, i32* @gasdev.iset
%48 = load double, double* %7
%49 = load double, double* %4
%50 = fmul double %48, %49
store double %50, double* %2
br label %53
51: ; preds = %1
store i32 0, i32* @gasdev.iset
%52 = load double, double* @gasdev.gset
store double %52, double* %2
br label %53
53: ; preds = %51, %36
%54 = load double, double* %2
ret double %54
}

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 %26, label %3
3: ; preds = %1, %3
%4 = tail call i32 @ran3(i64* %0)
%5 = shl nsw i32 %4, 1
%6 = add nsw i32 %5, -1
%7 = sitofp i32 %6 to double
%8 = tail call i32 @ran3(i64* %0)
%9 = shl nsw i32 %8, 1
%10 = add nsw i32 %9, -1
%11 = sitofp i32 %10 to double
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %12)
%14 = fcmp oge double %13, 1.000000e+00
%15 = fcmp oeq double %13, 0.000000e+00
%16 = or i1 %14, %15
br i1 %16, label %3, label %17
17: ; preds = %3
%18 = tail call i32 @log(double %13)
%19 = mul nsw i32 %18, -2
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, %13
%22 = fptosi double %21 to i32
%23 = tail call double @sqrt(i32 %22)
%24 = fmul double %23, %7
store double %24, double* @gasdev.gset
store i1 true, i1* @gasdev.iset
%25 = fmul double %23, %11
br label %28
26: ; preds = %1
store i1 false, i1* @gasdev.iset
%27 = load double, double* @gasdev.gset
br label %28
28: ; preds = %26, %17
%29 = phi double [ %25, %17 ], [ %27, %26 ]
ret double %29
}