// File: /workspace/github_cpp_makefile_star2_O1/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 0xb74a
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3e5c
movl %edx, %ebx
leaq 0x820(%rsp), %rdi
xorl %ebp, %ebp
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x20d0
cmpq %r14, %r15
jae 0xb78b
movl $0x80000000, %eax       # imm = 0x80000000
movq %r15, %rdx
movl (%rdx), %esi
xorl %eax, %esi
movl %ebx, %ecx
shrl %cl, %esi
movzbl %sil, %ecx
incl 0x820(%rsp,%rcx,4)
addq $0x20, %rdx
cmpq %r14, %rdx
jb 0xb76f
movq %r15, 0xc20(%rsp)
movl $0x1, %eax
movq %r15, %rcx
movl 0x81c(%rsp,%rax,4), %edx
cmpq $0x1, %rdx
sbbl $-0x1, %ebp
shlq $0x5, %rdx
addq %rdx, %rcx
movq %rcx, 0xc20(%rsp,%rax,8)
incq %rax
cmpq $0x101, %rax            # imm = 0x101
jne 0xb79b
cmpl $0x1, %ebp
jbe 0xb8fa
leaq 0x20(%rsp), %rdi
leaq 0xc20(%rsp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x2160
leal -0x8(%rbx), %ebp
xorl %r14d, %r14d
movq 0xc20(%rsp,%r14,8), %rdi
movq 0xc28(%rsp,%r14,8), %rsi
movq %rsi, %rax
subq %rdi, %rax
testq %rax, %rax
jle 0xb8d8
movq 0x20(%rsp,%r14,8), %rdx
cmpq %rsi, %rdx
jae 0xb8bf
movq 0x20(%rsp,%r14,8), %rcx
cmpq %rcx, %rdx
cmovbq %rcx, %rdx
leaq 0x8(%rdx), %r8
movl (%rdx), %r9d
leal -0x80000000(%r9), %r10d
movl %ebx, %ecx
shrl %cl, %r10d
movzbl %r10b, %ecx
movq 0x20(%rsp,%rcx,8), %r10
cmpq %rcx, %r14
je 0xb8ad
movl 0x4(%rdx), %r11d
movq 0x10(%r8), %r15
movq %r15, 0x10(%rsp)
movups (%r8), %xmm0
movaps %xmm0, (%rsp)
movl (%r10), %r15d
movl %r15d, (%rdx)
movl 0x4(%r10), %r15d
movl %r15d, 0x4(%rdx)
leaq 0x8(%r10), %r15
movl $0x2, %r12d
movl (%r10,%r12,4), %r13d
movl %r13d, (%rdx,%r12,4)
incq %r12
cmpq $0x8, %r12
jne 0xb870
leaq 0x20(%r10), %r12
movl %r9d, (%r10)
movl %r11d, 0x4(%r10)
movq 0x10(%rsp), %r9
movq %r9, 0x10(%r15)
movaps (%rsp), %xmm0
movups %xmm0, (%r15)
movq %r12, 0x20(%rsp,%rcx,8)
cmpq %rcx, %r14
jne 0xb826
jmp 0xb8b6
addq $0x20, %r10
movq %r10, 0x20(%rsp,%rcx,8)
addq $0x20, %rdx
jmp 0xb80d
cmpq $0x20, %rax
jle 0xb8d8
cmpl $0x8, %ebx
jb 0xb8d3
movl %ebp, %edx
callq 0xb709
jmp 0xb8d8
callq 0x8483
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0xb7e9
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x8, %ebx
jb 0xb920
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 0xb709
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8483