#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 log2_64(int);
int size_class_num_tiny();
scalar_t__ size_in_tiny(size_t);
int size_to_size_class(size_t size) {
  if (size_in_tiny(size))
    return (size + (16 - 1)) / 16 - 1;
  return log2_64(size - 1) - log2_64(256) + size_class_num_tiny();
}


x86 assembly (clang, -O0):
<size_to_size_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <size_in_tiny@plt>
cmp    $0x0,%rax
je     1167 <size_to_size_class+0x37>
mov    -0x10(%rbp),%rax
add    $0xf,%rax
shr    $0x4,%rax
sub    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    119e <size_to_size_class+0x6e>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edi
call   1050 <log2_64@plt>
mov    %eax,-0x18(%rbp)
mov    $0x100,%edi
call   1050 <log2_64@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <size_class_num_tiny@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size_to_size_class>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <size_in_tiny@plt>
test   %rax,%rax
je     114d <size_to_size_class+0x1d>
add    $0xf,%rbx
shr    $0x4,%rbx
add    $0xffffffff,%ebx
jmp    1170 <size_to_size_class+0x40>
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1050 <log2_64@plt>
mov    %eax,%ebp
mov    $0x100,%edi
call   1050 <log2_64@plt>
sub    %eax,%ebp
xor    %eax,%eax
call   1040 <size_class_num_tiny@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @size_to_size_class(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = call i64 @size_in_tiny(i64 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i64, i64* %3
%9 = add i64 %8, 15
%10 = udiv i64 %9, 16
%11 = sub i64 %10, 1
%12 = trunc i64 %11 to i32
store i32 %12, i32* %2
br label %22
13: ; preds = %1
%14 = load i64, i64* %3
%15 = sub i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i32 @log2_64(i32 %16)
%18 = call i32 @log2_64(i32 256)
%19 = sub nsw i32 %17, %18
%20 = call i32 (...) @size_class_num_tiny()
%21 = add nsw i32 %19, %20
store i32 %21, i32* %2
br label %22
22: ; preds = %13, %7
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @size_to_size_class(i64 %0) {
%2 = tail call i64 @size_in_tiny(i64 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = add i64 %0, 15
%6 = lshr i64 %5, 4
%7 = trunc i64 %6 to i32
%8 = add i32 %7, -1
br label %17
9: ; preds = %1
%10 = trunc i64 %0 to i32
%11 = add i32 %10, -1
%12 = tail call i32 @log2_64(i32 %11)
%13 = tail call i32 @log2_64(i32 256)
%14 = sub i32 %12, %13
%15 = tail call i32 (...) @size_class_num_tiny()
%16 = add nsw i32 %14, %15
br label %17
17: ; preds = %9, %4
%18 = phi i32 [ %8, %4 ], [ %16, %9 ]
ret i32 %18
}