#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 */
int /*<<< orphan*/ dump_error(char *);
double exp(double);
double log(double);
double ran1(int *);
double sqrt(double);
double gamdev(int ia, int *idum) {
  int j;
  double am, e, s, v1, v2, x, y;
  if (ia < 1)
    dump_error("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    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1175 <gamdev+0x25>
lea    0xea0(%rip),%rdi
call   1030 <dump_error@plt>
cmpl   $0x6,-0x4(%rbp)
jge    11eb <gamdev+0x9b>
movsd  0xe81(%rip),%xmm0
movsd  %xmm0,-0x48(%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>
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <gamdev+0x43>
movsd  -0x48(%rbp),%xmm0
call   1060 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1363 <gamdev+0x213>
jmp    11f0 <gamdev+0xa0>
jmp    11f5 <gamdev+0xa5>
jmp    11fa <gamdev+0xaa>
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xdf1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xdd3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdae(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11fa <gamdev+0xaa>
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xd75(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jae    11f5 <gamdev+0xa5>
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd27(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ran1@plt>
ucomisd -0x28(%rbp),%xmm0
ja     11f0 <gamdev+0xa0>
jmp    1363 <gamdev+0x213>
movsd  -0x48(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamdev>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
jle    119b <gamdev+0x4b>
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x5,%edi
ja     11c5 <gamdev+0x75>
movsd  0xe94(%rip),%xmm0
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1170 <gamdev+0x20>
jmp    11af <gamdev+0x5f>
lea    0xe7e(%rip),%rdi
call   1030 <dump_error@plt>
movsd  0xe51(%rip),%xmm0
call   1060 <log@plt>
movapd %xmm0,%xmm1
xorpd  0xe50(%rip),%xmm1
jmp    1319 <gamdev+0x1c9>
add    $0xffffffff,%ebp
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x28(%rsp)
addsd  %xmm0,%xmm0
addsd  0xe22(%rip),%xmm0
movsd  %xmm0,0x30(%rsp)
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x40(%rsp)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <ran1@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe00(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movsd  0x10(%rsp),%xmm4
movapd %xmm0,%xmm3
addsd  %xmm0,%xmm3
addsd  0xdd8(%rip),%xmm3
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xdb4(%rip),%xmm1
movsd  0xdac(%rip),%xmm1
ja     11f0 <gamdev+0xa0>
movsd  0x30(%rsp),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
xorpd  %xmm0,%xmm0
movsd  0x40(%rsp),%xmm5
jae    129d <gamdev+0x14d>
movsd  0x30(%rsp),%xmm0
movsd  %xmm3,0x8(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movsd  0xd6b(%rip),%xmm1
movapd %xmm0,%xmm5
xorpd  %xmm0,%xmm0
divsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm5
movapd %xmm5,%xmm2
addsd  0x28(%rsp),%xmm2
ucomisd %xmm2,%xmm0
jae    11f0 <gamdev+0xa0>
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm2,%xmm0
divsd  0x28(%rsp),%xmm0
movapd %xmm2,0x10(%rsp)
movsd  %xmm5,0x38(%rsp)
call   1060 <log@plt>
mulsd  0x28(%rsp),%xmm0
subsd  0x38(%rsp),%xmm0
call   1040 <exp@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <ran1@plt>
movapd 0x10(%rsp),%xmm1
ucomisd 0x8(%rsp),%xmm0
ja     11f0 <gamdev+0xa0>
movapd %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

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

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