#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 Gamma_Distribution(double, double);
int fabs(double);
double quantile_Gamma_Distribution(double p, double nu) {
  double x, size, res;
  x = 10;
  size = 10;
  res = Gamma_Distribution(x, nu);
  while (fabs(res - p) / fabs(p) > 1e-10) {
    size /= 2;
    if (res < p) {
      x += size;
      res = Gamma_Distribution(x, nu);
    } else {
      x -= size;
      res = Gamma_Distribution(x, nu);
    }
  }
  return x * 2.0;
}


x86 assembly (clang, -O0):
<quantile_Gamma_Distribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xec6(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <Gamma_Distribution@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xe78(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1218 <quantile_Gamma_Distribution+0xf8>
movsd  -0x20(%rbp),%xmm0
movsd  0xe69(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ec <quantile_Gamma_Distribution+0xcc>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <Gamma_Distribution@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1213 <quantile_Gamma_Distribution+0xf3>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <Gamma_Distribution@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1160 <quantile_Gamma_Distribution+0x40>
movsd  0xdf0(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quantile_Gamma_Distribution>:
push   %rbx
sub    $0x40,%rsp
movsd  %xmm0,(%rsp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x28(%rsp)
call   1030 <Gamma_Distribution@plt>
movapd %xmm0,0x10(%rsp)
subsd  (%rsp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
test   %eax,%eax
jle    11fc <quantile_Gamma_Distribution+0xdc>
movsd  0xe8a(%rip),%xmm0
movapd 0x10(%rsp),%xmm3
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm1
mulsd  0xe82(%rip),%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm0
cmpltsd (%rsp),%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm2,%xmm3
orpd   %xmm3,%xmm0
movapd %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm1
call   1030 <Gamma_Distribution@plt>
movapd %xmm0,0x10(%rsp)
subsd  (%rsp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
movapd 0x10(%rsp),%xmm3
movapd 0x30(%rsp),%xmm0
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
test   %eax,%eax
jg     1180 <quantile_Gamma_Distribution+0x60>
addsd  %xmm0,%xmm0
jmp    1204 <quantile_Gamma_Distribution+0xe4>
movsd  0xe04(%rip),%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @quantile_Gamma_Distribution(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store double %1, double* %4
store double 1.000000e+01, double* %5
store double 1.000000e+01, double* %6
%8 = load double, double* %5
%9 = load double, double* %4
%10 = call double @Gamma_Distribution(double %8, double %9)
store double %10, double* %7
br label %11
11: ; preds = %41, %2
%12 = load double, double* %7
%13 = load double, double* %3
%14 = fsub double %12, %13
%15 = call i32 @fabs(double %14)
%16 = load double, double* %3
%17 = call i32 @fabs(double %16)
%18 = sdiv i32 %15, %17
%19 = sitofp i32 %18 to double
%20 = fcmp ogt double %19, 1.000000e-10
br i1 %20, label %21, label %42
21: ; preds = %11
%22 = load double, double* %6
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %6
%24 = load double, double* %7
%25 = load double, double* %3
%26 = fcmp olt double %24, %25
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = load double, double* %6
%29 = load double, double* %5
%30 = fadd double %29, %28
store double %30, double* %5
%31 = load double, double* %5
%32 = load double, double* %4
%33 = call double @Gamma_Distribution(double %31, double %32)
store double %33, double* %7
br label %41
34: ; preds = %21
%35 = load double, double* %6
%36 = load double, double* %5
%37 = fsub double %36, %35
store double %37, double* %5
%38 = load double, double* %5
%39 = load double, double* %4
%40 = call double @Gamma_Distribution(double %38, double %39)
store double %40, double* %7
br label %41
41: ; preds = %34, %27
br label %11
42: ; preds = %11
%43 = load double, double* %5
%44 = fmul double %43, 2.000000e+00
ret double %44
}

LLVM IR (-O2):
define double @quantile_Gamma_Distribution(double %0, double %1) {
%3 = tail call double @Gamma_Distribution(double 1.000000e+01, double %1)
%4 = fsub double %3, %0
%5 = tail call i32 @fabs(double %4)
%6 = tail call i32 @fabs(double %0)
%7 = sdiv i32 %5, %6
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %2, %9
%10 = phi double [ %19, %9 ], [ %3, %2 ]
%11 = phi double [ %13, %9 ], [ 1.000000e+01, %2 ]
%12 = phi double [ %18, %9 ], [ 1.000000e+01, %2 ]
%13 = fmul double %11, 5.000000e-01
%14 = fcmp olt double %10, %0
%15 = fsub double %12, %13
%16 = fadd double %12, %13
%17 = select i1 %14, double %16, double %15
%18 = select i1 %14, double %16, double %15
%19 = tail call double @Gamma_Distribution(double %17, double %1)
%20 = fsub double %19, %0
%21 = tail call i32 @fabs(double %20)
%22 = tail call i32 @fabs(double %0)
%23 = sdiv i32 %21, %22
%24 = icmp sgt i32 %23, 0
br i1 %24, label %9, label %25
25: ; preds = %9
%26 = fmul double %18, 2.000000e+00
br label %27
27: ; preds = %25, %2
%28 = phi double [ 2.000000e+01, %2 ], [ %26, %25 ]
ret double %28
}