#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 uint32_t;

/* Variables and functions */
int UINT32_C(int);
uint32_t dict_calc_hash_size(uint32_t elements) {
  uint32_t res = 1;
  while (elements) {
    elements >>= 1;
    res <<= 1;
  }
  if (res == 0) {
    res = UINT32_C(0x80000000);
  }
  if (res < (1 << 20)) {
    return (1 << 20);
  }
  return res;
}


x86 assembly (clang, -O0):
<dict_calc_hash_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1143 <dict_calc_hash_size+0x33>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1122 <dict_calc_hash_size+0x12>
cmpl   $0x0,-0xc(%rbp)
jne    115a <dict_calc_hash_size+0x4a>
mov    $0x80000000,%edi
call   1030 <UINT32_C@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x100000,-0xc(%rbp)
jge    1173 <dict_calc_hash_size+0x63>
movl   $0x100000,-0x4(%rbp)
jmp    1179 <dict_calc_hash_size+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dict_calc_hash_size>:
test   %edi,%edi
je     114e <dict_calc_hash_size+0x3e>
mov    $0x1,%eax
mov    %edi,%ecx
nopl   0x0(%rax,%rax,1)
sar    %ecx
add    %eax,%eax
cmp    $0x1,%edi
mov    %ecx,%edi
ja     1120 <dict_calc_hash_size+0x10>
test   %eax,%eax
jne    113e <dict_calc_hash_size+0x2e>
push   %rax
mov    $0x80000000,%edi
call   1030 <UINT32_C@plt>
add    $0x8,%rsp
cmp    $0x100001,%eax
mov    $0x100000,%ecx
cmovge %eax,%ecx
mov    %ecx,%eax
ret
mov    $0x100000,%eax
ret

LLVM IR (-O0):
define i32 @dict_calc_hash_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
br label %5
5: ; preds = %8, %1
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* %3
%10 = ashr i32 %9, 1
store i32 %10, i32* %3
%11 = load i32, i32* %4
%12 = shl i32 %11, 1
store i32 %12, i32* %4
br label %5
13: ; preds = %5
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @UINT32_C(i32 -2147483648)
store i32 %17, i32* %4
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 1048576
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1048576, i32* %2
br label %24
22: ; preds = %18
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %21
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @dict_calc_hash_size(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %7, %3 ], [ 1, %1 ]
%5 = phi i32 [ %6, %3 ], [ %0, %1 ]
%6 = ashr i32 %5, 1
%7 = shl i32 %4, 1
%8 = icmp ult i32 %5, 2
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = icmp eq i32 %7, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @UINT32_C(i32 -2147483648)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %12, %11 ], [ %7, %9 ]
%15 = icmp sgt i32 %14, 1048576
%16 = select i1 %15, i32 %14, i32 1048576
br label %17
17: ; preds = %13, %1
%18 = phi i32 [ 1048576, %1 ], [ %16, %13 ]
ret i32 %18
}