// File: Baobaobear[P]sort/./sortlib.hpp
// Function: void baobao::internal::quick_sort_loop<baobao::internal::indirect_sort_iter_warp<baobao::TestClass*>*, baobao::internal::indirect_sort_comp_warp<baobao::TestClass*, std::less<baobao::TestClass>>>(baobao::internal::indirect_sort_iter_warp<baobao::TestClass*>*, baobao::internal::indirect_sort_iter_warp<baobao::TestClass*>*, int, baobao::internal::indirect_sort_comp_warp<baobao::TestClass*, std::less<baobao::TestClass>>, bool)
void quick_sort_loop(RandomAccessIterator beg, RandomAccessIterator end, int deep, Comp compare, bool leftmost)
{
    if (end - beg <= qsort_insertion_sort_threshold)
    {
        if (leftmost)
        {
            q_insert_sort(beg, end, compare);
        }
        else
        {
            unguarded_q_insert_sort(beg, end, compare);
        }
        return;
    }
    if (deep <= 0)
    {
        shell_sort(beg, end, compare);
        return;
    }

    bool swaped = false;
    RandomAccessIterator l = quick_sort_partition(beg, end, compare, swaped), r = l + 1;
    if (!swaped && !compare(*(l - 1), *beg))
    {
        RandomAccessIterator i = leftmost ? insert_sort_limit(beg, l, compare, 1)
            : unguarded_insert_sort_limit(beg, l, compare, 1);
        if (i == l)
        {
            i = unguarded_insert_sort_limit(r, end, compare, 1);
        }
        if (i == end)
        {
            return;
        }
        if (i >= l)
        {
            while (r < end && util::object_equal(*r, *l, compare)) ++r;
            return quick_sort_loop(r, end, deep - 1, compare, false);
        }
    }
    while (r < end && util::object_equal(*r, *l, compare)) ++r;

    quick_sort_loop(beg, l, deep - 1, compare, leftmost);
    quick_sort_loop(r, end, deep - 1, compare, false);
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rcx, 0xf0(%rsp)
movb %r8b, %al
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movl %edx, 0x134(%rsp)
movq %rcx, 0x128(%rsp)
andb $0x1, %al
movb %al, 0x127(%rsp)
movq 0x138(%rsp), %rax
movq 0x140(%rsp), %rcx
subq %rcx, %rax
sarq $0x4, %rax
cmpq $0x28, %rax
jg 0x131b0
testb $0x1, 0x127(%rsp)
je 0x13159
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0x126(%rsp), %rdi
callq 0x13670
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
leaq 0x126(%rsp), %rdx
callq 0x13680
jmp 0x131ab
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0x125(%rsp), %rdi
callq 0x13670
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
leaq 0x125(%rsp), %rdx
callq 0x13820
jmp 0x13666
cmpl $0x0, 0x134(%rsp)
jg 0x13211
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x124(%rsp), %rdi
callq 0x13670
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
leaq 0x124(%rsp), %rdx
callq 0x139a0
jmp 0x13666
movq 0xf0(%rsp), %rsi
movb $0x0, 0x123(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0x117(%rsp), %rdi
callq 0x13670
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
leaq 0x117(%rsp), %rdx
leaq 0x123(%rsp), %rcx
callq 0x13ef0
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x108(%rsp)
testb $0x1, 0x123(%rsp)
jne 0x13521
movq 0xf0(%rsp), %rdi
movq 0x118(%rsp), %rsi
addq $-0x10, %rsi
movq 0x140(%rsp), %rdx
callq 0x144a0
testb $0x1, %al
jne 0x13521
testb $0x1, 0x127(%rsp)
je 0x13331
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xff(%rsp), %rdi
callq 0x13670
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0xff(%rsp), %rdx
movl $0x1, %ecx
callq 0x14530
movq %rax, 0xa8(%rsp)
jmp 0x13390
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0xfe(%rsp), %rdi
callq 0x13670
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
leaq 0xfe(%rsp), %rdx
movl $0x1, %ecx
callq 0x146b0
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
cmpq 0x118(%rsp), %rax
jne 0x1340b
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0xfd(%rsp), %rdi
callq 0x13670
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
leaq 0xfd(%rsp), %rdx
movl $0x1, %ecx
callq 0x146b0
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
cmpq 0x138(%rsp), %rax
jne 0x13422
jmp 0x13666
movq 0x100(%rsp), %rax
cmpq 0x118(%rsp), %rax
jb 0x1351f
jmp 0x1343a
movq 0x108(%rsp), %rcx
xorl %eax, %eax
cmpq 0x138(%rsp), %rcx
movb %al, 0x77(%rsp)
jae 0x1349c
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0xfc(%rsp), %rdi
callq 0x13670
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
leaq 0xfc(%rsp), %rdx
callq 0x14810
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x134a6
jmp 0x134bf
movq 0x108(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x108(%rsp)
jmp 0x1343a
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x134(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x5c(%rsp)
leaq 0xfb(%rsp), %rdi
callq 0x13670
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl 0x5c(%rsp), %edx
leaq 0xfb(%rsp), %rcx
xorl %r8d, %r8d
callq 0x130a0
jmp 0x13666
jmp 0x13521
jmp 0x13523
movq 0x108(%rsp), %rcx
xorl %eax, %eax
cmpq 0x138(%rsp), %rcx
movb %al, 0x47(%rsp)
jae 0x13585
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0xfa(%rsp), %rdi
callq 0x13670
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0xfa(%rsp), %rdx
callq 0x14810
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x1358f
jmp 0x135a8
movq 0x108(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x108(%rsp)
jmp 0x13523
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rax
movq %rax, (%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x134(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x14(%rsp)
leaq 0xf9(%rsp), %rdi
callq 0x13670
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edx
movb 0x127(%rsp), %al
leaq 0xf9(%rsp), %rcx
andb $0x1, %al
movzbl %al, %r8d
callq 0x130a0
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x134(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x2c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x13670
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %edx
leaq 0xf8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x130a0
addq $0x148, %rsp            # imm = 0x148
retq
nop