#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 cdfPascal(long, double, long);
long idfPascal(long n, double p, double u) {
  long x = (long)(n * p / (1.0 - p));
  if (cdfPascal(n, p, x) <= u)
    while (cdfPascal(n, p, x) <= u)
      x++;
  else if (cdfPascal(n, p, 0) <= u)
    while (cdfPascal(n, p, x - 1) > u)
      x--;
  else
    x = 0;
  return (x);
}


x86 assembly (clang, -O0):
<idfPascal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xec7(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
call   1030 <cdfPascal@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11ae <idfPascal+0x9e>
jmp    1174 <idfPascal+0x64>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
call   1030 <cdfPascal@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11a9 <idfPascal+0x99>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1174 <idfPascal+0x64>
jmp    121b <idfPascal+0x10b>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
xor    %eax,%eax
mov    %eax,%esi
call   1030 <cdfPascal@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     120e <idfPascal+0xfe>
jmp    11d7 <idfPascal+0xc7>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
sub    $0x1,%rsi
call   1030 <cdfPascal@plt>
ucomisd -0x18(%rbp),%xmm0
jbe    1209 <idfPascal+0xf9>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11d7 <idfPascal+0xc7>
jmp    1216 <idfPascal+0x106>
movq   $0x0,-0x20(%rbp)
jmp    121b <idfPascal+0x10b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idfPascal>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,(%rsp)
mov    %rdi,%r14
cvtsi2sd %rdi,%xmm2
mulsd  %xmm0,%xmm2
movsd  0xece(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rbx
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rsi
call   1030 <cdfPascal@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    11a0 <idfPascal+0x90>
xor    %r15d,%r15d
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
xor    %esi,%esi
call   1030 <cdfPascal@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     11c7 <idfPascal+0xb7>
add    $0x1,%rbx
mov    %rbx,%r15
nopl   (%rax)
lea    -0x2(%r15),%rsi
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <cdfPascal@plt>
add    $0xffffffffffffffff,%r15
ucomisd (%rsp),%xmm0
ja     1180 <idfPascal+0x70>
jmp    11c7 <idfPascal+0xb7>
nop
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rsi
call   1030 <cdfPascal@plt>
add    $0x1,%rbx
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    11a0 <idfPascal+0x90>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%r15
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @idfPascal(i64 %0, double %1, double %2) {
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca i64
store i64 %0, i64* %4
store double %1, double* %5
store double %2, double* %6
%8 = load i64, i64* %4
%9 = sitofp i64 %8 to double
%10 = load double, double* %5
%11 = fmul double %9, %10
%12 = load double, double* %5
%13 = fsub double 1.000000e+00, %12
%14 = fdiv double %11, %13
%15 = fptosi double %14 to i64
store i64 %15, i64* %7
%16 = load i64, i64* %4
%17 = load double, double* %5
%18 = load i64, i64* %7
%19 = call double @cdfPascal(i64 %16, double %17, i64 %18)
%20 = load double, double* %6
%21 = fcmp ole double %19, %20
br i1 %21, label %22, label %34
22: ; preds = %3
br label %23
23: ; preds = %30, %22
%24 = load i64, i64* %4
%25 = load double, double* %5
%26 = load i64, i64* %7
%27 = call double @cdfPascal(i64 %24, double %25, i64 %26)
%28 = load double, double* %6
%29 = fcmp ole double %27, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i64, i64* %7
%32 = add nsw i64 %31, 1
store i64 %32, i64* %7
br label %23
33: ; preds = %23
br label %55
34: ; preds = %3
%35 = load i64, i64* %4
%36 = load double, double* %5
%37 = call double @cdfPascal(i64 %35, double %36, i64 0)
%38 = load double, double* %6
%39 = fcmp ole double %37, %38
br i1 %39, label %40, label %53
40: ; preds = %34
br label %41
41: ; preds = %49, %40
%42 = load i64, i64* %4
%43 = load double, double* %5
%44 = load i64, i64* %7
%45 = sub nsw i64 %44, 1
%46 = call double @cdfPascal(i64 %42, double %43, i64 %45)
%47 = load double, double* %6
%48 = fcmp ogt double %46, %47
br i1 %48, label %49, label %52
49: ; preds = %41
%50 = load i64, i64* %7
%51 = add nsw i64 %50, -1
store i64 %51, i64* %7
br label %41
52: ; preds = %41
br label %54
53: ; preds = %34
store i64 0, i64* %7
br label %54
54: ; preds = %53, %52
br label %55
55: ; preds = %54, %33
%56 = load i64, i64* %7
ret i64 %56
}

LLVM IR (-O2):
define i64 @idfPascal(i64 %0, double %1, double %2) {
%4 = sitofp i64 %0 to double
%5 = fmul double %4, %1
%6 = fsub double 1.000000e+00, %1
%7 = fdiv double %5, %6
%8 = fptosi double %7 to i64
%9 = tail call double @cdfPascal(i64 %0, double %1, i64 %8)
%10 = fcmp ugt double %9, %2
br i1 %10, label %16, label %11
11: ; preds = %3, %11
%12 = phi i64 [ %15, %11 ], [ %8, %3 ]
%13 = tail call double @cdfPascal(i64 %0, double %1, i64 %12)
%14 = fcmp ugt double %13, %2
%15 = add nsw i64 %12, 1
br i1 %14, label %24, label %11
16: ; preds = %3
%17 = tail call double @cdfPascal(i64 %0, double %1, i64 0)
%18 = fcmp ugt double %17, %2
br i1 %18, label %24, label %19
19: ; preds = %16, %19
%20 = phi i64 [ %21, %19 ], [ %8, %16 ]
%21 = add nsw i64 %20, -1
%22 = tail call double @cdfPascal(i64 %0, double %1, i64 %21)
%23 = fcmp ogt double %22, %2
br i1 %23, label %19, label %24
24: ; preds = %11, %19, %16
%25 = phi i64 [ 0, %16 ], [ %20, %19 ], [ %12, %11 ]
ret i64 %25
}