#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 int64_t;
typedef int int32_t;

/* Variables and functions */
int INT64_MAX;
int32_t buckets_needed_to_cover_value(int64_t value, int32_t sub_bucket_count,
                                      int32_t unit_magnitude) {
  int64_t smallest_untrackable_value = ((int64_t)sub_bucket_count)
                                       << unit_magnitude;
  int32_t buckets_needed = 1;
  while (smallest_untrackable_value <= value) {
    if (smallest_untrackable_value > INT64_MAX / 2) {
      return buckets_needed + 1;
    }
    smallest_untrackable_value <<= 1;
    buckets_needed++;
  }
  return buckets_needed;
}


x86 assembly (clang, -O0):
<buckets_needed_to_cover_value>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1174 <buckets_needed_to_cover_value+0x74>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jle    115d <buckets_needed_to_cover_value+0x5d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <buckets_needed_to_cover_value+0x7a>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    111f <buckets_needed_to_cover_value+0x1f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<buckets_needed_to_cover_value>:
mov    %edx,%ecx
shl    %cl,%esi
mov    $0x1,%eax
cmp    %edi,%esi
jg     1140 <buckets_needed_to_cover_value+0x40>
mov    0x2ed4(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %ecx,%esi
jg     1140 <buckets_needed_to_cover_value+0x40>
add    %esi,%esi
add    $0x1,%eax
cmp    %edi,%esi
jle    1130 <buckets_needed_to_cover_value+0x30>
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
@INT64_MAX = global i32 0
define i32 @buckets_needed_to_cover_value(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = shl i32 %10, %11
store i32 %12, i32* %8
store i32 1, i32* %9
br label %13
13: ; preds = %25, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i32, i32* %8
%19 = load i32, i32* @INT64_MAX
%20 = sdiv i32 %19, 2
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %32
25: ; preds = %17
%26 = load i32, i32* %8
%27 = shl i32 %26, 1
store i32 %27, i32* %8
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %13
30: ; preds = %13
%31 = load i32, i32* %9
store i32 %31, i32* %4
br label %32
32: ; preds = %30, %22
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@INT64_MAX = global i32 0
define i32 @buckets_needed_to_cover_value(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %1, %2
%5 = icmp sgt i32 %4, %0
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = load i32, i32* @INT64_MAX
%8 = sdiv i32 %7, 2
br label %9
9: ; preds = %6, %15
%10 = phi i32 [ 1, %6 ], [ %17, %15 ]
%11 = phi i32 [ %4, %6 ], [ %16, %15 ]
%12 = icmp sgt i32 %11, %8
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = add nuw nsw i32 %10, 1
br label %19
15: ; preds = %9
%16 = shl i32 %11, 1
%17 = add nuw nsw i32 %10, 1
%18 = icmp sgt i32 %16, %0
br i1 %18, label %19, label %9
19: ; preds = %15, %3, %13
%20 = phi i32 [ %14, %13 ], [ 1, %3 ], [ %17, %15 ]
ret i32 %20
}