#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 binocdf_mat(int, int, double);
double invbinocdf2(double y, int n, int x, double r) {
  double p = 1.0;
  double cumdist = 0;
  double currpdf;
  int count;
  if ((y == 1) & (x < n))
    p = 1.0;
  if ((n < 0) | (p < 0) | (p > 1) | (y < 0.0) | (y > 1.0))
    p = -1.0;
  if (p == 1.0) {
    p = 1.0 + r;
    while ((cumdist < y) & (p >= r)) {
      p -= r;
      cumdist = binocdf_mat(n, x, p);
    }
  }
  if (p < 0)
    p = 0;
  return p;
}


x86 assembly (clang, -O0):
<invbinocdf2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%eax
mov    -0x10(%rbp),%ecx
cmp    -0xc(%rbp),%ecx
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1182 <invbinocdf2+0x72>
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
movsd  -0x20(%rbp),%xmm0
movsd  0xe52(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
movsd  -0x8(%rbp),%xmm0
movsd  0xe23(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     1202 <invbinocdf2+0xf2>
movsd  0xe0b(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdf1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1297 <invbinocdf2+0x187>
jp     1297 <invbinocdf2+0x187>
movsd  0xdd9(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
setae  %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1292 <invbinocdf2+0x182>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1030 <binocdf_mat@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1231 <invbinocdf2+0x121>
jmp    1297 <invbinocdf2+0x187>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12ad <invbinocdf2+0x19d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invbinocdf2>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm2
mov    %edi,%eax
shr    $0x1f,%eax
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
ucomisd %xmm2,%xmm0
seta   %cl
or     %eax,%ecx
xor    %eax,%eax
ucomisd 0xec8(%rip),%xmm2
seta   %al
or     %ecx,%eax
je     1156 <invbinocdf2+0x46>
movsd  0xec1(%rip),%xmm3
xorpd  %xmm0,%xmm0
maxsd  %xmm3,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
movsd  0xea2(%rip),%xmm3
addsd  %xmm1,%xmm3
ucomisd %xmm0,%xmm2
jbe    1147 <invbinocdf2+0x37>
ucomisd %xmm1,%xmm3
jb     1147 <invbinocdf2+0x37>
mov    %edi,%ebx
mov    %esi,%ebp
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
xchg   %ax,%ax
subsd  %xmm1,%xmm3
movsd  %xmm3,(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
movapd %xmm3,%xmm0
call   1030 <binocdf_mat@plt>
movsd  0x10(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    11b5 <invbinocdf2+0xa5>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm3
jae    1180 <invbinocdf2+0x70>
jmp    1147 <invbinocdf2+0x37>
movsd  (%rsp),%xmm3
jmp    1147 <invbinocdf2+0x37>

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

LLVM IR (-O2):
define double @invbinocdf2(double %0, i32 %1, i32 %2, double %3) {
%5 = lshr i32 %1, 31
%6 = fcmp olt double %0, 0.000000e+00
%7 = zext i1 %6 to i32
%8 = or i32 %5, %7
%9 = fcmp ogt double %0, 1.000000e+00
%10 = zext i1 %9 to i32
%11 = or i32 %8, %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %4
%14 = fadd double %3, 1.000000e+00
%15 = fcmp ogt double %0, 0.000000e+00
%16 = fcmp oge double %14, %3
%17 = and i1 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %13, %18
%19 = phi double [ %20, %18 ], [ %14, %13 ]
%20 = fsub double %19, %3
%21 = tail call double @binocdf_mat(i32 %1, i32 %2, double %20)
%22 = fcmp olt double %21, %0
%23 = fcmp oge double %20, %3
%24 = and i1 %22, %23
br i1 %24, label %18, label %25
25: ; preds = %18, %13, %4
%26 = phi double [ -1.000000e+00, %4 ], [ %14, %13 ], [ %20, %18 ]
%27 = fcmp olt double %26, 0.000000e+00
%28 = select i1 %27, double 0.000000e+00, double %26
ret double %28
}