// File: Baobaobear[P]sort/./sortlib.hpp
// Function: baobao::internal::indirect_sort_iter_warp<baobao::TestClass*>* baobao::internal::quick_sort_partition<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*>*, baobao::internal::indirect_sort_comp_warp<baobao::TestClass*, std::less<baobao::TestClass>>, bool&)
RandomAccessIterator quick_sort_partition(RandomAccessIterator beg, RandomAccessIterator end, Comp compare, bool& swaped)
{
    typedef typename std::iterator_traits<RandomAccessIterator>::difference_type diff_type;
    typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
    RandomAccessIterator l = beg, r = end - 1;
    uint32_t rnd = util::fake_rand_simple();
    diff_type n = end - beg, h = (n - 1) / 2;
    if (util::is_scalar<value_type>::value)
    {
        diff_type w = h;
        util::make_mid_pivot(*(beg + rnd % w), *r, *(beg + h + rnd % w), compare);
    }
    else
    {
        if (n < 1 << 14)
        {
            diff_type w = h;
            util::make_mid_pivot(*(beg + rnd % w), *r, *(beg + h + rnd % w), compare);
        }
        else
        {
            diff_type w = h - 3;
            util::make_mid_pivot(*(beg), *(r), *(beg + h + 1), compare);
            util::make_mid_pivot(*(beg + 1), *(beg + h - 1), *(r - 1), compare);
            util::make_mid_pivot(*(beg + 2 + rnd % w), *(beg + h), *(r - 2 - rnd % w), compare);
            util::make_mid_pivot(*(beg + h - 1), *(r), *(beg + h), compare);
        }
    }

    value_type pivot = *r;

    while (compare(*l, pivot))
        ++l;
    while (l < r && !compare(*r, pivot))
        --r;
    if (l < r)
    {
        std::swap(*l++, *r--);
        swaped = true;
        while (1)
        {
            while (compare(*l, pivot))
                ++l;
            while (!compare(*r, pivot))
                --r;
            if (l >= r)
                break;
            std::swap(*l++, *r--);
        }
    }
    std::swap(*l, *(end - 1));
    return l;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdx, 0xa8(%rsp)
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq %rdx, 0x110(%rsp)
movq %rcx, 0x108(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x118(%rsp), %rax
addq $-0x10, %rax
movq %rax, 0xf8(%rsp)
callq 0x23d0
movl %eax, 0xf4(%rsp)
movq 0x118(%rsp), %rax
movq 0x120(%rsp), %rcx
subq %rcx, %rax
sarq $0x4, %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, 0xe0(%rsp)
cmpq $0x4000, 0xe8(%rsp) # imm = 0x4000
jge 0x1407c
movq 0xa8(%rsp), %rsi
movq 0xe0(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x80(%rsp)
movl 0xf4(%rsp), %eax
cqto
idivq 0xd8(%rsp)
movq 0x80(%rsp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movq %rax, 0x90(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x88(%rsp)
movl 0xf4(%rsp), %eax
cqto
idivq 0xd8(%rsp)
movq 0x88(%rsp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movq %rax, 0xa0(%rsp)
leaq 0xd7(%rsp), %rdi
callq 0x13670
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0xd7(%rsp), %rcx
callq 0x14b10
jmp 0x142a0
movq 0xa8(%rsp), %rsi
movq 0xe0(%rsp), %rax
subq $0x3, %rax
movq %rax, 0xc8(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $0x10, %rax
movq %rax, 0x20(%rsp)
leaq 0xc7(%rsp), %rdi
callq 0x13670
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xc7(%rsp), %rcx
callq 0x14b10
movq 0xa8(%rsp), %rsi
movq 0x120(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x28(%rsp)
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $-0x10, %rax
movq %rax, 0x30(%rsp)
movq 0xf8(%rsp), %rax
addq $-0x10, %rax
movq %rax, 0x38(%rsp)
leaq 0xc6(%rsp), %rdi
callq 0x13670
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xc6(%rsp), %rcx
callq 0x14b10
movq 0xa8(%rsp), %rsi
movq 0x120(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x40(%rsp)
movl 0xf4(%rsp), %eax
cqto
idivq 0xc8(%rsp)
movq 0x40(%rsp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movq %rax, 0x50(%rsp)
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0xf8(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x48(%rsp)
movl 0xf4(%rsp), %eax
cqto
idivq 0xc8(%rsp)
movq 0x48(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x60(%rsp)
leaq 0xc5(%rsp), %rdi
callq 0x13670
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0xc5(%rsp), %rcx
callq 0x14b10
movq 0xa8(%rsp), %rsi
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $-0x10, %rax
movq %rax, 0x68(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x120(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
leaq 0xc4(%rsp), %rdi
callq 0x13670
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0xc4(%rsp), %rcx
callq 0x14b10
movq 0xf8(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0xb0(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xa8(%rsp), %rdi
movq 0x100(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x144a0
testb $0x1, %al
jne 0x142e2
jmp 0x142f8
movq 0x100(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x100(%rsp)
jmp 0x142bf
jmp 0x142fa
movq 0x100(%rsp), %rcx
xorl %eax, %eax
cmpq 0xf8(%rsp), %rcx
movb %al, 0xf(%rsp)
jae 0x14335
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x144a0
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x1433f
jmp 0x14355
movq 0xf8(%rsp), %rax
addq $-0x10, %rax
movq %rax, 0xf8(%rsp)
jmp 0x142fa
movq 0x100(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x1446f
movq 0x100(%rsp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x100(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, %rax
addq $-0x10, %rax
movq %rax, 0xf8(%rsp)
callq 0x14880
movq 0x108(%rsp), %rax
movb $0x1, (%rax)
jmp 0x143ab
movq 0xa8(%rsp), %rdi
movq 0x100(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x144a0
testb $0x1, %al
jne 0x143ce
jmp 0x143e4
movq 0x100(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x100(%rsp)
jmp 0x143ab
jmp 0x143e6
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x144a0
xorb $-0x1, %al
testb $0x1, %al
jne 0x1440b
jmp 0x14421
movq 0xf8(%rsp), %rax
addq $-0x10, %rax
movq %rax, 0xf8(%rsp)
jmp 0x143e6
movq 0x100(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jb 0x14435
jmp 0x1446d
movq 0x100(%rsp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x100(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, %rax
addq $-0x10, %rax
movq %rax, 0xf8(%rsp)
callq 0x14880
jmp 0x143a9
jmp 0x1446f
movq 0x100(%rsp), %rdi
movq 0x118(%rsp), %rsi
addq $-0x10, %rsi
callq 0x14880
movq 0x100(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax,%rax)