#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__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ lngamma(double);
double pow(double, double);
int /*<<< orphan*/ stderr;
double chi_square_density(double n, double x, const char *prompt) {
  if (n <= 0) {
    fprintf(stderr,
            "%s: IMPLEMENTATION ERROR! (Invalid argument in function "
            "\"chi_square_density\")\n",
            prompt);
    exit(4);
  }
  return x <= 0 ? 0
                : pow(2, -n / 2) * pow(x, n / 2 - 1) *
                      exp(-x / 2 - lngamma(n / 2));
}


x86 assembly (clang, -O0):
<chi_square_density>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1197 <chi_square_density+0x47>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11b2 <chi_square_density+0x62>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1290 <chi_square_density+0x140>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe2a(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
call   1060 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xe02(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xdfe(%rip),%xmm2
subsd  %xmm2,%xmm1
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <lngamma@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chi_square_density>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    121b <chi_square_density+0xbb>
ucomisd %xmm1,%xmm0
jae    1216 <chi_square_density+0xb6>
movapd %xmm2,%xmm0
mulsd  0xe74(%rip),%xmm0
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1030 <exp2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe58(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xe52(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
call   1070 <pow@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  0xe1b(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <lngamma@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1050 <exp@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret
mov    %rdi,%rdx
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x4,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [79 x i8] c"%s: IMPLEMENTATION ERROR! (Invalid argument in function \22chi_square_density\22)\0A\00"
define double @chi_square_density(double %0, double %1, i8* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i8*
store double %0, double* %4
store double %1, double* %5
store i8* %2, i8** %6
%7 = load double, double* %4
%8 = fcmp ole double %7, 0.000000e+00
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %6
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 4)
unreachable
14: ; preds = %3
%15 = load double, double* %5
%16 = fcmp ole double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %14
br label %40
18: ; preds = %14
%19 = load double, double* %4
%20 = fneg double %19
%21 = fdiv double %20, 2.000000e+00
%22 = call double @pow(double 2.000000e+00, double %21)
%23 = load double, double* %5
%24 = load double, double* %4
%25 = fdiv double %24, 2.000000e+00
%26 = fsub double %25, 1.000000e+00
%27 = call double @pow(double %23, double %26)
%28 = fmul double %22, %27
%29 = load double, double* %5
%30 = fneg double %29
%31 = fdiv double %30, 2.000000e+00
%32 = load double, double* %4
%33 = fdiv double %32, 2.000000e+00
%34 = call i64 @lngamma(double %33)
%35 = sitofp i64 %34 to double
%36 = fsub double %31, %35
%37 = fptosi double %36 to i64
%38 = call double @exp(i64 %37)
%39 = fmul double %28, %38
br label %40
40: ; preds = %18, %17
%41 = phi double [ 0.000000e+00, %17 ], [ %39, %18 ]
ret double %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [79 x i8] c"%s: IMPLEMENTATION ERROR! (Invalid argument in function \22chi_square_density\22)\0A\00"
define double @chi_square_density(double %0, double %1, i8* %2) {
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = tail call i32 @exit(i32 4)
unreachable
9: ; preds = %3
%10 = fcmp ugt double %1, 0.000000e+00
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = fmul double %0, -5.000000e-01
%13 = tail call double @exp2(double %12)
%14 = fmul double %0, 5.000000e-01
%15 = fadd double %14, -1.000000e+00
%16 = tail call double @pow(double %1, double %15)
%17 = fmul double %13, %16
%18 = fmul double %1, -5.000000e-01
%19 = tail call i64 @lngamma(double %14)
%20 = sitofp i64 %19 to double
%21 = fsub double %18, %20
%22 = fptosi double %21 to i64
%23 = tail call double @exp(i64 %22)
%24 = fmul double %17, %23
br label %25
25: ; preds = %9, %11
%26 = phi double [ %24, %11 ], [ 0.000000e+00, %9 ]
ret double %26
}