// File: /workspace/github_cpp_makefile_star2_O3/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 0xb536
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3dcc
movl %edx, %ebx
leaq 0x820(%rsp), %rdi
xorl %ebp, %ebp
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x20d0
cmpq %r14, %r15
jae 0xb577
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 0xb55b
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 0xb587
cmpl $0x1, %ebp
jbe 0xb6fe
leaq 0x20(%rsp), %rdi
leaq 0xc20(%rsp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x2150
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 0xb6dc
movq 0x20(%rsp,%r14,8), %r9
movq %r9, %rdx
cmpq %rsi, %r9
jae 0xb6c3
cmpq %r9, %rdx
cmovbq %r9, %rdx
movl (%rdx), %r8d
leal -0x80000000(%r8), %r10d
movl %ebx, %ecx
shrl %cl, %r10d
movzbl %r10b, %ecx
cmpq %rcx, %r14
je 0xb6ad
leaq 0x8(%rdx), %r9
movq 0x20(%rsp,%rcx,8), %r10
movl 0x4(%rdx), %r11d
movq 0x10(%r9), %r15
movq %r15, 0x10(%rsp)
movups (%r9), %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 0xb65e
movl %r8d, (%r10)
movl %r11d, 0x4(%r10)
movq 0x10(%rsp), %r8
movq %r8, 0x10(%r15)
movaps (%rsp), %xmm0
movups %xmm0, (%r15)
addq $0x20, %r10
movq %r10, 0x20(%rsp,%rcx,8)
movl (%rdx), %r8d
leal -0x80000000(%r8), %r10d
movl %ebx, %ecx
shrl %cl, %r10d
movzbl %r10b, %ecx
cmpq %rcx, %r14
jne 0xb62c
movq 0x20(%rsp,%r14,8), %r9
addq $0x20, %r9
movq %r9, 0x20(%rsp,%r14,8)
addq $0x20, %rdx
cmpq %rsi, %rdx
jb 0xb605
cmpq $0x20, %rax
jle 0xb6dc
cmpl $0x8, %ebx
jb 0xb6d7
movl %ebp, %edx
callq 0xb4f5
jmp 0xb6dc
callq 0x83f0
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0xb5d5
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x8, %ebx
jb 0xb724
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 0xb4f5
movq %r15, %rdi
movq %r14, %rsi
addq $0x1428, %rsp           # imm = 0x1428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x83f0