#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 fran32_r(unsigned int *, unsigned int *);
double log(float);
float sqrt(double);
float gasdev_r(unsigned *pstate0, unsigned *pstate1) {
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  if (iset == 0) {
    do {
      v1 = 2.0 * fran32_r(pstate0, pstate1) - 1.0;
      v2 = 2.0 * fran32_r(pstate0, pstate1) - 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_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,0x2ef5(%rip)
jne    1265 <gasdev_r+0x135>
jmp    1152 <gasdev_r+0x22>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fran32_r@plt>
addsd  %xmm0,%xmm0
movsd  0xe95(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fran32_r@plt>
addsd  %xmm0,%xmm0
movsd  0xe6f(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x28(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
movsd  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    11fa <gasdev_r+0xca>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1152 <gasdev_r+0x22>
movss  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdf6(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,0x2df9(%rip)
movl   $0x1,0x2deb(%rip)
movss  -0x28(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    127c <gasdev_r+0x14c>
movl   $0x0,0x2dcd(%rip)
movss  0x2dc9(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasdev_r>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmpb   $0x0,0x2efe(%rip)
je     1154 <gasdev_r+0x24>
movb   $0x0,0x2ef5(%rip)
movss  0x2ef1(%rip),%xmm2
jmp    121a <gasdev_r+0xea>
mov    %rsi,%r14
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fran32_r@plt>
addsd  %xmm0,%xmm0
movsd  0xe89(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fran32_r@plt>
addsd  %xmm0,%xmm0
addsd  0xe64(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  0x8(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe51(%rip),%xmm0
jae    1160 <gasdev_r+0x30>
ucomiss 0xe4c(%rip),%xmm0
jne    11cc <gasdev_r+0x9c>
jnp    1160 <gasdev_r+0x30>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
call   1030 <log@plt>
mulsd  0xe1c(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <sqrt@plt>
movss  0xc(%rsp),%xmm2
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e31(%rip)
movb   $0x1,0x2e26(%rip)
mulss  %xmm0,%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@gasdev_r.iset = internal unnamed_addr global i1 false
@gasdev_r.gset = internal unnamed_addr global float 0.000000e+00
define float @gasdev_r(i32* %0, i32* %1) {
%3 = load i1, i1* @gasdev_r.iset
br i1 %3, label %24, label %4
4: ; preds = %2, %4
%5 = tail call double @fran32_r(i32* %0, i32* %1)
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fptrunc double %6 to float
%8 = tail call double @fran32_r(i32* %0, i32* %1)
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = fptrunc double %9 to float
%11 = fmul float %10, %10
%12 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %11)
%13 = fcmp oge float %12, 1.000000e+00
%14 = fcmp oeq float %12, 0.000000e+00
%15 = or i1 %13, %14
br i1 %15, label %4, label %16
16: ; preds = %4
%17 = fpext float %12 to double
%18 = tail call double @log(float %12)
%19 = fmul double %18, -2.000000e+00
%20 = fdiv double %19, %17
%21 = tail call float @sqrt(double %20)
%22 = fmul float %21, %7
store float %22, float* @gasdev_r.gset
store i1 true, i1* @gasdev_r.iset
%23 = fmul float %21, %10
br label %26
24: ; preds = %2
store i1 false, i1* @gasdev_r.iset
%25 = load float, float* @gasdev_r.gset
br label %26
26: ; preds = %24, %16
%27 = phi float [ %23, %16 ], [ %25, %24 ]
ret float %27
}