#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*/ THArgCheck(int, int, char *);
double __uniform__();
int log(double);
unsigned THRandom_geometric(double p) {
  THArgCheck(p > 0 && p < 1, 1, "must be > 0 and < 1");
  return ((unsigned)(log(1 - __uniform__()) / log(p)) + 1);
}


x86 assembly (clang, -O0):
<THRandom_geometric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x9(%rbp)
jbe    1167 <THRandom_geometric+0x37>
movsd  0xea4(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x1,%esi
lea    0xe8d(%rip),%rdx
call   1050 <THArgCheck@plt>
mov    $0x0,%al
call   1030 <__uniform__@plt>
movaps %xmm0,%xmm1
movsd  0xe6e(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1040 <log@plt>
mov    %eax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<THRandom_geometric>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movsd  0xeb2(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
and    %al,%cl
movzbl %cl,%edi
lea    0xea7(%rip),%rdx
mov    $0x1,%esi
call   1050 <THArgCheck@plt>
xor    %eax,%eax
call   1030 <__uniform__@plt>
movsd  0xe86(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <log@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"must be > 0 and < 1\00"
define i32 @THRandom_geometric(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp ogt double %3, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load double, double* %2
%7 = fcmp olt double %6, 1.000000e+00
br label %8
8: ; preds = %5, %1
%9 = phi i1 [ false, %1 ], [ %7, %5 ]
%10 = zext i1 %9 to i32
%11 = call i32 @THArgCheck(i32 %10, i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call double (...) @__uniform__()
%13 = fsub double 1.000000e+00, %12
%14 = call i32 @log(double %13)
%15 = load double, double* %2
%16 = call i32 @log(double %15)
%17 = sdiv i32 %14, %16
%18 = add i32 %17, 1
ret i32 %18
}

LLVM IR (-O2):
@.str = [20 x i8] c"must be > 0 and < 1\00"
define i32 @THRandom_geometric(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
%3 = fcmp olt double %0, 1.000000e+00
%4 = and i1 %2, %3
%5 = zext i1 %4 to i32
%6 = tail call i32 @THArgCheck(i32 %5, i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = tail call double (...) @__uniform__()
%8 = fsub double 1.000000e+00, %7
%9 = tail call i32 @log(double %8)
%10 = tail call i32 @log(double %0)
%11 = sdiv i32 %9, %10
%12 = add i32 %11, 1
ret i32 %12
}