#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 = 2.0 * ran1(idum) - 1.0;
          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    1372 <gamdev+0x222>
jmp    11e6 <gamdev+0x96>
jmp    11eb <gamdev+0x9b>
jmp    11f0 <gamdev+0xa0>
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xdf7(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xdd1(%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  0xda4(%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  0xd67(%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  0xd11(%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    1372 <gamdev+0x222>
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    12f8 <gamdev+0x1a8>
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>
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe00(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movss  0x10(%rsp),%xmm3
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  0xdd4(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
ucomiss 0xdbc(%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  0xd60(%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 %103
36: ; preds = %16
br label %37
37: ; preds = %97, %36
br label %38
38: ; preds = %74, %37
br label %39
39: ; preds = %50, %38
%40 = load i64*, i64** %4
%41 = call float @ran1(i64* %40)
%42 = fpext float %41 to double
%43 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %42, double -1.000000e+00)
%44 = fptrunc double %43 to float
store float %44, float* %9
%45 = load i64*, i64** %4
%46 = call float @ran1(i64* %45)
%47 = fpext float %46 to double
%48 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %47, double -1.000000e+00)
%49 = fptrunc double %48 to float
store float %49, float* %10
br label %50
50: ; preds = %39
%51 = load float, float* %9
%52 = load float, float* %9
%53 = load float, float* %10
%54 = load float, float* %10
%55 = fmul float %53, %54
%56 = call float @llvm.fmuladd.f32(float %51, float %52, float %55)
%57 = fpext float %56 to double
%58 = fcmp ogt double %57, 1.000000e+00
br i1 %58, label %39, label %59
59: ; preds = %50
%60 = load float, float* %10
%61 = load float, float* %9
%62 = fdiv float %60, %61
store float %62, float* %12
%63 = load i32, i32* %3
%64 = sub nsw i32 %63, 1
%65 = sitofp i32 %64 to float
store float %65, float* %6
%66 = load float, float* %6
%67 = fpext float %66 to double
%68 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %67, double 1.000000e+00)
%69 = call float @sqrt(double %68)
store float %69, float* %8
%70 = load float, float* %8
%71 = load float, float* %12
%72 = load float, float* %6
%73 = call float @llvm.fmuladd.f32(float %70, float %71, float %72)
store float %73, float* %11
br label %74
74: ; preds = %59
%75 = load float, float* %11
%76 = fpext float %75 to double
%77 = fcmp ole double %76, 0.000000e+00
br i1 %77, label %38, label %78
78: ; preds = %74
%79 = load float, float* %12
%80 = load float, float* %12
%81 = fmul float %79, %80
%82 = fpext float %81 to double
%83 = fadd double 1.000000e+00, %82
%84 = load float, float* %6
%85 = load float, float* %11
%86 = load float, float* %6
%87 = fdiv float %85, %86
%88 = call float @log(float %87)
%89 = load float, float* %8
%90 = load float, float* %12
%91 = fmul float %89, %90
%92 = fneg float %91
%93 = call float @llvm.fmuladd.f32(float %84, float %88, float %92)
%94 = call double @exp(float %93)
%95 = fmul double %83, %94
%96 = fptrunc double %95 to float
store float %96, float* %7
br label %97
97: ; preds = %78
%98 = load i64*, i64** %4
%99 = call float @ran1(i64* %98)
%100 = load float, float* %7
%101 = fcmp ogt float %99, %100
br i1 %101, label %37, label %102
102: ; preds = %97
br label %103
103: ; preds = %102, %32
%104 = load float, float* %11
ret float %104
}

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 %55
23: ; preds = %35, %7
%24 = tail call float @ran1(i64* %1)
%25 = fpext float %24 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 2.000000e+00, double -1.000000e+00)
%27 = fptrunc double %26 to float
%28 = tail call float @ran1(i64* %1)
%29 = fpext float %28 to double
%30 = tail call double @llvm.fmuladd.f64(double %29, double 2.000000e+00, double -1.000000e+00)
%31 = fptrunc double %30 to float
%32 = fmul float %31, %31
%33 = tail call float @llvm.fmuladd.f32(float %27, float %27, float %32)
%34 = fcmp ogt float %33, 1.000000e+00
br i1 %34, label %35, label %36
35: ; preds = %23, %41, %36
br label %23
36: ; preds = %23
%37 = fdiv float %31, %27
%38 = tail call float @sqrt(double %11)
%39 = tail call float @llvm.fmuladd.f32(float %38, float %37, float %9)
%40 = fcmp ugt float %39, 0.000000e+00
br i1 %40, label %41, label %35
41: ; preds = %36
%42 = fmul float %37, %37
%43 = fpext float %42 to double
%44 = fadd double %43, 1.000000e+00
%45 = fdiv float %39, %9
%46 = tail call float @log(float %45)
%47 = fneg float %38
%48 = fmul float %37, %47
%49 = tail call float @llvm.fmuladd.f32(float %9, float %46, float %48)
%50 = tail call double @exp(float %49)
%51 = fmul double %44, %50
%52 = fptrunc double %51 to float
%53 = tail call float @ran1(i64* %1)
%54 = fcmp ogt float %53, %52
br i1 %54, label %35, label %55
55: ; preds = %41, %19
%56 = phi float [ %22, %19 ], [ %39, %41 ]
ret float %56
}