// File: /workspace/github_cpp_makefile_star2_O2/walker-xian[P]teisye/src/teisye.cpp
// Function: teisye::heap::alloc(unsigned long)
inline void* alloc(size_t size) noexcept
    {
        auto key = _book.key(size + sizeof(memory_unit::header));
        memory_unit* unit{};
        if (key <= _book.key_max_small())
        {
            unit = _thread_cache.alloc(key);
            if (unit)
            {
                unit->_header._idle = false;
                unit->_header._size = static_cast<uint32_t>(size);
                assert(validate(unit));
                return &unit->_next;
            }
        }

        if (key <= _book.key_max_medium())
        {
            unit = _shared_cache.alloc(key);
            if (unit)
            {
                unit->_header._idle = false;
                unit->_header._size = static_cast<uint32_t>(size);
                assert(validate(unit));
                return &unit->_next;
            }

            unit = _slabs.alloc(_book.value(key));
        }
        else if (key <= _book.key_max_large())
        {
            unit = _large.alloc(size);
        }
        else
        {
            size_t adjusted_size = size + sizeof(huge_unit) + sizeof(huge_unit::_raw_ptr);
            void *raw_ptr = ::malloc(adjusted_size);
            if (raw_ptr)
            {
                auto hu = align<huge_unit*>(raw_ptr, sizeof(huge_unit)) - 1;
                assert(hu >= raw_ptr);
                hu->_raw_ptr = raw_ptr;
                unit = reinterpret_cast<memory_unit*>(&hu->_unit);
            }
        }

        assert(unit);
        if (unit)
        {
            unit->_header._size = static_cast<uint32_t>(size);
            unit->_header._signature = _unit_signature;
            unit->_header._key = key;
            unit->_header._idle = false;
            assert(is_aligned(&unit->_next));
            assert(validate(unit));
            return &unit->_next;
        }

        return nullptr;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
addq $0x8, %rsi
leaq 0xf0ce(%rip), %r12      # 0x21718
movq %r12, %rdi
callq 0x129b6
movl %eax, %ebp
movsbl %al, %r13d
cmpb 0xf24a(%rip), %al       # 0x218a8
jg 0x126bf
callq 0x125f0
movq %fs:0x0, %rax
leaq -0x1a0(%rax), %rdi
movl %r13d, %esi
callq 0x12b06
testq %rax, %rax
je 0x126bf
movq %rax, %r15
movb $0x0, 0x3(%rax)
movl %r14d, 0x4(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1298e
testb %al, %al
jne 0x12734
leaq 0x31b9(%rip), %rdi      # 0x15860
leaq 0x31c1(%rip), %rsi      # 0x1586f
leaq 0x31c9(%rip), %rcx      # 0x1587e
movl $0x297, %edx            # imm = 0x297
callq 0x4220
cmpb 0xf1e3(%rip), %bpl      # 0x218a9
jle 0x12702
cmpb 0xf1db(%rip), %bpl      # 0x218aa
jle 0x1273a
leaq 0x18(%r14), %rdi
callq 0x4530
testq %rax, %rax
je 0x127a4
leaq 0x1f(%rax), %rsi
andq $-0x10, %rsi
leaq -0x10(%rsi), %rcx
cmpq %rax, %rcx
jb 0x12820
movq %rax, -0x10(%rsi)
addq $-0x8, %rsi
jmp 0x1276b
leaq 0xf1a7(%rip), %rdi      # 0x218b0
movl %r13d, %esi
callq 0x12b40
testq %rax, %rax
je 0x12748
movq %rax, %r15
movb $0x0, 0x3(%rax)
movl %r14d, 0x4(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1298e
testb %al, %al
je 0x12801
addq $0x8, %r15
jmp 0x12792
leaq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x12bf0
jmp 0x12763
cmpb $0x31, %bpl
jg 0x12758
movsbq %bpl, %rax
movq (%r12,%rax,8), %rsi
jmp 0x1275b
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x12b76
movq %rax, %rsi
testq %rax, %rax
je 0x127a4
movl %r14d, 0x4(%rsi)
movw $0x6871, (%rsi)         # imm = 0x6871
movb %bpl, 0x2(%rsi)
movb $0x0, 0x3(%rsi)
leaq 0x8(%rsi), %r15
testb $0xf, %r15b
jne 0x127c3
movq %rbx, %rdi
callq 0x1298e
testb %al, %al
je 0x127e2
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3103(%rip), %rdi      # 0x158ae
leaq 0x30bd(%rip), %rsi      # 0x1586f
leaq 0x30c5(%rip), %rcx      # 0x1587e
movl $0x2ba, %edx            # imm = 0x2BA
callq 0x4220
leaq 0x30e9(%rip), %rdi      # 0x158b3
leaq 0x309e(%rip), %rsi      # 0x1586f
leaq 0x30a6(%rip), %rcx      # 0x1587e
movl $0x2c1, %edx            # imm = 0x2C1
callq 0x4220
leaq 0x3077(%rip), %rdi      # 0x15860
leaq 0x307f(%rip), %rsi      # 0x1586f
leaq 0x3087(%rip), %rcx      # 0x1587e
movl $0x2c2, %edx            # imm = 0x2C2
callq 0x4220
leaq 0x3058(%rip), %rdi      # 0x15860
leaq 0x3060(%rip), %rsi      # 0x1586f
leaq 0x3068(%rip), %rcx      # 0x1587e
movl $0x2a3, %edx            # imm = 0x2A3
callq 0x4220
leaq 0x3079(%rip), %rdi      # 0x158a0
leaq 0x3041(%rip), %rsi      # 0x1586f
leaq 0x3049(%rip), %rcx      # 0x1587e
movl $0x2b4, %edx            # imm = 0x2B4
callq 0x4220
nop