unsigned elf_get_nbucket(unsigned nsym) {
  static unsigned hash_buckets[] = {
      1,    3,    17,   37,   67,    97,    131,   197,    263,   521,
      1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147};
  unsigned i;
  for (i = 1; i < (sizeof(hash_buckets) / sizeof(hash_buckets[0])); i++)
    if (hash_buckets[i] > nsym)
      break;
  return hash_buckets[i - 1];
}


x86 assembly (clang, -O0):
<elf_get_nbucket>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x13,%rax
jae    114b <elf_get_nbucket+0x4b>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2f09(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
jbe    1138 <elf_get_nbucket+0x38>
jmp    114b <elf_get_nbucket+0x4b>
jmp    113d <elf_get_nbucket+0x3d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    110e <elf_get_nbucket+0xe>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2ed4(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<elf_get_nbucket>:
cmp    $0x3,%edi
jae    110c <elf_get_nbucket+0xc>
xor    %eax,%eax
jmp    11fb <elf_get_nbucket+0xfb>
mov    $0x1,%eax
cmp    $0x11,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x2,%eax
cmp    $0x25,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x3,%eax
cmp    $0x43,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x4,%eax
cmp    $0x61,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x5,%eax
cmp    $0x83,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x6,%eax
cmp    $0xc5,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x7,%eax
cmp    $0x107,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x8,%eax
cmp    $0x209,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x9,%eax
cmp    $0x407,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xa,%eax
cmp    $0x805,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xb,%eax
cmp    $0x1003,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xc,%eax
cmp    $0x2011,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xd,%eax
cmp    $0x401b,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xe,%eax
cmp    $0x8003,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0xf,%eax
cmp    $0x10001,%edi
jb     11fb <elf_get_nbucket+0xfb>
mov    $0x10,%eax
cmp    $0x2001d,%edi
jb     11fb <elf_get_nbucket+0xfb>
cmp    $0x40003,%edi
mov    $0x12,%eax
sbb    $0x0,%rax
lea    0xdfe(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@elf_get_nbucket.hash_buckets = internal global [19 x i32] [i32 1, i32 3, i32 17, i32 37, i32 67, i32 97, i32 131, i32 197, i32 263, i32 521, i32 1031, i32 2053, i32 4099, i32 8209, i32 16411, i32 32771, i32 65537, i32 131101, i32 262147]
define i32 @elf_get_nbucket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
br label %4
4: ; preds = %17, %1
%5 = load i32, i32* %3
%6 = zext i32 %5 to i64
%7 = icmp ult i64 %6, 19
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [19 x i32], [19 x i32]* @elf_get_nbucket.hash_buckets, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = load i32, i32* %2
%14 = icmp ugt i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %8
br label %20
16: ; preds = %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add i32 %18, 1
store i32 %19, i32* %3
br label %4
20: ; preds = %15, %4
%21 = load i32, i32* %3
%22 = sub i32 %21, 1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [19 x i32], [19 x i32]* @elf_get_nbucket.hash_buckets, i64 0, i64 %23
%25 = load i32, i32* %24
ret i32 %25
}

LLVM IR (-O2):
@elf_get_nbucket.hash_buckets = internal unnamed_addr constant [19 x i32] [i32 1, i32 3, i32 17, i32 37, i32 67, i32 97, i32 131, i32 197, i32 263, i32 521, i32 1031, i32 2053, i32 4099, i32 8209, i32 16411, i32 32771, i32 65537, i32 131101, i32 262147]
define i32 @elf_get_nbucket(i32 %0) {
%2 = icmp ult i32 %0, 3
br i1 %2, label %38, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 17
br i1 %4, label %38, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 37
br i1 %6, label %38, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 67
br i1 %8, label %38, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 97
br i1 %10, label %38, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 131
br i1 %12, label %38, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 197
br i1 %14, label %38, label %15
15: ; preds = %13
%16 = icmp ult i32 %0, 263
br i1 %16, label %38, label %17
17: ; preds = %15
%18 = icmp ult i32 %0, 521
br i1 %18, label %38, label %19
19: ; preds = %17
%20 = icmp ult i32 %0, 1031
br i1 %20, label %38, label %21
21: ; preds = %19
%22 = icmp ult i32 %0, 2053
br i1 %22, label %38, label %23
23: ; preds = %21
%24 = icmp ult i32 %0, 4099
br i1 %24, label %38, label %25
25: ; preds = %23
%26 = icmp ult i32 %0, 8209
br i1 %26, label %38, label %27
27: ; preds = %25
%28 = icmp ult i32 %0, 16411
br i1 %28, label %38, label %29
29: ; preds = %27
%30 = icmp ult i32 %0, 32771
br i1 %30, label %38, label %31
31: ; preds = %29
%32 = icmp ult i32 %0, 65537
br i1 %32, label %38, label %33
33: ; preds = %31
%34 = icmp ult i32 %0, 131101
br i1 %34, label %38, label %35
35: ; preds = %33
%36 = icmp ult i32 %0, 262147
%37 = select i1 %36, i64 17, i64 18
br label %38
38: ; preds = %35, %33, %31, %29, %27, %25, %23, %21, %19, %17, %15, %13, %11, %9, %7, %5, %3, %1
%39 = phi i64 [ 0, %1 ], [ 1, %3 ], [ 2, %5 ], [ 3, %7 ], [ 4, %9 ], [ 5, %11 ], [ 6, %13 ], [ 7, %15 ], [ 8, %17 ], [ 9, %19 ], [ 10, %21 ], [ 11, %23 ], [ 12, %25 ], [ 13, %27 ], [ 14, %29 ], [ 15, %31 ], [ 16, %33 ], [ %37, %35 ]
%40 = getelementptr inbounds [19 x i32], [19 x i32]* @elf_get_nbucket.hash_buckets, i64 0, i64 %39
%41 = load i32, i32* %40
ret i32 %41
}