// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r13
movq %rsi, %r12
movq %rdi, %rbx
leaq -0x10(%rsi), %r14
movl 0xe794(%rip), %r15d     # 0x17158
incl %r15d
movl %r15d, 0xe78a(%rip)     # 0x17158
movq %rsi, %rcx
subq %rdi, %rcx
sarq $0x4, %rcx
leaq -0x1(%rcx), %rax
pushq $0x2
popq %rsi
cqto
idivq %rsi
movq %rax, %rbp
cmpq $0x3fff, %rcx           # imm = 0x3FFF
jg 0x8a17
movl %r15d, %eax
xorl %edx, %edx
idivq %rbp
shlq $0x4, %rdx
leaq (%rdx,%rbx), %rdi
shlq $0x4, %rbp
addq %rdi, %rbp
leaq 0xf(%rsp), %rcx
movq %r14, %rsi
movq %rbp, %rdx
jmp 0x8aa5
leaq -0x3(%rbp), %rax
movq %rax, 0x28(%rsp)
shlq $0x4, %rbp
movq %r13, 0x30(%rsp)
leaq (%rbx,%rbp), %r13
leaq (%rbx,%rbp), %rdx
addq $0x10, %rdx
leaq 0xe(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8e84
leaq 0x10(%rbx), %rdi
addq %rbx, %rbp
addq $-0x10, %rbp
leaq -0x20(%r12), %rdx
leaq 0xd(%rsp), %rcx
movq %rbp, %rsi
callq 0x8e84
movl %r15d, %eax
xorl %edx, %edx
idivq 0x28(%rsp)
shlq $0x4, %rdx
leaq (%rbx,%rdx), %rdi
addq $0x20, %rdi
movq %r12, %rax
subq %rdx, %rax
addq $-0x30, %rax
leaq 0xc(%rsp), %rcx
movq %r13, %rsi
movq %rax, %rdx
callq 0x8e84
leaq 0xb(%rsp), %rcx
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq 0x30(%rsp), %r13
callq 0x8e84
movq -0x10(%r12), %rax
movq -0x8(%r12), %rcx
movl (%rcx), %esi
movq 0x8(%rbx), %rdx
movl (%rdx), %edx
cmpl %esi, %edx
jl 0x8ac7
jg 0x8acd
cmpq %rax, (%rbx)
jae 0x8acd
addq $0x10, %rbx
jmp 0x8ab6
movq %r14, %rdx
cmpq %rdx, %rbx
jae 0x8b50
movq 0x8(%rdx), %rdi
movl (%rdi), %edi
cmpl %esi, %edi
jl 0x8aec
jg 0x8ae6
cmpq %rax, (%rdx)
jb 0x8aec
addq $-0x10, %rdx
jmp 0x8ad0
movups (%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%rdx), %xmm0
movups %xmm0, (%rbx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rdx)
movb $0x1, (%r13)
movl (%rcx), %esi
addq $0x10, %rbx
movq 0x8(%rbx), %rdi
movl (%rdi), %edi
cmpl %esi, %edi
jl 0x8b09
jg 0x8b1e
cmpq %rax, (%rbx)
jb 0x8b09
addq $-0x10, %rdx
movq 0x8(%rdx), %rdi
movl (%rdi), %edi
cmpl %esi, %edi
jl 0x8b33
jg 0x8b1e
cmpq %rax, (%rdx)
jae 0x8b1e
cmpq %rdx, %rbx
jae 0x8b50
movups (%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%rdx), %xmm0
movups %xmm0, (%rbx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rdx)
jmp 0x8b07
movups (%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r14)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq