#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*/ exit(int);
double exp(scalar_t__);
scalar_t__ gamma_log(double);
double log(double);
int /*<<< orphan*/ printf(char *);
double gammapdf(double x, double k, double th) {
  double oup, t;
  if (k <= 0. || th <= 0.) {
    printf("Gamma Distribution parameters must be positive and real.");
    exit(1);
  }
  t = x / th;
  if (t > 0.) {
    oup = exp((k - 1) * log(t) - t - gamma_log(k)) / th;
  } else if (t < 0.) {
    oup = 0.0;
  } else if (t == 0.0 && k == 1) {
    oup = 1.0 / th;
  } else {
    printf("The Output is Complex and cannot be determined");
    exit(1);
  }
  return oup;
}


x86 assembly (clang, -O0):
<gammapdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1183 <gammapdf+0x33>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1199 <gammapdf+0x49>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movsd  -0x8(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    123c <gammapdf+0xec>
movsd  -0x10(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <gamma_log@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <exp@plt>
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12c3 <gammapdf+0x173>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1257 <gammapdf+0x107>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12be <gammapdf+0x16e>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a3 <gammapdf+0x153>
jp     12a3 <gammapdf+0x153>
movsd  -0x10(%rbp),%xmm0
movsd  0xd84(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    12a3 <gammapdf+0x153>
jp     12a3 <gammapdf+0x153>
movsd  0xd6c(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12b9 <gammapdf+0x169>
lea    0xd97(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    12be <gammapdf+0x16e>
jmp    12c3 <gammapdf+0x173>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammapdf>:
sub    $0x28,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    121e <gammapdf+0xce>
ucomisd %xmm2,%xmm0
jae    121e <gammapdf+0xce>
divsd  %xmm2,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jbe    11ef <gammapdf+0x9f>
movsd  0xe82(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
call   1060 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <gamma_log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1050 <exp@plt>
divsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
ret
ucomisd %xmm3,%xmm0
ja     1219 <gammapdf+0xc9>
ucomisd 0xe03(%rip),%xmm1
jne    1227 <gammapdf+0xd7>
jp     1227 <gammapdf+0xd7>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jne    1227 <gammapdf+0xd7>
jp     1227 <gammapdf+0xd7>
movsd  0xdeb(%rip),%xmm0
divsd  %xmm2,%xmm0
add    $0x28,%rsp
ret
lea    0xdeb(%rip),%rdi
jmp    122e <gammapdf+0xde>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"Gamma Distribution parameters must be positive and real.\00"
@.str.1 = [47 x i8] c"The Output is Complex and cannot be determined\00"
define double @gammapdf(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%9 = load double, double* %5
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load double, double* %6
%13 = fcmp ole double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %11, %3
%15 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = load double, double* %4
%19 = load double, double* %6
%20 = fdiv double %18, %19
store double %20, double* %8
%21 = load double, double* %8
%22 = fcmp ogt double %21, 0.000000e+00
br i1 %22, label %23, label %39
23: ; preds = %17
%24 = load double, double* %5
%25 = fsub double %24, 1.000000e+00
%26 = load double, double* %8
%27 = call double @log(double %26)
%28 = load double, double* %8
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %25, double %27, double %29)
%31 = load double, double* %5
%32 = call i64 @gamma_log(double %31)
%33 = sitofp i64 %32 to double
%34 = fsub double %30, %33
%35 = fptosi double %34 to i64
%36 = call double @exp(i64 %35)
%37 = load double, double* %6
%38 = fdiv double %36, %37
store double %38, double* %7
br label %57
39: ; preds = %17
%40 = load double, double* %8
%41 = fcmp olt double %40, 0.000000e+00
br i1 %41, label %42, label %43
42: ; preds = %39
store double 0.000000e+00, double* %7
br label %56
43: ; preds = %39
%44 = load double, double* %8
%45 = fcmp oeq double %44, 0.000000e+00
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = load double, double* %5
%48 = fcmp oeq double %47, 1.000000e+00
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load double, double* %6
%51 = fdiv double 1.000000e+00, %50
store double %51, double* %7
br label %55
52: ; preds = %46, %43
%53 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %49
br label %56
56: ; preds = %55, %42
br label %57
57: ; preds = %56, %23
%58 = load double, double* %7
ret double %58
}

LLVM IR (-O2):
@.str = [57 x i8] c"Gamma Distribution parameters must be positive and real.\00"
@.str.1 = [47 x i8] c"The Output is Complex and cannot be determined\00"
define double @gammapdf(double %0, double %1, double %2) {
%4 = fcmp ole double %1, 0.000000e+00
%5 = fcmp ole double %2, 0.000000e+00
%6 = or i1 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = fdiv double %0, %2
%12 = fcmp ogt double %11, 0.000000e+00
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = fadd double %1, -1.000000e+00
%15 = tail call double @log(double %11)
%16 = fneg double %11
%17 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %16)
%18 = tail call i64 @gamma_log(double %1)
%19 = sitofp i64 %18 to double
%20 = fsub double %17, %19
%21 = fptosi double %20 to i64
%22 = tail call double @exp(i64 %21)
%23 = fdiv double %22, %2
br label %35
24: ; preds = %10
%25 = fcmp olt double %11, 0.000000e+00
br i1 %25, label %35, label %26
26: ; preds = %24
%27 = fcmp oeq double %11, 0.000000e+00
%28 = fcmp oeq double %1, 1.000000e+00
%29 = and i1 %28, %27
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = fdiv double 1.000000e+00, %2
br label %35
32: ; preds = %26
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %24, %30, %13
%36 = phi double [ %23, %13 ], [ %31, %30 ], [ 0.000000e+00, %24 ]
ret double %36
}