#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 cdfChisquare(long, double);
double fabs(double);
double pdfChisquare(long, double);
double idfChisquare(long n, double u) {
  double t, x = n;
  do {
    t = x;
    x = t + (u - cdfChisquare(n, t)) / pdfChisquare(n, t);
    if (x <= 0.0)
      x = 0.5 * t;
  } while (fabs(x - t) >= 1.0e-10);
  return (x);
}


x86 assembly (clang, -O0):
<idfChisquare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
call   1030 <cdfChisquare@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
call   1040 <pdfChisquare@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11c1 <idfChisquare+0xa1>
movsd  0xe49(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11c6 <idfChisquare+0xa6>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xe39(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe25(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    113c <idfChisquare+0x1c>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idfChisquare>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rdi,%xmm0
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <cdfChisquare@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
mov    %rbx,%rdi
movsd  (%rsp),%xmm0
call   1040 <pdfChisquare@plt>
movapd 0x10(%rsp),%xmm3
divsd  %xmm0,%xmm3
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm3
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  0xe73(%rip),%xmm1
movapd %xmm3,%xmm0
cmpnlesd 0xe76(%rip),%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm1,%xmm0
orpd   %xmm3,%xmm0
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
andpd  0xe6a(%rip),%xmm1
ucomisd 0xe4a(%rip),%xmm1
jae    1140 <idfChisquare+0x20>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @idfChisquare(i64 %0, double %1) {
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i64 %0, i64* %3
store double %1, double* %4
%7 = load i64, i64* %3
%8 = sitofp i64 %7 to double
store double %8, double* %6
br label %9
9: ; preds = %28, %2
%10 = load double, double* %6
store double %10, double* %5
%11 = load double, double* %5
%12 = load double, double* %4
%13 = load i64, i64* %3
%14 = load double, double* %5
%15 = call double @cdfChisquare(i64 %13, double %14)
%16 = fsub double %12, %15
%17 = load i64, i64* %3
%18 = load double, double* %5
%19 = call double @pdfChisquare(i64 %17, double %18)
%20 = fdiv double %16, %19
%21 = fadd double %11, %20
store double %21, double* %6
%22 = load double, double* %6
%23 = fcmp ole double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %9
%25 = load double, double* %5
%26 = fmul double 5.000000e-01, %25
store double %26, double* %6
br label %27
27: ; preds = %24, %9
br label %28
28: ; preds = %27
%29 = load double, double* %6
%30 = load double, double* %5
%31 = fsub double %29, %30
%32 = call double @llvm.fabs.f64(double %31)
%33 = fcmp oge double %32, 1.000000e-10
br i1 %33, label %9, label %34
34: ; preds = %28
%35 = load double, double* %6
ret double %35
}

LLVM IR (-O2):
define double @idfChisquare(i64 %0, double %1) {
%3 = sitofp i64 %0 to double
br label %4
4: ; preds = %4, %2
%5 = phi double [ %3, %2 ], [ %13, %4 ]
%6 = tail call double @cdfChisquare(i64 %0, double %5)
%7 = fsub double %1, %6
%8 = tail call double @pdfChisquare(i64 %0, double %5)
%9 = fdiv double %7, %8
%10 = fadd double %5, %9
%11 = fcmp ugt double %10, 0.000000e+00
%12 = fmul double %5, 5.000000e-01
%13 = select i1 %11, double %10, double %12
%14 = fsub double %13, %5
%15 = tail call double @llvm.fabs.f64(double %14)
%16 = fcmp ult double %15, 1.000000e-10
br i1 %16, label %17, label %4
17: ; preds = %4
ret double %13
}