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


x86 assembly (clang, -O0):
<gasdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1154 <gasdev+0x24>
movl   $0x0,0x2eec(%rip)
cmpl   $0x0,0x2ee5(%rip)
jne    1259 <gasdev+0x129>
jmp    1166 <gasdev+0x36>
mov    -0x10(%rbp),%rdi
call   1030 <ran2d@plt>
addsd  %xmm0,%xmm0
movsd  0xe85(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ran2d@plt>
addsd  %xmm0,%xmm0
movsd  0xe67(%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  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11f6 <gasdev+0xc6>
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    1166 <gasdev+0x36>
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdfa(%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,0x2e0d(%rip)
movl   $0x1,0x2dfb(%rip)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1270 <gasdev+0x140>
movl   $0x0,0x2ddd(%rip)
movsd  0x2ddd(%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
mov    %rdi,%rbx
cmpq   $0x0,(%rdi)
js     115b <gasdev+0x2b>
cmpb   $0x0,0x2efb(%rip)
je     1170 <gasdev+0x40>
movb   $0x0,0x2ef2(%rip)
movsd  0x2ef2(%rip),%xmm1
jmp    122d <gasdev+0xfd>
movb   $0x0,0x2ede(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <ran2d@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe78(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <ran2d@plt>
addsd  %xmm0,%xmm0
addsd  0xe5a(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe44(%rip),%xmm2
jae    1170 <gasdev+0x40>
ucomisd 0xe4a(%rip),%xmm2
jne    11d2 <gasdev+0xa2>
jnp    1170 <gasdev+0x40>
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x18(%rsp)
call   1040 <log@plt>
mulsd  0xe21(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1205 <gasdev+0xd5>
sqrtsd %xmm0,%xmm0
jmp    120a <gasdev+0xda>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e26(%rip)
movb   $0x1,0x2e17(%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 i64*, i64** %3
%9 = load i64, i64* %8
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* @gasdev.iset
br label %12
12: ; preds = %11, %1
%13 = load i32, i32* @gasdev.iset
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %50
15: ; preds = %12
br label %16
16: ; preds = %35, %15
%17 = load i64*, i64** %3
%18 = call double @ran2d(i64* %17)
%19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double -1.000000e+00)
store double %19, double* %6
%20 = load i64*, i64** %3
%21 = call double @ran2d(i64* %20)
%22 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %21, double -1.000000e+00)
store double %22, double* %7
%23 = load double, double* %6
%24 = load double, double* %6
%25 = load double, double* %7
%26 = load double, double* %7
%27 = fmul double %25, %26
%28 = call double @llvm.fmuladd.f64(double %23, double %24, double %27)
store double %28, double* %5
br label %29
29: ; preds = %16
%30 = load double, double* %5
%31 = fcmp oge double %30, 1.000000e+00
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load double, double* %5
%34 = fcmp oeq double %33, 0.000000e+00
br label %35
35: ; preds = %32, %29
%36 = phi i1 [ true, %29 ], [ %34, %32 ]
br i1 %36, label %16, label %37
37: ; preds = %35
%38 = load double, double* %5
%39 = call double @log(double %38)
%40 = fmul double -2.000000e+00, %39
%41 = load double, double* %5
%42 = fdiv double %40, %41
%43 = call double @sqrt(double %42)
store double %43, double* %4
%44 = load double, double* %6
%45 = load double, double* %4
%46 = fmul double %44, %45
store double %46, double* @gasdev.gset
store i32 1, i32* @gasdev.iset
%47 = load double, double* %7
%48 = load double, double* %4
%49 = fmul double %47, %48
store double %49, double* %2
br label %52
50: ; preds = %12
store i32 0, i32* @gasdev.iset
%51 = load double, double* @gasdev.gset
store double %51, double* %2
br label %52
52: ; preds = %50, %37
%53 = load double, double* %2
ret double %53
}

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