#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 */
int /*<<< orphan*/ error(char *);
double geomcdf(int /*<<< orphan*/, double);
double geominv(double q, double p) {
  if (p <= 0 || p > 1)
    error("Parameter lambda is smaller than 0.");
  if (q <= 0 || q > 1)
    error("Parameter q must be a probability.");
  unsigned k = 0;
  while (q > geomcdf(k++, p))
    continue;
  return k;
}


x86 assembly (clang, -O0):
<geominv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1157 <geominv+0x37>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1163 <geominv+0x43>
lea    0xeaa(%rip),%rdi
call   1040 <error@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jae    1188 <geominv+0x68>
movsd  -0x8(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1194 <geominv+0x74>
lea    0xe9d(%rip),%rdi
call   1040 <error@plt>
movl   $0x0,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <geomcdf@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d1 <geominv+0xb1>
jmp    119b <geominv+0x7b>
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geominv>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
jae    1144 <geominv+0x24>
ucomisd 0xebe(%rip),%xmm1
jbe    115b <geominv+0x3b>
lea    0xebd(%rip),%rdi
call   1040 <error@plt>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jae    116f <geominv+0x4f>
ucomisd 0xe93(%rip),%xmm0
jbe    1180 <geominv+0x60>
lea    0xeb6(%rip),%rdi
call   1040 <error@plt>
movsd  (%rsp),%xmm1
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
lea    0x1(%rdi),%ebx
movapd %xmm1,%xmm0
call   1030 <geomcdf@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
ucomisd %xmm0,%xmm2
ja     1190 <geominv+0x70>
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Parameter lambda is smaller than 0.\00"
@.str.1 = [35 x i8] c"Parameter q must be a probability.\00"
define double @geominv(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp ole double %6, 0.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load double, double* %4
%10 = fcmp ogt double %9, 1.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = load double, double* %3
%15 = fcmp ole double %14, 0.000000e+00
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load double, double* %3
%18 = fcmp ogt double %17, 1.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %16, %13
%20 = call i32 @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
store i32 0, i32* %5
br label %22
22: ; preds = %29, %21
%23 = load double, double* %3
%24 = load i32, i32* %5
%25 = add i32 %24, 1
store i32 %25, i32* %5
%26 = load double, double* %4
%27 = call double @geomcdf(i32 %24, double %26)
%28 = fcmp ogt double %23, %27
br i1 %28, label %29, label %30
29: ; preds = %22
br label %22
30: ; preds = %22
%31 = load i32, i32* %5
%32 = uitofp i32 %31 to double
ret double %32
}

LLVM IR (-O2):
@.str = [36 x i8] c"Parameter lambda is smaller than 0.\00"
@.str.1 = [35 x i8] c"Parameter q must be a probability.\00"
define double @geominv(double %0, double %1) {
%3 = fcmp ole double %1, 0.000000e+00
%4 = fcmp ogt double %1, 1.000000e+00
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = fcmp ole double %0, 0.000000e+00
%10 = fcmp ogt double %0, 1.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %8, %12
br label %15
15: ; preds = %14, %15
%16 = phi i32 [ %17, %15 ], [ 0, %14 ]
%17 = add i32 %16, 1
%18 = tail call double @geomcdf(i32 %16, double %1)
%19 = fcmp olt double %18, %0
br i1 %19, label %15, label %20
20: ; preds = %15
%21 = uitofp i32 %17 to double
ret double %21
}