#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 */
double betainv(double, double, double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
double sqrt(double);
double tinv_appx(double, int);
double tinv(double p, int df) {
  double t, q, pmin, x, y, d2, sign;
  if (df <= 0) {
    printf("Degree Of Freedom should be a positive real integer");
    exit(1);
  }
  if (p < 0. || p > 1.0) {
    printf("Probablity Values can only take values between 0.0 and 1.0");
    exit(1);
  }
  q = 1. - p;
  if (p <= q) {
    pmin = 2.0 * p;
  } else {
    pmin = 2.0 * q;
  }
  if (p == 0.) {
    t = -1.79e+308;
  }
  if (p == 1.) {
    t = 1.79e+308;
  }
  if (p > 0. && p < 1. && df <= 1000) {
    if (p < 0.5) {
      sign = -1.0;
    } else {
      sign = 1.0;
    }
    d2 = ((double)df) / 2.0;
    x = betainv(pmin, d2, 0.5);
    y = 1. - x;
    t = sqrt((double)df * y / x);
  }
  if (p > 0. && p < 1. && df > 1000) {
    t = tinv_appx(p, df);
  }
  return t;
}


x86 assembly (clang, -O0):
<tinv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1180 <tinv+0x30>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     11a5 <tinv+0x55>
movsd  -0x8(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11bb <tinv+0x6b>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movsd  0xe3d(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11f8 <tinv+0xa8>
movsd  0xe1f(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    120a <tinv+0xba>
movsd  0xe08(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    122f <tinv+0xdf>
jp     122f <tinv+0xdf>
movsd  0xde6(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1259 <tinv+0x109>
jp     1259 <tinv+0x109>
movsd  0xdc4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    131a <tinv+0x1ca>
movsd  0xd8d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    131a <tinv+0x1ca>
cmpl   $0x3e8,-0xc(%rbp)
jg     131a <tinv+0x1ca>
movsd  0xd8d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    12b0 <tinv+0x160>
movsd  0xd82(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12bd <tinv+0x16d>
movsd  0xd48(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xd3e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  0xd3b(%rip),%xmm2
call   1060 <betainv@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xd09(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    135e <tinv+0x20e>
movsd  0xccc(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    135e <tinv+0x20e>
cmpl   $0x3e8,-0xc(%rbp)
jle    135e <tinv+0x20e>
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1040 <tinv_appx@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tinv>:
push   %rax
test   %edi,%edi
jle    1245 <tinv+0xf5>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     124e <tinv+0xfe>
ucomisd 0xe91(%rip),%xmm0
ja     124e <tinv+0xfe>
movsd  0xe83(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %cl
ucomisd %xmm0,%xmm2
seta   %al
and    %cl,%al
cmp    $0x1,%al
jne    1207 <tinv+0xb7>
cmp    $0x3e8,%edi
ja     1207 <tinv+0xb7>
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm0,%xmm3
cmplesd %xmm1,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm1,%xmm3
orpd   %xmm0,%xmm3
addsd  %xmm3,%xmm3
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe36(%rip),%xmm2
mulsd  %xmm2,%xmm1
movapd %xmm3,%xmm0
call   1060 <betainv@plt>
movsd  0xe19(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     121c <tinv+0xcc>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
pop    %rax
ret
cmp    $0x3e9,%edi
setb   %cl
xor    $0x1,%al
or     %cl,%al
jne    1226 <tinv+0xd6>
pop    %rax
jmp    1040 <tinv_appx@plt>
movapd %xmm1,%xmm0
pop    %rax
jmp    1050 <sqrt@plt>
cmpeqsd 0xdd1(%rip),%xmm0
movq   %xmm0,%rax
and    $0x1,%eax
lea    0xdd2(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
pop    %rax
ret
lea    0xdd4(%rip),%rdi
jmp    1255 <tinv+0x105>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Degree Of Freedom should be a positive real integer\00"
@.str.1 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @tinv(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load double, double* %3
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load double, double* %3
%22 = fcmp ogt double %21, 1.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %20, %17
%24 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load double, double* %3
%28 = fsub double 1.000000e+00, %27
store double %28, double* %6
%29 = load double, double* %3
%30 = load double, double* %6
%31 = fcmp ole double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load double, double* %3
%34 = fmul double 2.000000e+00, %33
store double %34, double* %7
br label %38
35: ; preds = %26
%36 = load double, double* %6
%37 = fmul double 2.000000e+00, %36
store double %37, double* %7
br label %38
38: ; preds = %35, %32
%39 = load double, double* %3
%40 = fcmp oeq double %39, 0.000000e+00
br i1 %40, label %41, label %42
41: ; preds = %38
store double -1.790000e+308, double* %5
br label %42
42: ; preds = %41, %38
%43 = load double, double* %3
%44 = fcmp oeq double %43, 1.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %42
store double 1.790000e+308, double* %5
br label %46
46: ; preds = %45, %42
%47 = load double, double* %3
%48 = fcmp ogt double %47, 0.000000e+00
br i1 %48, label %49, label %76
49: ; preds = %46
%50 = load double, double* %3
%51 = fcmp olt double %50, 1.000000e+00
br i1 %51, label %52, label %76
52: ; preds = %49
%53 = load i32, i32* %4
%54 = icmp sle i32 %53, 1000
br i1 %54, label %55, label %76
55: ; preds = %52
%56 = load double, double* %3
%57 = fcmp olt double %56, 5.000000e-01
br i1 %57, label %58, label %59
58: ; preds = %55
store double -1.000000e+00, double* %11
br label %60
59: ; preds = %55
store double 1.000000e+00, double* %11
br label %60
60: ; preds = %59, %58
%61 = load i32, i32* %4
%62 = sitofp i32 %61 to double
%63 = fdiv double %62, 2.000000e+00
store double %63, double* %10
%64 = load double, double* %7
%65 = load double, double* %10
%66 = call double @betainv(double %64, double %65, double 5.000000e-01)
store double %66, double* %8
%67 = load double, double* %8
%68 = fsub double 1.000000e+00, %67
store double %68, double* %9
%69 = load i32, i32* %4
%70 = sitofp i32 %69 to double
%71 = load double, double* %9
%72 = fmul double %70, %71
%73 = load double, double* %8
%74 = fdiv double %72, %73
%75 = call double @sqrt(double %74)
store double %75, double* %5
br label %76
76: ; preds = %60, %52, %49, %46
%77 = load double, double* %3
%78 = fcmp ogt double %77, 0.000000e+00
br i1 %78, label %79, label %89
79: ; preds = %76
%80 = load double, double* %3
%81 = fcmp olt double %80, 1.000000e+00
br i1 %81, label %82, label %89
82: ; preds = %79
%83 = load i32, i32* %4
%84 = icmp sgt i32 %83, 1000
br i1 %84, label %85, label %89
85: ; preds = %82
%86 = load double, double* %3
%87 = load i32, i32* %4
%88 = call double @tinv_appx(double %86, i32 %87)
store double %88, double* %5
br label %89
89: ; preds = %85, %82, %79, %76
%90 = load double, double* %5
ret double %90
}

LLVM IR (-O2):
@.str = [52 x i8] c"Degree Of Freedom should be a positive real integer\00"
@.str.1 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @tinv(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 ([52 x i8], [52 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 = fsub double 1.000000e+00, %0
%16 = fcmp ogt double %0, 0.000000e+00
%17 = fcmp olt double %0, 1.000000e+00
%18 = and i1 %16, %17
%19 = icmp ult i32 %1, 1001
%20 = and i1 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %14
%22 = fcmp oge double %15, %0
%23 = select i1 %22, double %0, double %15
%24 = fmul double %23, 2.000000e+00
%25 = sitofp i32 %1 to double
%26 = fmul double %25, 5.000000e-01
%27 = tail call double @betainv(double %24, double %26, double 5.000000e-01)
%28 = fsub double 1.000000e+00, %27
%29 = fmul double %28, %25
%30 = fdiv double %29, %27
%31 = tail call double @sqrt(double %30)
br label %39
32: ; preds = %14
%33 = fcmp oeq double %0, 1.000000e+00
%34 = select i1 %33, double 1.790000e+308, double -1.790000e+308
%35 = icmp ugt i32 %1, 1000
%36 = and i1 %18, %35
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = tail call double @tinv_appx(double %0, i32 %1)
br label %39
39: ; preds = %21, %37, %32
%40 = phi double [ %38, %37 ], [ %34, %32 ], [ %31, %21 ]
ret double %40
}