#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 fabs(double);
double stub1(double, int, double *);
double stub2(double, int, double *);
double findQuantile(double q, double (*cdf)(double, int, double *), int npara,
                    double *para) {
  int cnt;
  double a, b, c;
  if (q >= 1.0 - 1.0e-15)
    return 0;
  a = 0.0;
  b = 1.0;
  cnt = 0;
  while ((*cdf)(b, npara, para) < q && cnt++ < 1024) {
    a = b;
    b *= 2.0;
  }
  cnt = 0;
  c = (a + b) / 2.0;
  while (fabs(a - b) / a > 1.0e-8 && cnt++ < 1024) {
    c = (a + b) / 2.0;
    if ((*cdf)(c, npara, para) > q) {
      b = c;
    } else {
      a = c;
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<findQuantile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xedb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     113c <findQuantile+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a1 <findQuantile+0x1a1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x49(%rbp)
jbe    1197 <findQuantile+0x97>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x400,%eax
setl   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11a7 <findQuantile+0xa7>
jmp    11c8 <findQuantile+0xc8>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe57(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1158 <findQuantile+0x58>
movl   $0x0,-0x2c(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xe2f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movaps 0xe25(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x38(%rbp),%xmm0
xor    %eax,%eax
movsd  0xe0a(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x4a(%rbp)
jbe    1231 <findQuantile+0x131>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x400,%eax
setl   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    1241 <findQuantile+0x141>
jmp    1297 <findQuantile+0x197>
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xdbd(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   *%rax
ucomisd -0x10(%rbp),%xmm0
jbe    1288 <findQuantile+0x188>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1292 <findQuantile+0x192>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11ea <findQuantile+0xea>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findQuantile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
xorpd  %xmm3,%xmm3
ucomisd 0xeea(%rip),%xmm0
jae    1278 <findQuantile+0x178>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
movapd %xmm0,%xmm1
movsd  0xed7(%rip),%xmm0
mov    %esi,%edi
mov    %rdx,%rsi
movsd  %xmm1,0x8(%rsp)
call   *%rbx
movsd  0xec2(%rip),%xmm1
xorps  %xmm2,%xmm2
movaps %xmm2,0x10(%rsp)
movsd  0x8(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    11b0 <findQuantile+0xb0>
xor    %ebp,%ebp
movsd  0xea4(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm1,0x10(%rsp)
addsd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
mov    %r15d,%edi
mov    %r14,%rsi
call   *%rbx
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    11ab <findQuantile+0xab>
lea    0x1(%rbp),%eax
cmp    $0x3ff,%ebp
mov    %eax,%ebp
movsd  (%rsp),%xmm1
jb     1170 <findQuantile+0x70>
jmp    11b0 <findQuantile+0xb0>
movsd  (%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
andpd  0xe5a(%rip),%xmm0
divsd  %xmm3,%xmm0
ucomisd 0xe46(%rip),%xmm0
jbe    126c <findQuantile+0x16c>
xor    %ebp,%ebp
movapd %xmm3,%xmm2
xchg   %ax,%ax
movsd  %xmm1,(%rsp)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe15(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
call   *%rbx
movapd 0x20(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm0
movapd %xmm3,%xmm1
ja     1224 <findQuantile+0x124>
movsd  (%rsp),%xmm1
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andnpd %xmm3,%xmm0
andpd  0x10(%rsp),%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
andpd  0xdd5(%rip),%xmm0
divsd  %xmm2,%xmm0
ucomisd 0xdc1(%rip),%xmm0
jbe    1278 <findQuantile+0x178>
lea    0x1(%rbp),%eax
cmp    $0x3ff,%ebp
mov    %eax,%ebp
jb     11e0 <findQuantile+0xe0>
jmp    1278 <findQuantile+0x178>
addsd  %xmm1,%xmm3
mulsd  0xd98(%rip),%xmm3
movapd %xmm3,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @findQuantile(double %0, double (double, i32, double*)* %1, i32 %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double (double, i32, double*)*
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double %0, double* %6
store double (double, i32, double*)* %1, double (double, i32, double*)** %7
store i32 %2, i32* %8
store double* %3, double** %9
%14 = load double, double* %6
%15 = fcmp oge double %14, 0x3FEFFFFFFFFFFFF7
br i1 %15, label %16, label %17
16: ; preds = %4
store double 0.000000e+00, double* %5
br label %74
17: ; preds = %4
store double 0.000000e+00, double* %11
store double 1.000000e+00, double* %12
store i32 0, i32* %10
br label %18
18: ; preds = %32, %17
%19 = load double (double, i32, double*)*, double (double, i32, double*)** %7
%20 = load double, double* %12
%21 = load i32, i32* %8
%22 = load double*, double** %9
%23 = call double %19(double %20, i32 %21, double* %22)
%24 = load double, double* %6
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
%29 = icmp slt i32 %27, 1024
br label %30
30: ; preds = %26, %18
%31 = phi i1 [ false, %18 ], [ %29, %26 ]
br i1 %31, label %32, label %36
32: ; preds = %30
%33 = load double, double* %12
store double %33, double* %11
%34 = load double, double* %12
%35 = fmul double %34, 2.000000e+00
store double %35, double* %12
br label %18
36: ; preds = %30
store i32 0, i32* %10
%37 = load double, double* %11
%38 = load double, double* %12
%39 = fadd double %37, %38
%40 = fdiv double %39, 2.000000e+00
store double %40, double* %13
br label %41
41: ; preds = %71, %36
%42 = load double, double* %11
%43 = load double, double* %12
%44 = fsub double %42, %43
%45 = call double @llvm.fabs.f64(double %44)
%46 = load double, double* %11
%47 = fdiv double %45, %46
%48 = fcmp ogt double %47, 1.000000e-08
br i1 %48, label %49, label %53
49: ; preds = %41
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
%52 = icmp slt i32 %50, 1024
br label %53
53: ; preds = %49, %41
%54 = phi i1 [ false, %41 ], [ %52, %49 ]
br i1 %54, label %55, label %72
55: ; preds = %53
%56 = load double, double* %11
%57 = load double, double* %12
%58 = fadd double %56, %57
%59 = fdiv double %58, 2.000000e+00
store double %59, double* %13
%60 = load double (double, i32, double*)*, double (double, i32, double*)** %7
%61 = load double, double* %13
%62 = load i32, i32* %8
%63 = load double*, double** %9
%64 = call double %60(double %61, i32 %62, double* %63)
%65 = load double, double* %6
%66 = fcmp ogt double %64, %65
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = load double, double* %13
store double %68, double* %12
br label %71
69: ; preds = %55
%70 = load double, double* %13
store double %70, double* %11
br label %71
71: ; preds = %69, %67
br label %41
72: ; preds = %53
%73 = load double, double* %13
store double %73, double* %5
br label %74
74: ; preds = %72, %16
%75 = load double, double* %5
ret double %75
}

LLVM IR (-O2):
define double @findQuantile(double %0, double (double, i32, double*)* nocapture %1, i32 %2, double* %3) {
%5 = fcmp ult double %0, 0x3FEFFFFFFFFFFFF7
br i1 %5, label %6, label %44
6: ; preds = %4
%7 = tail call double %1(double 1.000000e+00, i32 %2, double* %3)
%8 = fcmp olt double %7, %0
br i1 %8, label %9, label %18
9: ; preds = %6, %9
%10 = phi double [ %13, %9 ], [ 1.000000e+00, %6 ]
%11 = phi i32 [ %12, %9 ], [ 0, %6 ]
%12 = add nuw nsw i32 %11, 1
%13 = fmul double %10, 2.000000e+00
%14 = tail call double %1(double %13, i32 %2, double* %3)
%15 = fcmp olt double %14, %0
%16 = icmp ult i32 %11, 1023
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %9, label %18
18: ; preds = %9, %6
%19 = phi double [ 0.000000e+00, %6 ], [ %10, %9 ]
%20 = phi double [ 1.000000e+00, %6 ], [ %13, %9 ]
%21 = fadd double %19, %20
%22 = fmul double %21, 5.000000e-01
%23 = fsub double %19, %20
%24 = tail call double @llvm.fabs.f64(double %23)
%25 = fdiv double %24, %19
%26 = fcmp ogt double %25, 1.000000e-08
br i1 %26, label %27, label %44
27: ; preds = %18, %27
%28 = phi double [ %37, %27 ], [ %20, %18 ]
%29 = phi double [ %36, %27 ], [ %19, %18 ]
%30 = phi i32 [ %31, %27 ], [ 0, %18 ]
%31 = add nuw nsw i32 %30, 1
%32 = fadd double %29, %28
%33 = fmul double %32, 5.000000e-01
%34 = tail call double %1(double %33, i32 %2, double* %3)
%35 = fcmp ogt double %34, %0
%36 = select i1 %35, double %29, double %33
%37 = select i1 %35, double %33, double %28
%38 = fsub double %36, %37
%39 = tail call double @llvm.fabs.f64(double %38)
%40 = fdiv double %39, %36
%41 = fcmp ogt double %40, 1.000000e-08
%42 = icmp ult i32 %30, 1023
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %27, label %44
44: ; preds = %27, %18, %4
%45 = phi double [ 0.000000e+00, %4 ], [ %22, %18 ], [ %33, %27 ]
ret double %45
}