#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 */
scalar_t__ likely(int);
unsigned int tfw_hpack_int_size(unsigned long index, unsigned short max) {
  unsigned int size = 1;
  if (likely(index < max))
    return size;
  ++size;
  index -= max;
  while (index > 0x7F) {
    ++size;
    index >>= 7;
  }
  return size;
}


x86 assembly (clang, -O0):
<tfw_hpack_int_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzwl -0x12(%rbp),%ecx
cmp    %rcx,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <likely@plt>
cmp    $0x0,%rax
je     1157 <tfw_hpack_int_size+0x47>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <tfw_hpack_int_size+0x8c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movzwl -0x12(%rbp),%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x7f,-0x10(%rbp)
jbe    1196 <tfw_hpack_int_size+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x7,%rax
mov    %rax,-0x10(%rbp)
jmp    1171 <tfw_hpack_int_size+0x61>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tfw_hpack_int_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %esi,%r14d
xor    %edi,%edi
cmp    %rbx,%r14
seta   %dil
call   1030 <likely@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1163 <tfw_hpack_int_size+0x53>
sub    %r14,%rbx
mov    $0x2,%eax
cmp    $0x80,%rbx
jb     1163 <tfw_hpack_int_size+0x53>
mov    $0x2,%eax
mov    %rbx,%rcx
xchg   %ax,%ax
add    $0x1,%eax
shr    $0x7,%rcx
cmp    $0x3fff,%rbx
mov    %rcx,%rbx
ja     1150 <tfw_hpack_int_size+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @tfw_hpack_int_size(i64 %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i16
%6 = alloca i32
store i64 %0, i64* %4
store i16 %1, i16* %5
store i32 1, i32* %6
%7 = load i64, i64* %4
%8 = load i16, i16* %5
%9 = zext i16 %8 to i64
%10 = icmp ult i64 %7, %9
%11 = zext i1 %10 to i32
%12 = call i64 @likely(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %33
16: ; preds = %2
%17 = load i32, i32* %6
%18 = add i32 %17, 1
store i32 %18, i32* %6
%19 = load i16, i16* %5
%20 = zext i16 %19 to i64
%21 = load i64, i64* %4
%22 = sub i64 %21, %20
store i64 %22, i64* %4
br label %23
23: ; preds = %26, %16
%24 = load i64, i64* %4
%25 = icmp ugt i64 %24, 127
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %6
%28 = add i32 %27, 1
store i32 %28, i32* %6
%29 = load i64, i64* %4
%30 = lshr i64 %29, 7
store i64 %30, i64* %4
br label %23
31: ; preds = %23
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %33
33: ; preds = %31, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @tfw_hpack_int_size(i64 %0, i16 zeroext %1) {
%3 = zext i16 %1 to i64
%4 = icmp ugt i64 %3, %0
%5 = zext i1 %4 to i32
%6 = tail call i64 @likely(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = sub i64 %0, %3
%10 = icmp ugt i64 %9, 127
br i1 %10, label %11, label %17
11: ; preds = %8, %11
%12 = phi i32 [ %14, %11 ], [ 2, %8 ]
%13 = phi i64 [ %15, %11 ], [ %9, %8 ]
%14 = add nuw nsw i32 %12, 1
%15 = lshr i64 %13, 7
%16 = icmp ugt i64 %13, 16383
br i1 %16, label %11, label %17
17: ; preds = %11, %8, %2
%18 = phi i32 [ 1, %2 ], [ 2, %8 ], [ %14, %11 ]
ret i32 %18
}