#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 */
scalar_t__ LnGamma(double);
int /*<<< orphan*/ error2(char *);
double exp(scalar_t__);
double pow(double, double);
int /*<<< orphan*/ printf(char *, double, double, double);
double PDFGamma(double x, double alpha, double beta) {
  if (x <= 0 || alpha <= 0 || beta <= 0) {
    printf("x=%.6f a=%.6f b=%.6f", x, alpha, beta);
    error2("x a b outside range in PDFGamma()");
  }
  if (alpha > 100)
    error2("large alpha in PDFGamma()");
  return pow(beta * x, alpha) / x * exp(-beta * x - LnGamma(alpha));
}


x86 assembly (clang, -O0):
<PDFGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jae    1191 <PDFGamma+0x41>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1191 <PDFGamma+0x41>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11b8 <PDFGamma+0x68>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1040 <error2@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11db <PDFGamma+0x8b>
lea    0xe69(%rip),%rdi
call   1040 <error2@plt>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1060 <pow@plt>
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <LnGamma@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
cvtsi2sd %rax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PDFGamma>:
sub    $0x28,%rsp
xorpd  %xmm3,%xmm3
movsd  %xmm0,(%rsp)
ucomisd %xmm0,%xmm3
movapd %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
jae    117f <PDFGamma+0x2f>
ucomisd %xmm1,%xmm3
jae    117f <PDFGamma+0x2f>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jb     11ad <PDFGamma+0x5d>
lea    0xe9a(%rip),%rdi
movsd  (%rsp),%xmm0
movaps 0x10(%rsp),%xmm2
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
call   1040 <error2@plt>
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
ucomisd 0xe4b(%rip),%xmm1
jbe    11cf <PDFGamma+0x7f>
lea    0xe99(%rip),%rdi
call   1040 <error2@plt>
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
movsd  (%rsp),%xmm0
mulsd  %xmm2,%xmm0
call   1060 <pow@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movaps 0x10(%rsp),%xmm0
xorps  0xe1c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <LnGamma@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd 0x10(%rsp),%xmm1
mulsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1050 <exp@plt>
mulsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"x=%.6f a=%.6f b=%.6f\00"
@.str.1 = [34 x i8] c"x a b outside range in PDFGamma()\00"
@.str.2 = [26 x i8] c"large alpha in PDFGamma()\00"
define double @PDFGamma(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%7 = load double, double* %4
%8 = fcmp ole double %7, 0.000000e+00
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = load double, double* %5
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load double, double* %6
%14 = fcmp ole double %13, 0.000000e+00
br i1 %14, label %15, label %21
15: ; preds = %12, %9, %3
%16 = load double, double* %4
%17 = load double, double* %5
%18 = load double, double* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %16, double %17, double %18)
%20 = call i32 @error2(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %15, %12
%22 = load double, double* %5
%23 = fcmp ogt double %22, 1.000000e+02
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @error2(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load double, double* %6
%28 = load double, double* %4
%29 = fmul double %27, %28
%30 = load double, double* %5
%31 = call double @pow(double %29, double %30)
%32 = load double, double* %4
%33 = fdiv double %31, %32
%34 = load double, double* %6
%35 = fneg double %34
%36 = load double, double* %4
%37 = load double, double* %5
%38 = call i64 @LnGamma(double %37)
%39 = sitofp i64 %38 to double
%40 = fneg double %39
%41 = call double @llvm.fmuladd.f64(double %35, double %36, double %40)
%42 = fptosi double %41 to i64
%43 = call double @exp(i64 %42)
%44 = fmul double %33, %43
ret double %44
}

LLVM IR (-O2):
@.str = [21 x i8] c"x=%.6f a=%.6f b=%.6f\00"
@.str.1 = [34 x i8] c"x a b outside range in PDFGamma()\00"
@.str.2 = [26 x i8] c"large alpha in PDFGamma()\00"
define double @PDFGamma(double %0, double %1, double %2) {
%4 = fcmp ole double %0, 0.000000e+00
%5 = fcmp ole double %1, 0.000000e+00
%6 = or i1 %4, %5
%7 = fcmp ole double %2, 0.000000e+00
%8 = or i1 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %2)
%11 = tail call i32 @error2(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %3, %9
%13 = fcmp ogt double %1, 1.000000e+02
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @error2(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = fmul double %0, %2
%18 = tail call double @pow(double %17, double %1)
%19 = fdiv double %18, %0
%20 = fneg double %2
%21 = tail call i64 @LnGamma(double %1)
%22 = sitofp i64 %21 to double
%23 = fneg double %22
%24 = tail call double @llvm.fmuladd.f64(double %20, double %0, double %23)
%25 = fptosi double %24 to i64
%26 = tail call double @exp(i64 %25)
%27 = fmul double %19, %26
ret double %27
}