#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 int /*<<< orphan*/ primes;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int rq_hashtable_calc_size(int size) {
  static long primes[] = {8 + 3,
                          16 + 3,
                          32 + 5,
                          64 + 3,
                          128 + 3,
                          256 + 27,
                          512 + 9,
                          1024 + 9,
                          2048 + 5,
                          4096 + 3,
                          8192 + 27,
                          16384 + 43,
                          32768 + 3,
                          65536 + 45,
                          131072 + 29,
                          262144 + 3,
                          524288 + 21,
                          1048576 + 7,
                          2097152 + 17,
                          4194304 + 15,
                          8388608 + 9,
                          16777216 + 43,
                          33554432 + 35,
                          67108864 + 15,
                          134217728 + 29,
                          268435456 + 3,
                          536870912 + 11,
                          1073741824 + 85,
                          0};
  int i;
  int newsize;
  for (i = 0, newsize = 8; i < sizeof(primes) / sizeof(primes[0]);
       i++, newsize <<= 1) {
    if (newsize > size)
      return primes[i];
  }
  assert(0);
  return 0;
}


x86 assembly (clang, -O0):
<rq_hashtable_calc_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x8,-0x10(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x1d,%rax
jae    1176 <rq_hashtable_calc_size+0x66>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    115a <rq_hashtable_calc_size+0x4a>
movslq -0xc(%rbp),%rcx
lea    0x2ee2(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %eax,-0x4(%rbp)
jmp    1184 <rq_hashtable_calc_size+0x74>
jmp    115f <rq_hashtable_calc_size+0x4f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1129 <rq_hashtable_calc_size+0x19>
xor    %edi,%edi
call   1030 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_hashtable_calc_size>:
push   %rbx
cmp    $0x7,%edi
jg     111d <rq_hashtable_calc_size+0xd>
xor    %eax,%eax
jmp    12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x1,%eax
cmp    $0x10,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x2,%eax
cmp    $0x20,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x3,%eax
cmp    $0x40,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x4,%eax
cmp    $0x80,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x5,%eax
cmp    $0x100,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x6,%eax
cmp    $0x200,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x7,%eax
cmp    $0x400,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x8,%eax
cmp    $0x800,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x9,%eax
cmp    $0x1000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xa,%eax
cmp    $0x2000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xb,%eax
cmp    $0x4000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xc,%eax
cmp    $0x8000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xd,%eax
cmp    $0x10000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xe,%eax
cmp    $0x20000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0xf,%eax
cmp    $0x40000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x10,%eax
cmp    $0x80000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x11,%eax
cmp    $0x100000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x12,%eax
cmp    $0x200000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x13,%eax
cmp    $0x400000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x14,%eax
cmp    $0x800000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x15,%eax
cmp    $0x1000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x16,%eax
cmp    $0x2000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x17,%eax
cmp    $0x4000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x18,%eax
cmp    $0x8000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x19,%eax
cmp    $0x10000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x1a,%eax
cmp    $0x20000000,%edi
jb     12b7 <rq_hashtable_calc_size+0x1a7>
mov    $0x1b,%eax
cmp    $0x40000000,%edi
jae    12c5 <rq_hashtable_calc_size+0x1b5>
lea    0xd42(%rip),%rcx
mov    (%rcx,%rax,8),%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <assert@plt>
jmp    12c1 <rq_hashtable_calc_size+0x1b1>

LLVM IR (-O0):
@rq_hashtable_calc_size.primes = internal global [29 x i64] [i64 11, i64 19, i64 37, i64 67, i64 131, i64 283, i64 521, i64 1033, i64 2053, i64 4099, i64 8219, i64 16427, i64 32771, i64 65581, i64 131101, i64 262147, i64 524309, i64 1048583, i64 2097169, i64 4194319, i64 8388617, i64 16777259, i64 33554467, i64 67108879, i64 134217757, i64 268435459, i64 536870923, i64 1073741909, i64 0]
define i32 @rq_hashtable_calc_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 8, i32* %5
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 29
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = load i32, i32* %5
%12 = load i32, i32* %3
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [29 x i64], [29 x i64]* @rq_hashtable_calc_size.primes, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %2
br label %28
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = shl i32 %24, 1
store i32 %25, i32* %5
br label %6
26: ; preds = %6
%27 = call i32 @assert(i32 0)
store i32 0, i32* %2
br label %28
28: ; preds = %26, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@rq_hashtable_calc_size.primes = internal unnamed_addr constant [29 x i64] [i64 11, i64 19, i64 37, i64 67, i64 131, i64 283, i64 521, i64 1033, i64 2053, i64 4099, i64 8219, i64 16427, i64 32771, i64 65581, i64 131101, i64 262147, i64 524309, i64 1048583, i64 2097169, i64 4194319, i64 8388617, i64 16777259, i64 33554467, i64 67108879, i64 134217757, i64 268435459, i64 536870923, i64 1073741909, i64 0]
define i32 @rq_hashtable_calc_size(i32 %0) {
%2 = icmp slt i32 %0, 8
br i1 %2, label %3, label %8
3: ; preds = %60, %58, %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %1
%4 = phi i64 [ 0, %1 ], [ 1, %8 ], [ 2, %10 ], [ 3, %12 ], [ 4, %14 ], [ 5, %16 ], [ 6, %18 ], [ 7, %20 ], [ 8, %22 ], [ 9, %24 ], [ 10, %26 ], [ 11, %28 ], [ 12, %30 ], [ 13, %32 ], [ 14, %34 ], [ 15, %36 ], [ 16, %38 ], [ 17, %40 ], [ 18, %42 ], [ 19, %44 ], [ 20, %46 ], [ 21, %48 ], [ 22, %50 ], [ 23, %52 ], [ 24, %54 ], [ 25, %56 ], [ 26, %58 ], [ 27, %60 ]
%5 = getelementptr inbounds [29 x i64], [29 x i64]* @rq_hashtable_calc_size.primes, i64 0, i64 %4
%6 = load i64, i64* %5
%7 = trunc i64 %6 to i32
br label %64
8: ; preds = %1
%9 = icmp ult i32 %0, 16
br i1 %9, label %3, label %10
10: ; preds = %8
%11 = icmp ult i32 %0, 32
br i1 %11, label %3, label %12
12: ; preds = %10
%13 = icmp ult i32 %0, 64
br i1 %13, label %3, label %14
14: ; preds = %12
%15 = icmp ult i32 %0, 128
br i1 %15, label %3, label %16
16: ; preds = %14
%17 = icmp ult i32 %0, 256
br i1 %17, label %3, label %18
18: ; preds = %16
%19 = icmp ult i32 %0, 512
br i1 %19, label %3, label %20
20: ; preds = %18
%21 = icmp ult i32 %0, 1024
br i1 %21, label %3, label %22
22: ; preds = %20
%23 = icmp ult i32 %0, 2048
br i1 %23, label %3, label %24
24: ; preds = %22
%25 = icmp ult i32 %0, 4096
br i1 %25, label %3, label %26
26: ; preds = %24
%27 = icmp ult i32 %0, 8192
br i1 %27, label %3, label %28
28: ; preds = %26
%29 = icmp ult i32 %0, 16384
br i1 %29, label %3, label %30
30: ; preds = %28
%31 = icmp ult i32 %0, 32768
br i1 %31, label %3, label %32
32: ; preds = %30
%33 = icmp ult i32 %0, 65536
br i1 %33, label %3, label %34
34: ; preds = %32
%35 = icmp ult i32 %0, 131072
br i1 %35, label %3, label %36
36: ; preds = %34
%37 = icmp ult i32 %0, 262144
br i1 %37, label %3, label %38
38: ; preds = %36
%39 = icmp ult i32 %0, 524288
br i1 %39, label %3, label %40
40: ; preds = %38
%41 = icmp ult i32 %0, 1048576
br i1 %41, label %3, label %42
42: ; preds = %40
%43 = icmp ult i32 %0, 2097152
br i1 %43, label %3, label %44
44: ; preds = %42
%45 = icmp ult i32 %0, 4194304
br i1 %45, label %3, label %46
46: ; preds = %44
%47 = icmp ult i32 %0, 8388608
br i1 %47, label %3, label %48
48: ; preds = %46
%49 = icmp ult i32 %0, 16777216
br i1 %49, label %3, label %50
50: ; preds = %48
%51 = icmp ult i32 %0, 33554432
br i1 %51, label %3, label %52
52: ; preds = %50
%53 = icmp ult i32 %0, 67108864
br i1 %53, label %3, label %54
54: ; preds = %52
%55 = icmp ult i32 %0, 134217728
br i1 %55, label %3, label %56
56: ; preds = %54
%57 = icmp ult i32 %0, 268435456
br i1 %57, label %3, label %58
58: ; preds = %56
%59 = icmp ult i32 %0, 536870912
br i1 %59, label %3, label %60
60: ; preds = %58
%61 = icmp ult i32 %0, 1073741824
br i1 %61, label %3, label %62
62: ; preds = %60
%63 = tail call i32 @assert(i32 0)
br label %64
64: ; preds = %62, %3
%65 = phi i32 [ %7, %3 ], [ 0, %62 ]
ret i32 %65
}