// File: /workspace/github_cpp_makefile_star2_O2/Baobaobear[P]sort/./sortlib.hpp
// Function: void baobao::internal::radix_sort_msd_in_place<baobao::TestClass*, baobao::internal::radix_get_index<baobao::TestClass, unsigned int>, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, baobao::internal::radix_get_index<baobao::TestClass, unsigned int>, unsigned int, std::less<baobao::TestClass>)
void radix_sort_msd_in_place(RandomAccessIterator beg, RandomAccessIterator end, RadixIndexFunc get_index, uint32_t offset, Comp compare)
{
    if (end - beg < qsort_insertion_sort_threshold)
    {
        internal::q_insert_sort(beg, end, compare);
        return;
    }
    uint32_t counter[256] = { 0 }, not_empty_count = 0;
    RandomAccessIterator _split_iter[257], *split_iter = &_split_iter[1];
    for (RandomAccessIterator i = beg; i < end; ++i)
    {
        uint32_t index = (get_index(*i) >> offset) & 0xff;
        counter[index]++;
    }
    _split_iter[0] = beg;
    for (size_t i = 0; i < 256; ++i)
    {
        not_empty_count += counter[i] > 0;
        split_iter[i] = split_iter[i - 1] + counter[i];
    }
    if (not_empty_count > 1)
    {
        RandomAccessIterator sort_iter[256];
        memcpy(sort_iter, _split_iter, sizeof(sort_iter));
        for (size_t i = 0; i < 256; ++i)
        {
            if (split_iter[i] - split_iter[i - 1] > 0)
            {
                for (RandomAccessIterator start_i = sort_iter[i]; start_i < split_iter[i]; ++start_i)
                {
                    if (start_i < sort_iter[i]) start_i = sort_iter[i];

                    RandomAccessIterator cur = start_i;
                    while (true)
                    {
                        uint32_t index = (get_index(*cur) >> offset) & 0xff;
                        if (i == index)
                        {
                            sort_iter[index]++;
                            break;
                        }

                        std::swap(*cur, *sort_iter[index]);
                        sort_iter[index]++;
                    }
                }
                if (split_iter[i] - split_iter[i - 1] > 1)
                {
                    if (offset >= 8)
                    {
                        radix_sort_msd_in_place(split_iter[i - 1], split_iter[i], get_index, offset - 8, compare);
                    }
                    else
                    {
                        internal::quick_sort(split_iter[i - 1], split_iter[i], compare);
                    }
                }
            }
        }
    }
    else
    {
        if (offset >= 8)
        {
            radix_sort_msd_in_place(beg, end, get_index, offset - 8, compare);
        }
        else
        {
            internal::quick_sort(beg, end, compare);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1428, %rsp           # imm = 0x1428
movq %rsi, %r14
movq %rdi, %r15
movq %rsi, %rax
subq %rdi, %rax
cmpq $0x4ff, %rax            # imm = 0x4FF
jg 0x8fe6
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3867
movl %edx, %ebx
leaq 0x820(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x20e0
movl $0x80000000, %eax       # imm = 0x80000000
movq %r15, %rdx
cmpq %r14, %rdx
jae 0x9022
movl (%rdx), %esi
xorl %eax, %esi
movl %ebx, %ecx
shrl %cl, %esi
movzbl %sil, %ecx
incl 0x820(%rsp,%rcx,4)
addq $0x20, %rdx
jmp 0x9004
movq %r15, 0xc20(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x100, %rax            # imm = 0x100
je 0x905d
movl 0x820(%rsp,%rax,4), %edx
cmpq $0x1, %rdx
sbbl $-0x1, %ecx
shlq $0x5, %rdx
addq 0xc20(%rsp,%rax,8), %rdx
movq %rdx, 0xc28(%rsp,%rax,8)
incq %rax
jmp 0x902e
cmpl $0x1, %ecx
jbe 0x914d
leaq 0x20(%rsp), %rdi
leaq 0xc20(%rsp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x2150
leal -0x8(%rbx), %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
movl $0x80000000, %r15d      # imm = 0x80000000
cmpq $0x100, %rbp            # imm = 0x100
je 0x9173
movq 0xc20(%rsp,%rbp,8), %rcx
movq 0xc28(%rsp,%rbp,8), %rax
movq %rax, (%rsp)
subq %rcx, %rax
testq %rax, %rax
jle 0x9145
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp,%rbp,8), %rax
movq %rax, %r12
cmpq (%rsp), %r12
jae 0x911b
cmpq %rax, %r12
cmovbq %rax, %r12
movl (%r12), %eax
xorl %r15d, %eax
movl %ebx, %ecx
shrl %cl, %eax
movzbl %al, %r14d
cmpq %r14, %rbp
je 0x9107
movq 0x20(%rsp,%r14,8), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x4106
addq $0x20, %r13
movq %r13, 0x20(%rsp,%r14,8)
jmp 0x90d8
movq 0x20(%rsp,%rbp,8), %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp,%rbp,8)
addq $0x20, %r12
jmp 0x90cb
cmpq $0x20, 0x10(%rsp)
movq 0x18(%rsp), %rdi
jle 0x9145
cmpl $0x8, %ebx
jb 0x913c
movq (%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0x8fa5
jmp 0x9145
movq (%rsp), %rsi
callq 0x6ed4
incq %rbp
jmp 0x908c
cmpl $0x8, %ebx
jb 0x9185
addl $-0x8, %ebx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8fa5
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ed4