#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 */
unsigned int slabs_clsid(size_t size) {
  int res = 1;
  if (size == 0)
    return 0;
  size--;
  while (size >>= 1)
    res++;
  if (res < 3)
    res = 3;
  if (res > 20)
    res = 0;
  return res;
}


x86 assembly (clang, -O0):
<slabs_clsid>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1126 <slabs_clsid+0x26>
movl   $0x0,-0x4(%rbp)
jmp    117e <slabs_clsid+0x7e>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1156 <slabs_clsid+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1132 <slabs_clsid+0x32>
cmpl   $0x3,-0x14(%rbp)
jge    1167 <slabs_clsid+0x67>
movl   $0x3,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jle    1178 <slabs_clsid+0x78>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<slabs_clsid>:
test   %rdi,%rdi
je     1140 <slabs_clsid+0x40>
add    $0xffffffffffffffff,%rdi
mov    $0x3,%eax
cmp    $0x2,%rdi
jb     113f <slabs_clsid+0x3f>
xor    %ecx,%ecx
mov    %rdi,%rdx
nopl   0x0(%rax)
shr    %rdx
add    $0x1,%ecx
cmp    $0x3,%rdi
mov    %rdx,%rdi
ja     1120 <slabs_clsid+0x20>
cmp    $0x3,%ecx
jb     113f <slabs_clsid+0x3f>
lea    0x1(%rcx),%edx
xor    %eax,%eax
cmp    $0x14,%ecx
cmovb  %edx,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @slabs_clsid(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
store i32 1, i32* %4
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %28
8: ; preds = %1
%9 = load i64, i64* %3
%10 = add i64 %9, -1
store i64 %10, i64* %3
br label %11
11: ; preds = %15, %8
%12 = load i64, i64* %3
%13 = lshr i64 %12, 1
store i64 %13, i64* %3
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %11
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 3, i32* %4
br label %22
22: ; preds = %21, %18
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 20
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %4
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %7
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @slabs_clsid(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = add i64 %0, -1
%5 = icmp ult i64 %4, 2
br i1 %5, label %17, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %10, %6 ], [ 1, %3 ]
%8 = phi i64 [ %9, %6 ], [ %4, %3 ]
%9 = lshr i64 %8, 1
%10 = add nuw nsw i32 %7, 1
%11 = icmp ult i64 %8, 4
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = icmp ugt i32 %7, 2
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = icmp ugt i32 %7, 19
%16 = select i1 %15, i32 0, i32 %10
br label %17
17: ; preds = %14, %3, %12, %1
%18 = phi i32 [ 0, %1 ], [ 3, %12 ], [ 3, %3 ], [ %16, %14 ]
ret i32 %18
}