#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 */
typedef scalar_t__ uint32_t;
struct cl_rhash_table {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cl_rhash_table_entry_exists(struct cl_rhash_table *,
                                               void **);
void **cl_rhash_table_ptr(struct cl_rhash_table *, scalar_t__);
scalar_t__ cl_rhash_table_size(struct cl_rhash_table *);
scalar_t__ cl_rhash_table_slot(struct cl_rhash_table *, scalar_t__, scalar_t__);
uint32_t cl_rhash_table_find_empty(struct cl_rhash_table *tbl, uint32_t hcode,
                                   uint32_t ipr) {
  uint32_t n_size = cl_rhash_table_size(tbl);
  for (uint32_t pr = ipr; pr < n_size; pr++) {
    uint32_t slot = cl_rhash_table_slot(tbl, hcode, pr);
    void **ent = cl_rhash_table_ptr(tbl, slot);
    if (!cl_rhash_table_entry_exists(tbl, ent))
      return pr;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cl_rhash_table_find_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cl_rhash_table_size@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    11d6 <cl_rhash_table_find_empty+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <cl_rhash_table_slot@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <cl_rhash_table_ptr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <cl_rhash_table_entry_exists@plt>
cmp    $0x0,%eax
jne    11c0 <cl_rhash_table_find_empty+0x80>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11de <cl_rhash_table_find_empty+0x9e>
jmp    11c5 <cl_rhash_table_find_empty+0x85>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1169 <cl_rhash_table_find_empty+0x29>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_rhash_table_find_empty>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <cl_rhash_table_size@plt>
cmp    %rbx,%rax
jle    1191 <cl_rhash_table_find_empty+0x51>
mov    %rax,%r12
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <cl_rhash_table_slot@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <cl_rhash_table_ptr@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <cl_rhash_table_entry_exists@plt>
test   %eax,%eax
je     1193 <cl_rhash_table_find_empty+0x53>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <cl_rhash_table_find_empty+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cl_rhash_table = type { i32 }
define i64 @cl_rhash_table_find_empty(%struct.cl_rhash_table* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca %struct.cl_rhash_table*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8**
store %struct.cl_rhash_table* %0, %struct.cl_rhash_table** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%12 = load %struct.cl_rhash_table*, %struct.cl_rhash_table** %5
%13 = call i64 @cl_rhash_table_size(%struct.cl_rhash_table* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %7
store i64 %14, i64* %9
br label %15
15: ; preds = %34, %3
%16 = load i64, i64* %9
%17 = load i64, i64* %8
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = load %struct.cl_rhash_table*, %struct.cl_rhash_table** %5
%21 = load i64, i64* %6
%22 = load i64, i64* %9
%23 = call i64 @cl_rhash_table_slot(%struct.cl_rhash_table* %20, i64 %21, i64 %22)
store i64 %23, i64* %10
%24 = load %struct.cl_rhash_table*, %struct.cl_rhash_table** %5
%25 = load i64, i64* %10
%26 = call i8** @cl_rhash_table_ptr(%struct.cl_rhash_table* %24, i64 %25)
store i8** %26, i8*** %11
%27 = load %struct.cl_rhash_table*, %struct.cl_rhash_table** %5
%28 = load i8**, i8*** %11
%29 = call i32 @cl_rhash_table_entry_exists(%struct.cl_rhash_table* %27, i8** %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %19
%32 = load i64, i64* %9
store i64 %32, i64* %4
br label %38
33: ; preds = %19
br label %34
34: ; preds = %33
%35 = load i64, i64* %9
%36 = add nsw i64 %35, 1
store i64 %36, i64* %9
br label %15
37: ; preds = %15
store i64 0, i64* %4
br label %38
38: ; preds = %37, %31
%39 = load i64, i64* %4
ret i64 %39
}

LLVM IR (-O2):
%struct.cl_rhash_table = type { i32 }
define i64 @cl_rhash_table_find_empty(%struct.cl_rhash_table* %0, i64 %1, i64 %2) {
%4 = tail call i64 @cl_rhash_table_size(%struct.cl_rhash_table* %0)
%5 = icmp sgt i64 %4, %2
br i1 %5, label %6, label %15
6: ; preds = %3, %12
%7 = phi i64 [ %13, %12 ], [ %2, %3 ]
%8 = tail call i64 @cl_rhash_table_slot(%struct.cl_rhash_table* %0, i64 %1, i64 %7)
%9 = tail call i8** @cl_rhash_table_ptr(%struct.cl_rhash_table* %0, i64 %8)
%10 = tail call i32 @cl_rhash_table_entry_exists(%struct.cl_rhash_table* %0, i8** %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = add i64 %7, 1
%14 = icmp eq i64 %13, %4
br i1 %14, label %15, label %6
15: ; preds = %6, %12, %3
%16 = phi i64 [ 0, %3 ], [ 0, %12 ], [ %7, %6 ]
ret i64 %16
}