#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 */
int /*<<< orphan*/ assert(int);
int nlz16(unsigned int);
int calc_index(unsigned int alloc_size) {
  if ((alloc_size >> (9 + 3 + 4)) != 0) {
    return ((9 + 1) * (1 << 3));
  }
  int fli = 16 - nlz16(alloc_size >> (3 + 4));
  int shift = (fli == 0) ? (fli + 4) : (fli + 4 - 1);
  int sli = (alloc_size >> shift) & ((1 << 3) - 1);
  int index = (fli << 3) + sli;
  assert(fli >= 0);
  assert(fli <= 9);
  assert(sli >= 0);
  assert(sli <= (1 << 3) - 1);
  return index;
}


x86 assembly (clang, -O0):
<calc_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
cmp    $0x0,%eax
je     1146 <calc_index+0x26>
movl   $0x50,-0x4(%rbp)
jmp    11eb <calc_index+0xcb>
mov    -0x8(%rbp),%edi
shr    $0x7,%edi
call   1040 <nlz16@plt>
mov    %eax,%ecx
mov    $0x10,%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1175 <calc_index+0x55>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <calc_index+0x61>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
shr    %cl,%eax
and    $0x7,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x9,-0xc(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x7,-0x14(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_index>:
mov    $0x50,%eax
cmp    $0xffff,%edi
ja     119f <calc_index+0x7f>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
shr    $0x7,%edi
call   1040 <nlz16@plt>
mov    %eax,%r14d
mov    $0x13,%al
sub    %r14b,%al
cmp    $0x10,%r14d
movzbl %al,%eax
mov    $0x4,%ecx
cmovne %eax,%ecx
shr    %cl,%ebx
and    $0x7,%ebx
lea    0x0(,%r14,8),%eax
sub    %eax,%ebx
sub    $0xffffff80,%ebx
xor    %edi,%edi
cmp    $0x11,%r14d
setl   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x7,%r14d
setge  %dil
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @calc_index(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = lshr i32 %8, 16
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 80, i32* %2
br label %53
12: ; preds = %1
%13 = load i32, i32* %3
%14 = lshr i32 %13, 7
%15 = call i32 @nlz16(i32 %14)
%16 = sub nsw i32 16, %15
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 4
br label %26
22: ; preds = %12
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 4
%25 = sub nsw i32 %24, 1
br label %26
26: ; preds = %22, %19
%27 = phi i32 [ %21, %19 ], [ %25, %22 ]
store i32 %27, i32* %5
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = lshr i32 %28, %29
%31 = and i32 %30, 7
store i32 %31, i32* %6
%32 = load i32, i32* %4
%33 = shl i32 %32, 3
%34 = load i32, i32* %6
%35 = add nsw i32 %33, %34
store i32 %35, i32* %7
%36 = load i32, i32* %4
%37 = icmp sge i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32, i32* %4
%41 = icmp sle i32 %40, 9
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %6
%45 = icmp sge i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* %6
%49 = icmp sle i32 %48, 7
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i32, i32* %7
store i32 %52, i32* %2
br label %53
53: ; preds = %26, %11
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @calc_index(i32 %0) {
%2 = icmp ult i32 %0, 65536
br i1 %2, label %3, label %22
3: ; preds = %1
%4 = lshr i32 %0, 7
%5 = tail call i32 @nlz16(i32 %4)
%6 = icmp eq i32 %5, 16
%7 = sub i32 19, %5
%8 = select i1 %6, i32 4, i32 %7
%9 = lshr i32 %0, %8
%10 = and i32 %9, 7
%11 = mul i32 %5, -8
%12 = add i32 %11, 128
%13 = or i32 %10, %12
%14 = icmp slt i32 %5, 17
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = icmp sgt i32 %5, 6
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = tail call i32 @assert(i32 1)
%21 = tail call i32 @assert(i32 1)
br label %22
22: ; preds = %1, %3
%23 = phi i32 [ %13, %3 ], [ 80, %1 ]
ret i32 %23
}