#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 uint32_t;

/* Variables and functions */
int tlsf_fls(size_t);
void tlsf_mapping_insert(size_t size, uint32_t *first_level,
                         uint32_t *second_level) {
  if (size < (1 << 7)) {
    *first_level = 0;
    *second_level = size / ((1 << 7) / (1 << 5));
  } else {
    *first_level = tlsf_fls(size);
    *second_level = (size >> (*first_level - 5)) - (1 << 5);
    *first_level = *first_level - (7 - 1);
  }
}


x86 assembly (clang, -O0):
<tlsf_mapping_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x80,-0x8(%rbp)
jae    1151 <tlsf_mapping_insert+0x41>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
shr    $0x2,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    118f <tlsf_mapping_insert+0x7f>
mov    -0x8(%rbp),%rdi
call   1030 <tlsf_fls@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x5,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
sub    $0x20,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0x6,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlsf_mapping_insert>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
cmp    $0x7f,%rdi
ja     1134 <tlsf_mapping_insert+0x24>
movl   $0x0,(%r15)
shr    $0x2,%rbx
mov    %ebx,(%r14)
jmp    114f <tlsf_mapping_insert+0x3f>
mov    %rbx,%rdi
call   1030 <tlsf_fls@plt>
mov    %eax,(%r15)
lea    -0x5(%rax),%ecx
shr    %cl,%rbx
add    $0xffffffe0,%ebx
mov    %ebx,(%r14)
addl   $0xfffffffa,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @tlsf_mapping_insert(i64 %0, i32* %1, i32* %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32*
store i64 %0, i64* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%7 = load i64, i64* %4
%8 = icmp ult i64 %7, 128
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = load i32*, i32** %5
store i32 0, i32* %10
%11 = load i64, i64* %4
%12 = udiv i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = load i32*, i32** %6
store i32 %13, i32* %14
br label %32
15: ; preds = %3
%16 = load i64, i64* %4
%17 = call i32 @tlsf_fls(i64 %16)
%18 = load i32*, i32** %5
store i32 %17, i32* %18
%19 = load i64, i64* %4
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = sub nsw i32 %21, 5
%23 = zext i32 %22 to i64
%24 = lshr i64 %19, %23
%25 = sub i64 %24, 32
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %6
store i32 %26, i32* %27
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, 6
%31 = load i32*, i32** %5
store i32 %30, i32* %31
br label %32
32: ; preds = %15, %9
ret void
}

LLVM IR (-O2):
define void @tlsf_mapping_insert(i64 %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = icmp ult i64 %0, 128
br i1 %4, label %5, label %8
5: ; preds = %3
store i32 0, i32* %1
%6 = lshr i64 %0, 2
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
br label %17
8: ; preds = %3
%9 = tail call i32 @tlsf_fls(i64 %0)
store i32 %9, i32* %1
%10 = add nsw i32 %9, -5
%11 = zext i32 %10 to i64
%12 = lshr i64 %0, %11
%13 = trunc i64 %12 to i32
%14 = add i32 %13, -32
store i32 %14, i32* %2
%15 = load i32, i32* %1
%16 = add nsw i32 %15, -6
store i32 %16, i32* %1
br label %17
17: ; preds = %8, %5
ret void
}