int hash_find_prime(int cap) {
  static const int table[] = {
      7, 23, 107, 317, 719, 1777, 5107, 7879, 10007,
  };
  int l = 0, m, r = (sizeof(table) / sizeof(table[0]));
  while (l < r) {
    m = (l + r) / 2;
    if (table[m] < cap)
      l = m + 1;
    else
      r = m;
  }
  return table[l];
}


x86 assembly (clang, -O0):
<hash_find_prime>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x9,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1162 <hash_find_prime+0x62>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xec3(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
jge    1157 <hash_find_prime+0x57>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115d <hash_find_prime+0x5d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1115 <hash_find_prime+0x15>
movslq -0x8(%rbp),%rcx
lea    0xe93(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_find_prime>:
xor    %ecx,%ecx
mov    $0x9,%edx
lea    0xef2(%rip),%r8
jmp    1116 <hash_find_prime+0x16>
mov    %esi,%edx
cmp    %edx,%ecx
jge    1134 <hash_find_prime+0x34>
lea    (%rdx,%rcx,1),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
movslq %esi,%rax
cmp    %edi,(%r8,%rax,4)
jge    1110 <hash_find_prime+0x10>
add    $0x1,%esi
mov    %esi,%ecx
cmp    %edx,%ecx
jl     1116 <hash_find_prime+0x16>
movslq %ecx,%rax
mov    (%r8,%rax,4),%eax
ret

LLVM IR (-O0):
@hash_find_prime.table = internal constant [9 x i32] [i32 7, i32 23, i32 107, i32 317, i32 719, i32 1777, i32 5107, i32 7879, i32 10007]
define i32 @hash_find_prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 9, i32* %5
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %5
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load i32, i32* %3
%12 = load i32, i32* %5
%13 = add nsw i32 %11, %12
%14 = sdiv i32 %13, 2
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i32], [9 x i32]* @hash_find_prime.table, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %26
24: ; preds = %10
%25 = load i32, i32* %4
store i32 %25, i32* %5
br label %26
26: ; preds = %24, %21
br label %6
27: ; preds = %6
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [9 x i32], [9 x i32]* @hash_find_prime.table, i64 0, i64 %29
%31 = load i32, i32* %30
ret i32 %31
}

LLVM IR (-O2):
@hash_find_prime.table = internal unnamed_addr constant [9 x i32] [i32 7, i32 23, i32 107, i32 317, i32 719, i32 1777, i32 5107, i32 7879, i32 10007]
define i32 @hash_find_prime(i32 %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 9, %1 ], [ %13, %2 ]
%4 = phi i32 [ 0, %1 ], [ %12, %2 ]
%5 = add nsw i32 %3, %4
%6 = sdiv i32 %5, 2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [9 x i32], [9 x i32]* @hash_find_prime.table, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, %0
%11 = add nsw i32 %6, 1
%12 = select i1 %10, i32 %11, i32 %4
%13 = select i1 %10, i32 %3, i32 %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %2, label %15
15: ; preds = %2
%16 = sext i32 %12 to i64
%17 = getelementptr inbounds [9 x i32], [9 x i32]* @hash_find_prime.table, i64 0, i64 %16
%18 = load i32, i32* %17
ret i32 %18
}