#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, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2.0 * ran1(idum) - 1.0;
      v2 = 2.0 * ran1(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 (double)(v2 * fac);
  } else {
    iset = 0;
    return (double)gset;
  }
}


x86 assembly (clang, -O0):
<gasdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2efd(%rip)
jne    1241 <gasdev+0x111>
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
mov    $0x1,%al
movsd  0xe4e(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11de <gasdev+0xae>
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>
movaps %xmm0,%xmm1
movsd  0xe12(%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,0x2e25(%rip)
movl   $0x1,0x2e13(%rip)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <gasdev+0x128>
movl   $0x0,0x2df5(%rip)
movsd  0x2df5(%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    121d <gasdev+0xed>
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>
addsd  %xmm0,%xmm0
addsd  0xe6a(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe54(%rip),%xmm2
jae    1160 <gasdev+0x30>
ucomisd 0xe5a(%rip),%xmm2
jne    11c2 <gasdev+0x92>
jnp    1160 <gasdev+0x30>
movsd  %xmm0,0x18(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1040 <log@plt>
mulsd  0xe31(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11f5 <gasdev+0xc5>
sqrtsd %xmm0,%xmm0
jmp    11fa <gasdev+0xca>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e3c(%rip)
movb   $0x1,0x2e2d(%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 %45
10: ; preds = %1
br label %11
11: ; preds = %30, %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 %30, label %27
27: ; preds = %24
%28 = load double, double* %5
%29 = fcmp oeq double %28, 0.000000e+00
br label %30
30: ; preds = %27, %24
%31 = phi i1 [ true, %24 ], [ %29, %27 ]
br i1 %31, label %11, label %32
32: ; preds = %30
%33 = load double, double* %5
%34 = call double @log(double %33)
%35 = fmul double -2.000000e+00, %34
%36 = load double, double* %5
%37 = fdiv double %35, %36
%38 = call double @sqrt(double %37)
store double %38, double* %4
%39 = load double, double* %6
%40 = load double, double* %4
%41 = fmul double %39, %40
store double %41, double* @gasdev.gset
store i32 1, i32* @gasdev.iset
%42 = load double, double* %7
%43 = load double, double* %4
%44 = fmul double %42, %43
store double %44, double* %2
br label %47
45: ; preds = %1
store i32 0, i32* @gasdev.iset
%46 = load double, double* @gasdev.gset
store double %46, double* %2
br label %47
47: ; preds = %45, %32
%48 = load double, double* %2
ret double %48
}

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 %20, 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 oge double %9, 1.000000e+00
%11 = fcmp oeq double %9, 0.000000e+00
%12 = or i1 %10, %11
br i1 %12, label %3, label %13
13: ; preds = %3
%14 = tail call double @log(double %9)
%15 = fmul double %14, -2.000000e+00
%16 = fdiv double %15, %9
%17 = tail call double @sqrt(double %16)
%18 = fmul double %5, %17
store double %18, double* @gasdev.gset
store i1 true, i1* @gasdev.iset
%19 = fmul double %7, %17
br label %22
20: ; preds = %1
store i1 false, i1* @gasdev.iset
%21 = load double, double* @gasdev.gset
br label %22
22: ; preds = %20, %13
%23 = phi double [ %19, %13 ], [ %21, %20 ]
ret double %23
}