#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 */

/* Variables and functions */
size_t dhash_size(size_t entries) {
  size_t primes[] = {
      389UL,       769UL,       1543UL,       3079UL,       6151UL,
      12289UL,     24593UL,     49157UL,      98317UL,      196613UL,
      393241UL,    786433UL,    1572869UL,    3145739UL,    6291469UL,
      12582917UL,  25165843UL,  50331653UL,   100663319UL,  201326611UL,
      402653189UL, 805306457UL, 1610612741UL, 3221225473UL, 4294967291UL};
  size_t const p_count = 20;
  size_t wantsize = entries << 1, i;
  if (entries > 2147483645UL) {
    return 0;
  }
  for (i = 0; i < p_count - 1; i++) {
    if (primes[i] > wantsize) {
      break;
    }
  }
  return primes[i];
}


x86 assembly (clang, -O0):
<dhash_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xed3(%rip),%rsi
mov    $0xc8,%edx
call   1030 <memcpy@plt>
movq   $0x14,-0xe8(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0xf0(%rbp)
cmpq   $0x7ffffffd,-0x10(%rbp)
7f
jbe    116c <dhash_size+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <dhash_size+0xc5>
movq   $0x0,-0xf8(%rbp)
cmpq   $0x13,-0xf8(%rbp)
13
jae    11c2 <dhash_size+0xb2>
mov    -0xf8(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
cmp    -0xf0(%rbp),%rax
jbe    11a6 <dhash_size+0x96>
jmp    11c2 <dhash_size+0xb2>
jmp    11ab <dhash_size+0x9b>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    1177 <dhash_size+0x67>
mov    -0xf8(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhash_size>:
cmp    $0x7ffffffd,%rdi
jbe    110c <dhash_size+0xc>
xor    %eax,%eax
ret
add    %rdi,%rdi
cmp    $0x185,%rdi
jae    111f <dhash_size+0x1f>
xor    %eax,%eax
jmp    1241 <dhash_size+0x141>
mov    $0x1,%eax
cmp    $0x301,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x2,%eax
cmp    $0x607,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x3,%eax
cmp    $0xc07,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x4,%eax
cmp    $0x1807,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x5,%eax
cmp    $0x3001,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x6,%eax
cmp    $0x6011,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x7,%eax
cmp    $0xc005,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x8,%eax
cmp    $0x1800d,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x9,%eax
cmp    $0x30005,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xa,%eax
cmp    $0x60019,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xb,%eax
cmp    $0xc0001,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xc,%eax
cmp    $0x180005,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xd,%eax
cmp    $0x30000b,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xe,%eax
cmp    $0x60000d,%rdi
jb     1241 <dhash_size+0x141>
mov    $0xf,%eax
cmp    $0xc00005,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x10,%eax
cmp    $0x1800013,%rdi
jb     1241 <dhash_size+0x141>
mov    $0x11,%eax
cmp    $0x3000005,%rdi
jb     1241 <dhash_size+0x141>
cmp    $0x6000017,%rdi
mov    $0x13,%eax
sbb    $0x0,%rax
lea    0xdb8(%rip),%rcx
mov    (%rcx,%rax,8),%rax
ret

LLVM IR (-O0):
@__const.dhash_size.primes = [25 x i64] [i64 389, i64 769, i64 1543, i64 3079, i64 6151, i64 12289, i64 24593, i64 49157, i64 98317, i64 196613, i64 393241, i64 786433, i64 1572869, i64 3145739, i64 6291469, i64 12582917, i64 25165843, i64 50331653, i64 100663319, i64 201326611, i64 402653189, i64 805306457, i64 1610612741, i64 3221225473, i64 4294967291]
define i64 @dhash_size(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [25 x i64]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
%8 = bitcast [25 x i64]* %4 to i8*
store i64 20, i64* %5
%9 = load i64, i64* %3
%10 = shl i64 %9, 1
store i64 %10, i64* %6
%11 = load i64, i64* %3
%12 = icmp ugt i64 %11, 2147483645
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 0, i64* %2
br label %33
14: ; preds = %1
store i64 0, i64* %7
br label %15
15: ; preds = %26, %14
%16 = load i64, i64* %7
%17 = icmp ult i64 %16, 19
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i64, i64* %7
%20 = getelementptr inbounds [25 x i64], [25 x i64]* %4, i64 0, i64 %19
%21 = load i64, i64* %20
%22 = load i64, i64* %6
%23 = icmp ugt i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
br label %29
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
br label %15
29: ; preds = %24, %15
%30 = load i64, i64* %7
%31 = getelementptr inbounds [25 x i64], [25 x i64]* %4, i64 0, i64 %30
%32 = load i64, i64* %31
store i64 %32, i64* %2
br label %33
33: ; preds = %29, %13
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
@__const.dhash_size.primes = [25 x i64] [i64 389, i64 769, i64 1543, i64 3079, i64 6151, i64 12289, i64 24593, i64 49157, i64 98317, i64 196613, i64 393241, i64 786433, i64 1572869, i64 3145739, i64 6291469, i64 12582917, i64 25165843, i64 50331653, i64 100663319, i64 201326611, i64 402653189, i64 805306457, i64 1610612741, i64 3221225473, i64 4294967291]
define i64 @dhash_size(i64 %0) {
%2 = shl i64 %0, 1
%3 = icmp ugt i64 %0, 2147483645
br i1 %3, label %47, label %4
4: ; preds = %1
%5 = icmp ult i64 %2, 389
br i1 %5, label %43, label %6
6: ; preds = %4
%7 = icmp ult i64 %2, 769
br i1 %7, label %43, label %8
8: ; preds = %6
%9 = icmp ult i64 %2, 1543
br i1 %9, label %43, label %10
10: ; preds = %8
%11 = icmp ult i64 %2, 3079
br i1 %11, label %43, label %12
12: ; preds = %10
%13 = icmp ult i64 %2, 6151
br i1 %13, label %43, label %14
14: ; preds = %12
%15 = icmp ult i64 %2, 12289
br i1 %15, label %43, label %16
16: ; preds = %14
%17 = icmp ult i64 %2, 24593
br i1 %17, label %43, label %18
18: ; preds = %16
%19 = icmp ult i64 %2, 49157
br i1 %19, label %43, label %20
20: ; preds = %18
%21 = icmp ult i64 %2, 98317
br i1 %21, label %43, label %22
22: ; preds = %20
%23 = icmp ult i64 %2, 196613
br i1 %23, label %43, label %24
24: ; preds = %22
%25 = icmp ult i64 %2, 393241
br i1 %25, label %43, label %26
26: ; preds = %24
%27 = icmp ult i64 %2, 786433
br i1 %27, label %43, label %28
28: ; preds = %26
%29 = icmp ult i64 %2, 1572869
br i1 %29, label %43, label %30
30: ; preds = %28
%31 = icmp ult i64 %2, 3145739
br i1 %31, label %43, label %32
32: ; preds = %30
%33 = icmp ult i64 %2, 6291469
br i1 %33, label %43, label %34
34: ; preds = %32
%35 = icmp ult i64 %2, 12582917
br i1 %35, label %43, label %36
36: ; preds = %34
%37 = icmp ult i64 %2, 25165843
br i1 %37, label %43, label %38
38: ; preds = %36
%39 = icmp ult i64 %2, 50331653
br i1 %39, label %43, label %40
40: ; preds = %38
%41 = icmp ult i64 %2, 100663319
%42 = select i1 %41, i64 18, i64 19
br label %43
43: ; preds = %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6, %4
%44 = phi i64 [ 0, %4 ], [ 1, %6 ], [ 2, %8 ], [ 3, %10 ], [ 4, %12 ], [ 5, %14 ], [ 6, %16 ], [ 7, %18 ], [ 8, %20 ], [ 9, %22 ], [ 10, %24 ], [ 11, %26 ], [ 12, %28 ], [ 13, %30 ], [ 14, %32 ], [ 15, %34 ], [ 16, %36 ], [ 17, %38 ], [ %42, %40 ]
%45 = getelementptr inbounds [25 x i64], [25 x i64]* @__const.dhash_size.primes, i64 0, i64 %44
%46 = load i64, i64* %45
br label %47
47: ; preds = %1, %43
%48 = phi i64 [ %46, %43 ], [ 0, %1 ]
ret i64 %48
}