#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*/ assert(int);
double exp(double);
double log(double);
double logGamma(double);
double Gammapdf(double x, double k, double theta) {
  assert((k > 0) && (theta > 0));
  if (x < 0)
    return 0;
  if (x <= 0)
    return (k == 1) ? 1 / theta : 0;
  if (k == 1)
    return exp(-x / theta) / theta;
  return exp((k - 1) * log(x / theta) - x / theta - logGamma(k)) / theta;
}


x86 assembly (clang, -O0):
<Gammapdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jbe    1180 <Gammapdf+0x40>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11a8 <Gammapdf+0x68>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d8 <Gammapdf+0x198>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1206 <Gammapdf+0xc6>
movsd  -0x18(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11ea <Gammapdf+0xaa>
jp     11ea <Gammapdf+0xaa>
movsd  0xe25(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11f7 <Gammapdf+0xb7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11f7 <Gammapdf+0xb7>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d8 <Gammapdf+0x198>
movsd  -0x18(%rbp),%xmm0
movsd  0xded(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1258 <Gammapdf+0x118>
jp     1258 <Gammapdf+0x118>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <exp@plt>
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d8 <Gammapdf+0x198>
movsd  -0x18(%rbp),%xmm0
movsd  0xd9b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <logGamma@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1040 <exp@plt>
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Gammapdf>:
sub    $0x38,%rsp
movapd %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x28(%rsp)
ucomisd %xmm0,%xmm1
seta   %al
movsd  %xmm2,0x8(%rsp)
ucomisd %xmm0,%xmm2
seta   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
xorpd  %xmm3,%xmm3
movapd 0x10(%rsp),%xmm0
ucomisd %xmm0,%xmm3
ja     122b <Gammapdf+0xeb>
movsd  0x28(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
xorpd  %xmm3,%xmm3
ucomisd %xmm0,%xmm3
jae    11b6 <Gammapdf+0x76>
ucomisd 0xe5c(%rip),%xmm2
jne    11d0 <Gammapdf+0x90>
jp     11d0 <Gammapdf+0x90>
xorpd  0xe60(%rip),%xmm0
divsd  %xmm1,%xmm0
jmp    121c <Gammapdf+0xdc>
ucomisd 0xe42(%rip),%xmm2
jne    122b <Gammapdf+0xeb>
jp     122b <Gammapdf+0xeb>
movsd  0xe36(%rip),%xmm3
divsd  %xmm1,%xmm3
jmp    122b <Gammapdf+0xeb>
movsd  0xe30(%rip),%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x30(%rsp)
divsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
call   1060 <log@plt>
mulsd  0x30(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x28(%rsp),%xmm0
call   1050 <logGamma@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <exp@plt>
movapd %xmm0,%xmm3
divsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @Gammapdf(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %6
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load double, double* %7
%12 = fcmp ogt double %11, 0.000000e+00
br label %13
13: ; preds = %10, %3
%14 = phi i1 [ false, %3 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load double, double* %5
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %13
store double 0.000000e+00, double* %4
br label %61
20: ; preds = %13
%21 = load double, double* %5
%22 = fcmp ole double %21, 0.000000e+00
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load double, double* %6
%25 = fcmp oeq double %24, 1.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load double, double* %7
%28 = fdiv double 1.000000e+00, %27
br label %30
29: ; preds = %23
br label %30
30: ; preds = %29, %26
%31 = phi double [ %28, %26 ], [ 0.000000e+00, %29 ]
store double %31, double* %4
br label %61
32: ; preds = %20
%33 = load double, double* %6
%34 = fcmp oeq double %33, 1.000000e+00
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load double, double* %5
%37 = fneg double %36
%38 = load double, double* %7
%39 = fdiv double %37, %38
%40 = call double @exp(double %39)
%41 = load double, double* %7
%42 = fdiv double %40, %41
store double %42, double* %4
br label %61
43: ; preds = %32
%44 = load double, double* %6
%45 = fsub double %44, 1.000000e+00
%46 = load double, double* %5
%47 = load double, double* %7
%48 = fdiv double %46, %47
%49 = call double @log(double %48)
%50 = load double, double* %5
%51 = load double, double* %7
%52 = fdiv double %50, %51
%53 = fneg double %52
%54 = call double @llvm.fmuladd.f64(double %45, double %49, double %53)
%55 = load double, double* %6
%56 = call double @logGamma(double %55)
%57 = fsub double %54, %56
%58 = call double @exp(double %57)
%59 = load double, double* %7
%60 = fdiv double %58, %59
store double %60, double* %4
br label %61
61: ; preds = %43, %35, %30, %19
%62 = load double, double* %4
ret double %62
}

LLVM IR (-O2):
define double @Gammapdf(double %0, double %1, double %2) {
%4 = fcmp ogt double %1, 0.000000e+00
%5 = fcmp ogt double %2, 0.000000e+00
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = fcmp olt double %0, 0.000000e+00
br i1 %9, label %32, label %10
10: ; preds = %3
%11 = fcmp ugt double %0, 0.000000e+00
%12 = fcmp oeq double %1, 1.000000e+00
br i1 %11, label %16, label %13
13: ; preds = %10
%14 = fdiv double 1.000000e+00, %2
%15 = select i1 %12, double %14, double 0.000000e+00
br label %32
16: ; preds = %10
br i1 %12, label %17, label %22
17: ; preds = %16
%18 = fneg double %0
%19 = fdiv double %18, %2
%20 = tail call double @exp(double %19)
%21 = fdiv double %20, %2
br label %32
22: ; preds = %16
%23 = fadd double %1, -1.000000e+00
%24 = fdiv double %0, %2
%25 = tail call double @log(double %24)
%26 = fneg double %24
%27 = tail call double @llvm.fmuladd.f64(double %23, double %25, double %26)
%28 = tail call double @logGamma(double %1)
%29 = fsub double %27, %28
%30 = tail call double @exp(double %29)
%31 = fdiv double %30, %2
br label %32
32: ; preds = %3, %22, %17, %13
%33 = phi double [ %15, %13 ], [ %21, %17 ], [ %31, %22 ], [ 0.000000e+00, %3 ]
ret double %33
}