#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 exp(float);
float log(float);
float sqrt(double);
float gamdev(int ia, long *idum) {
  float ran1(long *idum);
  void nrerror(char error_text[]);
  int j;
  float am, e, s, v1, v2, x, y;
  if (ia < 1)
    nrerror("Error in routine gamdev");
  if (ia < 6) {
    x = 1.0;
    for (j = 1; j <= ia; j++)
      x *= ran1(idum);
    x = -log(x);
  } else {
    do {
      do {
        do {
          v1 = ran1(idum);
          v2 = 2.0 * ran1(idum) - 1.0;
        } while (v1 * v1 + v2 * v2 > 1.0);
        y = v2 / v1;
        am = ia - 1;
        s = sqrt(2.0 * am + 1.0);
        x = s * y + am;
      } while (x <= 0.0);
      e = (1.0 + y * y) * exp(am * log(x / am) - s * y);
    } while (ran1(idum) > e);
  }
  return x;
}


x86 assembly (clang, -O0):
<gamdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1175 <gamdev+0x25>
lea    0xea4(%rip),%rdi
call   1030 <nrerror@plt>
cmpl   $0x6,-0x4(%rbp)
jge    11e1 <gamdev+0x91>
movss  0xe89(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11c0 <gamdev+0x70>
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <gamdev+0x43>
movss  -0x2c(%rbp),%xmm0
call   1060 <log@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    135a <gamdev+0x20a>
jmp    11e6 <gamdev+0x96>
jmp    11eb <gamdev+0x9b>
jmp    11f0 <gamdev+0xa0>
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xde9(%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
cvtss2sd %xmm0,%xmm0
movsd  0xdbc(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11f0 <gamdev+0xa0>
movss  -0x28(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xd7f(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x30(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    11eb <gamdev+0x9b>
movss  -0x30(%rbp),%xmm0
mulss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd29(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x2c(%rbp),%xmm0
divss  -0x18(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movss  -0x3c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
mulss  -0x30(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
ucomiss -0x1c(%rbp),%xmm0
ja     11e6 <gamdev+0x96>
jmp    135a <gamdev+0x20a>
movss  -0x2c(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamdev>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
test   %edi,%edi
jle    119b <gamdev+0x4b>
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x5,%edi
ja     11c3 <gamdev+0x73>
movss  0xea4(%rip),%xmm0
nopl   0x0(%rax)
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
movss  0x10(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1170 <gamdev+0x20>
jmp    11af <gamdev+0x5f>
lea    0xe8e(%rip),%rdi
call   1030 <nrerror@plt>
movss  0xe61(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
xorps  0xe62(%rip),%xmm1
jmp    12e0 <gamdev+0x190>
add    $0xffffffff,%ebp
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe20(%rip),%xmm0
movsd  %xmm0,0x30(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movss  0x10(%rsp),%xmm3
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xdec(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
ucomiss 0xdd4(%rip),%xmm1
ja     11f0 <gamdev+0xa0>
divss  %xmm3,%xmm2
movss  %xmm2,0x10(%rsp)
movsd  0x30(%rsp),%xmm0
call   1070 <sqrt@plt>
movss  0x10(%rsp),%xmm2
movaps %xmm0,%xmm3
mulss  %xmm2,%xmm3
movaps %xmm3,%xmm1
addss  0xc(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jae    11f0 <gamdev+0xa0>
mulss  %xmm2,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
addsd  0xd78(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movaps %xmm1,%xmm0
divss  0xc(%rsp),%xmm0
movaps %xmm1,0x10(%rsp)
movss  %xmm3,0x2c(%rsp)
call   1060 <log@plt>
mulss  0xc(%rsp),%xmm0
subss  0x2c(%rsp),%xmm0
call   1040 <exp@plt>
mulsd  0x20(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x20(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movaps 0x10(%rsp),%xmm1
ucomiss 0x20(%rsp),%xmm0
ja     11f0 <gamdev+0xa0>
movaps %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Error in routine gamdev\00"
define float @gamdev(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
store i32 %0, i32* %3
store i64* %1, i64** %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %2
br label %16
16: ; preds = %15, %2
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 6
br i1 %18, label %19, label %36
19: ; preds = %16
store float 1.000000e+00, float* %11
store i32 1, i32* %5
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i64*, i64** %4
%26 = call float @ran1(i64* %25)
%27 = load float, float* %11
%28 = fmul float %27, %26
store float %28, float* %11
br label %29
29: ; preds = %24
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %20
32: ; preds = %20
%33 = load float, float* %11
%34 = call float @log(float %33)
%35 = fneg float %34
store float %35, float* %11
br label %100
36: ; preds = %16
br label %37
37: ; preds = %94, %36
br label %38
38: ; preds = %71, %37
br label %39
39: ; preds = %47, %38
%40 = load i64*, i64** %4
%41 = call float @ran1(i64* %40)
store float %41, float* %9
%42 = load i64*, i64** %4
%43 = call float @ran1(i64* %42)
%44 = fpext float %43 to double
%45 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %44, double -1.000000e+00)
%46 = fptrunc double %45 to float
store float %46, float* %10
br label %47
47: ; preds = %39
%48 = load float, float* %9
%49 = load float, float* %9
%50 = load float, float* %10
%51 = load float, float* %10
%52 = fmul float %50, %51
%53 = call float @llvm.fmuladd.f32(float %48, float %49, float %52)
%54 = fpext float %53 to double
%55 = fcmp ogt double %54, 1.000000e+00
br i1 %55, label %39, label %56
56: ; preds = %47
%57 = load float, float* %10
%58 = load float, float* %9
%59 = fdiv float %57, %58
store float %59, float* %12
%60 = load i32, i32* %3
%61 = sub nsw i32 %60, 1
%62 = sitofp i32 %61 to float
store float %62, float* %6
%63 = load float, float* %6
%64 = fpext float %63 to double
%65 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %64, double 1.000000e+00)
%66 = call float @sqrt(double %65)
store float %66, float* %8
%67 = load float, float* %8
%68 = load float, float* %12
%69 = load float, float* %6
%70 = call float @llvm.fmuladd.f32(float %67, float %68, float %69)
store float %70, float* %11
br label %71
71: ; preds = %56
%72 = load float, float* %11
%73 = fpext float %72 to double
%74 = fcmp ole double %73, 0.000000e+00
br i1 %74, label %38, label %75
75: ; preds = %71
%76 = load float, float* %12
%77 = load float, float* %12
%78 = fmul float %76, %77
%79 = fpext float %78 to double
%80 = fadd double 1.000000e+00, %79
%81 = load float, float* %6
%82 = load float, float* %11
%83 = load float, float* %6
%84 = fdiv float %82, %83
%85 = call float @log(float %84)
%86 = load float, float* %8
%87 = load float, float* %12
%88 = fmul float %86, %87
%89 = fneg float %88
%90 = call float @llvm.fmuladd.f32(float %81, float %85, float %89)
%91 = call double @exp(float %90)
%92 = fmul double %80, %91
%93 = fptrunc double %92 to float
store float %93, float* %7
br label %94
94: ; preds = %75
%95 = load i64*, i64** %4
%96 = call float @ran1(i64* %95)
%97 = load float, float* %7
%98 = fcmp ogt float %96, %97
br i1 %98, label %37, label %99
99: ; preds = %94
br label %100
100: ; preds = %99, %32
%101 = load float, float* %11
ret float %101
}

LLVM IR (-O2):
@.str = [24 x i8] c"Error in routine gamdev\00"
define float @gamdev(i32 %0, i64* %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %5
4: ; preds = %2
tail call void @nrerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %19
5: ; preds = %2
%6 = icmp ult i32 %0, 6
br i1 %6, label %12, label %7
7: ; preds = %5
%8 = add nsw i32 %0, -1
%9 = sitofp i32 %8 to float
%10 = fpext float %9 to double
%11 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double 1.000000e+00)
br label %23
12: ; preds = %5, %12
%13 = phi i32 [ %17, %12 ], [ 1, %5 ]
%14 = phi float [ %16, %12 ], [ 1.000000e+00, %5 ]
%15 = tail call float @ran1(i64* %1)
%16 = fmul float %14, %15
%17 = add nuw i32 %13, 1
%18 = icmp eq i32 %13, %0
br i1 %18, label %19, label %12
19: ; preds = %12, %4
%20 = phi float [ 1.000000e+00, %4 ], [ %16, %12 ]
%21 = tail call float @log(float %20)
%22 = fneg float %21
br label %52
23: ; preds = %32, %7
%24 = tail call float @ran1(i64* %1)
%25 = tail call float @ran1(i64* %1)
%26 = fpext float %25 to double
%27 = tail call double @llvm.fmuladd.f64(double %26, double 2.000000e+00, double -1.000000e+00)
%28 = fptrunc double %27 to float
%29 = fmul float %28, %28
%30 = tail call float @llvm.fmuladd.f32(float %24, float %24, float %29)
%31 = fcmp ogt float %30, 1.000000e+00
br i1 %31, label %32, label %33
32: ; preds = %23, %38, %33
br label %23
33: ; preds = %23
%34 = fdiv float %28, %24
%35 = tail call float @sqrt(double %11)
%36 = tail call float @llvm.fmuladd.f32(float %35, float %34, float %9)
%37 = fcmp ugt float %36, 0.000000e+00
br i1 %37, label %38, label %32
38: ; preds = %33
%39 = fmul float %34, %34
%40 = fpext float %39 to double
%41 = fadd double %40, 1.000000e+00
%42 = fdiv float %36, %9
%43 = tail call float @log(float %42)
%44 = fneg float %35
%45 = fmul float %34, %44
%46 = tail call float @llvm.fmuladd.f32(float %9, float %43, float %45)
%47 = tail call double @exp(float %46)
%48 = fmul double %41, %47
%49 = fptrunc double %48 to float
%50 = tail call float @ran1(i64* %1)
%51 = fcmp ogt float %50, %49
br i1 %51, label %32, label %52
52: ; preds = %38, %19
%53 = phi float [ %22, %19 ], [ %36, %38 ]
ret float %53
}