#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 pgamma(double, double);
int /*<<< orphan*/ printf(char *);
double chicdf(double x, int df) {
  double oup, a;
  if (df <= 0) {
    printf("Degree of freedom is a real positive integer");
    exit(1);
  }
  if (x < 0.) {
    printf("The range of distribution only takes non-negative and real values");
    exit(1);
  }
  a = (double)df;
  oup = pgamma(x / 2, a / 2);
  return oup;
}


x86 assembly (clang, -O0):
<chicdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1160 <chicdf+0x30>
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1184 <chicdf+0x54>
lea    0xec0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe54(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1030 <pgamma@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chicdf>:
push   %rax
test   %edi,%edi
jle    115c <chicdf+0x2c>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1165 <chicdf+0x35>
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  0xeb2(%rip),%xmm2
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm1
pop    %rax
jmp    1030 <pgamma@plt>
lea    0xea5(%rip),%rdi
jmp    116c <chicdf+0x3c>
lea    0xec9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Degree of freedom is a real positive integer\00"
@.str.1 = [66 x i8] c"The range of distribution only takes non-negative and real values\00"
define double @chicdf(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load double, double* %3
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to double
store double %20, double* %6
%21 = load double, double* %3
%22 = fdiv double %21, 2.000000e+00
%23 = load double, double* %6
%24 = fdiv double %23, 2.000000e+00
%25 = call double @pgamma(double %22, double %24)
store double %25, double* %5
%26 = load double, double* %5
ret double %26
}

LLVM IR (-O2):
@.str = [45 x i8] c"Degree of freedom is a real positive integer\00"
@.str.1 = [66 x i8] c"The range of distribution only takes non-negative and real values\00"
define double @chicdf(double %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = fcmp olt double %0, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = sitofp i32 %1 to double
%14 = fmul double %0, 5.000000e-01
%15 = fmul double %13, 5.000000e-01
%16 = tail call double @pgamma(double %14, double %15)
ret double %16
}