#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 chi2pdf(double x, double df) {
  assert(df > 0);
  if (x <= 0)
    return 0;
  if (df == 2)
    return 0.5 * exp(-0.5 * x);
  df *= 0.5;
  return 0.5 * exp((df - 1) * log(0.5 * x) - 0.5 * x - logGamma(df));
}


x86 assembly (clang, -O0):
<chi2pdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1186 <chi2pdf+0x46>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1270 <chi2pdf+0x130>
movsd  -0x18(%rbp),%xmm0
movsd  0xe6d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11ce <chi2pdf+0x8e>
jp     11ce <chi2pdf+0x8e>
movsd  0xe6d(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe48(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1270 <chi2pdf+0x130>
movsd  0xe32(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe23(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe0a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  0xdf0(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <logGamma@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xda1(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chi2pdf>:
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
xor    %edi,%edi
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm0,%xmm1
seta   %dil
call   1030 <assert@plt>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm0
ucomisd %xmm0,%xmm1
jae    1202 <chi2pdf+0xc2>
movsd  0x8(%rsp),%xmm1
ucomisd 0xe7d(%rip),%xmm1
jne    1191 <chi2pdf+0x51>
jp     1191 <chi2pdf+0x51>
mulsd  0xe89(%rip),%xmm0
jmp    11f1 <chi2pdf+0xb1>
movsd  0xe6f(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xe5f(%rip),%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1060 <log@plt>
mulsd  0x10(%rsp),%xmm0
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <logGamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <exp@plt>
movapd %xmm0,%xmm1
mulsd  0xe06(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @chi2pdf(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %5
%7 = fcmp ogt double %6, 0.000000e+00
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load double, double* %4
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %2
store double 0.000000e+00, double* %3
br label %38
13: ; preds = %2
%14 = load double, double* %5
%15 = fcmp oeq double %14, 2.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load double, double* %4
%18 = fmul double -5.000000e-01, %17
%19 = call double @exp(double %18)
%20 = fmul double 5.000000e-01, %19
store double %20, double* %3
br label %38
21: ; preds = %13
%22 = load double, double* %5
%23 = fmul double %22, 5.000000e-01
store double %23, double* %5
%24 = load double, double* %5
%25 = fsub double %24, 1.000000e+00
%26 = load double, double* %4
%27 = fmul double 5.000000e-01, %26
%28 = call double @log(double %27)
%29 = load double, double* %4
%30 = fmul double 5.000000e-01, %29
%31 = fneg double %30
%32 = call double @llvm.fmuladd.f64(double %25, double %28, double %31)
%33 = load double, double* %5
%34 = call double @logGamma(double %33)
%35 = fsub double %32, %34
%36 = call double @exp(double %35)
%37 = fmul double 5.000000e-01, %36
store double %37, double* %3
br label %38
38: ; preds = %21, %16, %12
%39 = load double, double* %3
ret double %39
}

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