#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 gammainv(double, double, double);
int /*<<< orphan*/ printf(char *);
double chiinv(double p, int df) {
  double x, k;
  if (df <= 0) {
    printf("Degree of freedom is a real positive integer");
    exit(1);
  }
  if (p < 0. || p > 1.0) {
    printf("Probablity Values can only take values between 0.0 and 1.0");
    exit(1);
  }
  k = (double)df;
  x = gammainv(p, k / 2., 2.0);
  return x;
}


x86 assembly (clang, -O0):
<chiinv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1160 <chiinv+0x30>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1185 <chiinv+0x55>
movsd  -0x8(%rbp),%xmm0
movsd  0xe85(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <chiinv+0x6b>
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe51(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe45(%rip),%xmm2
call   1040 <gammainv@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chiinv>:
push   %rax
test   %edi,%edi
jle    1166 <chiinv+0x36>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     116f <chiinv+0x3f>
ucomisd 0xeb9(%rip),%xmm0
ja     116f <chiinv+0x3f>
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
mulsd  0xeb0(%rip),%xmm1
movsd  0xeb0(%rip),%xmm2
pop    %rax
jmp    1040 <gammainv@plt>
lea    0xeab(%rip),%rdi
jmp    1176 <chiinv+0x46>
lea    0xecf(%rip),%rdi
call   1030 <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 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @chiinv(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 %18, label %15
15: ; preds = %12
%16 = load double, double* %3
%17 = fcmp ogt double %16, 1.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %15, %12
%19 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to double
store double %23, double* %6
%24 = load double, double* %3
%25 = load double, double* %6
%26 = fdiv double %25, 2.000000e+00
%27 = call double @gammainv(double %24, double %26, double 2.000000e+00)
store double %27, double* %5
%28 = load double, double* %5
ret double %28
}

LLVM IR (-O2):
@.str = [45 x i8] c"Degree of freedom is a real positive integer\00"
@.str.1 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @chiinv(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
%9 = fcmp ogt double %0, 1.000000e+00
%10 = or i1 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = sitofp i32 %1 to double
%16 = fmul double %15, 5.000000e-01
%17 = tail call double @gammainv(double %0, double %16, double 2.000000e+00)
ret double %17
}