// File: Baobaobear[P]sort/./sortlib.hpp
// Function: void baobao::internal::indirect_qsort<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
void indirect_qsort(RandomAccessIterator beg, RandomAccessIterator end, Comp compare)
{
    if (end - beg > 1)
    {
        size_t size = (size_t)(end - beg);
        indirect_sort_iter_warp<RandomAccessIterator>* ptr = new indirect_sort_iter_warp<RandomAccessIterator>[size], *ptr_beg = ptr, *ptr_end = ptr + size;
        for (size_t i = 0; i < size; ++i)
        {
            ptr[i].it = beg + i;
            ptr[i].index = i;
        }
        internal::quick_sort(ptr_beg, ptr_end, indirect_sort_comp_warp<RandomAccessIterator, Comp>(compare));
        for (size_t i = 0; i < size; ++i)
        {
            ptr[i].index = ptr[i].it - beg;
        }

        for (size_t index = 0; index < size; ++index)
        {
            if (ptr[index].index)
            {
                size_t i = index;
                typename std::iterator_traits<RandomAccessIterator>::value_type v = *ptr[i].it;
                for (; ptr[i].index > index;)
                {
                    size_t j = ptr[i].index;
                    *ptr[i].it = *ptr[j].it;
                    ptr[i].index = 0;
                    i = j;
                }
                *ptr[i].it = v;
                ptr[i].index = 0;
            }
        }
        delete[] ptr;
    }
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x1, %rax
jle 0x12f8c
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x38(%rsp)
cmpq $0x0, %rax
je 0x12c8f
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rdx
shlq $0x4, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x12fb0
jmp 0x12c77
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rax
addq $0x10, %rax
cmpq %rcx, %rax
movq %rax, 0x28(%rsp)
jne 0x12c66
movq 0x38(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
movq 0x88(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x12d7a
movq 0xc8(%rsp), %rcx
movq 0x88(%rsp), %rax
shlq $0x5, %rax
addq %rax, %rcx
movq 0xb0(%rsp), %rax
movq 0x88(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq 0xb0(%rsp), %rax
movq 0x88(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
jmp 0x12cd7
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
callq 0x2200
jmp 0x12f94
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x87(%rsp), %rdi
callq 0x13090
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x87(%rsp), %rdx
callq 0x12fc0
movq $0x0, 0x78(%rsp)
movq 0x78(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x12e1e
movq 0xb0(%rsp), %rax
movq 0x78(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq 0xc8(%rsp), %rax
subq %rax, %rcx
sarq $0x5, %rcx
movq 0xb0(%rsp), %rax
movq 0x78(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x12dc1
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x12f6f
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x12f5a
movq 0x70(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x86a0
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq 0x70(%rsp), %rax
jbe 0x12f1d
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0xb0(%rsp), %rax
movq 0x40(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x8710
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq 0x40(%rsp), %rax
movq %rax, 0x68(%rsp)
jmp 0x12e84
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8710
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
jmp 0x12f5c
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x12e27
movq 0xb0(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x12f8a
movq (%rsp), %rdi
callq 0x2200
jmp 0x12f8c
addq $0xd8, %rsp
retq
movq 0xa8(%rsp), %rdi
callq 0x2280
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)