#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_copy(struct cl_rhash_table *, void **,
                                             void **);
int /*<<< orphan*/ cl_rhash_table_entry_update(struct cl_rhash_table *,
                                               scalar_t__);
scalar_t__ cl_rhash_table_find_empty(struct cl_rhash_table *, scalar_t__,
                                     scalar_t__);
void **cl_rhash_table_ptr(struct cl_rhash_table *, scalar_t__);
scalar_t__ cl_rhash_table_slot(struct cl_rhash_table *, scalar_t__, scalar_t__);
void cl_rhash_table_shift_forward(struct cl_rhash_table *tbl, uint32_t hcode,
                                  uint32_t ipr) {
  void **p_ent = NULL;
  uint32_t shift = cl_rhash_table_find_empty(tbl, hcode, ipr);
  for (uint32_t pr = shift; pr >= ipr; pr--) {
    uint32_t slot = cl_rhash_table_slot(tbl, hcode, pr);
    void **ent = cl_rhash_table_ptr(tbl, slot);
    if (p_ent)
      cl_rhash_table_entry_copy(tbl, p_ent, ent);
    cl_rhash_table_entry_update(tbl, slot);
    p_ent = ent;
  }
}


x86 assembly (clang, -O0):
<cl_rhash_table_shift_forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <cl_rhash_table_find_empty@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     11ff <cl_rhash_table_shift_forward+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <cl_rhash_table_slot@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <cl_rhash_table_ptr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d9 <cl_rhash_table_shift_forward+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1030 <cl_rhash_table_entry_copy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <cl_rhash_table_entry_update@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1189 <cl_rhash_table_shift_forward+0x39>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_rhash_table_shift_forward>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r12
mov    %rsi,(%rsp)
call   1040 <cl_rhash_table_find_empty@plt>
cmp    %r15,%rax
jge    117e <cl_rhash_table_shift_forward+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r13
xor    %ebx,%ebx
jmp    11aa <cl_rhash_table_shift_forward+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <cl_rhash_table_entry_update@plt>
lea    -0x1(%r13),%rax
mov    %r14,%rbx
cmp    %r15,%r13
mov    %rax,%r13
jle    116f <cl_rhash_table_shift_forward+0x1f>
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %r13,%rdx
call   1070 <cl_rhash_table_slot@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <cl_rhash_table_ptr@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1190 <cl_rhash_table_shift_forward+0x40>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <cl_rhash_table_entry_copy@plt>
jmp    1190 <cl_rhash_table_shift_forward+0x40>

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

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