// File: /workspace/github_cpp_makefile_star2_O3/Baobaobear[P]sort/./sortlib.hpp
// Function: std::pair<baobao::TestClass*, baobao::TestClass*> baobao::internal::find_swap_bound<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
std::pair<RandomAccessIterator, RandomAccessIterator> find_swap_bound(RandomAccessIterator beg, RandomAccessIterator mid, RandomAccessIterator end, Comp compare)
{
    if (end - beg < find_swap_bound_optimize_threshold)
    {
        RandomAccessIterator pivot_r = mid + (end - mid) / 2 + 1;
        RandomAccessIterator pivot_l = std::upper_bound(beg, mid, *pivot_r, compare);

        pivot_r = std::lower_bound(pivot_r, end, *pivot_l, compare);

        return std::make_pair(pivot_l, pivot_r);
    }
    else
    {
        typedef typename std::iterator_traits<RandomAccessIterator>::difference_type diff_type;

        RandomAccessIterator pivot_l = beg;
        RandomAccessIterator pivot_l_map = std::lower_bound(mid, end, *pivot_l, compare);

        if (pivot_l_map - mid > (end - mid) / 2 || mid - pivot_l <= pivot_l_map - mid)
        {
            return std::make_pair(pivot_l, pivot_l_map);
        }

        RandomAccessIterator pivot_r = std::lower_bound(beg, mid, *(end - 1), compare);
        RandomAccessIterator pivot_r_map = std::lower_bound(mid, end, *pivot_r, compare);

        if (mid - pivot_r > (mid - beg) / 2 || mid - pivot_r >= pivot_r_map - mid)
        {
            return std::make_pair(pivot_r, pivot_r_map);
        }

        do
        {
            RandomAccessIterator pivot_m = pivot_l + (pivot_r - pivot_l) / 2;
            pivot_m = std::lower_bound(pivot_l, pivot_r, *pivot_m, compare);
            if (pivot_m == pivot_l)
            {
                pivot_m = std::upper_bound(pivot_l, pivot_r, *pivot_m, compare);
                if (pivot_m == pivot_r)
                {
                    {
                        diff_type pivot_m_diff = (mid - pivot_l) - (pivot_l_map - mid);
                        if (pivot_l + pivot_m_diff <= pivot_r)
                        {
                            return std::make_pair(pivot_l + pivot_m_diff, pivot_l_map);
                        }
                    }
                    {
                        diff_type pivot_m_diff = (mid - pivot_r) - (pivot_r_map - mid);
                        if (pivot_l_map - pivot_m_diff <= pivot_r_map)
                        {
                            return std::make_pair(pivot_r, pivot_r_map + pivot_m_diff);
                        }
                    }
                    return std::make_pair(pivot_l, pivot_l_map);
                }
            }
            RandomAccessIterator pivot_m_map = std::lower_bound(pivot_l_map, pivot_r_map, *pivot_m, compare);
            diff_type pivot_m_diff = (mid - pivot_m) - (pivot_m_map - mid);
            if (pivot_m_diff > 0)
            {
                pivot_l = pivot_m;
                pivot_l_map = pivot_m_map;
            }
            else if (pivot_m_diff < 0)
            {
                pivot_r = pivot_m;
                pivot_r_map = pivot_m_map;
            }
            else
            {
                return std::make_pair(pivot_m, pivot_m_map);
            }
        } while (true);

        return std::make_pair(pivot_l, pivot_l_map);
    }
}

// Assembly:
pushq %r14
pushq %rbx
movq %rdx, %rax
movq %rdx, %rcx
subq %rdi, %rcx
subq %rsi, %rdx
sarq $0x5, %rdx
cmpq $0x1fff, %rcx           # imm = 0x1FFF
jg 0x79db
movq %rdx, %rcx
shrq $0x3f, %rcx
addq %rdx, %rcx
shlq $0x4, %rcx
andq $-0x20, %rcx
leaq (%rsi,%rcx), %rdx
addq $0x20, %rdx
subq %rdi, %rsi
sarq $0x5, %rsi
testq %rsi, %rsi
jle 0x799d
movl (%rdx), %ecx
movq %rsi, %r8
shrq %r8
movq %r8, %r9
shlq $0x5, %r9
cmpl (%rdi,%r9), %ecx
jl 0x7995
notq %r8
addq %rsi, %r8
addq %r9, %rdi
addq $0x20, %rdi
movq %r8, %rsi
testq %r8, %r8
jg 0x7978
subq %rdx, %rax
sarq $0x5, %rax
testq %rax, %rax
jle 0x79d3
movl (%rdi), %ecx
movq %rax, %rsi
shrq %rsi
movq %rsi, %r8
shlq $0x5, %r8
cmpl %ecx, (%rdx,%r8)
jge 0x79cb
notq %rsi
addq %rax, %rsi
addq %r8, %rdx
addq $0x20, %rdx
movq %rsi, %rax
testq %rsi, %rsi
jg 0x79ae
movq %rdi, %rax
jmp 0x7abf
testq %rdx, %rdx
jle 0x7a16
movl (%rdi), %r8d
movq %rsi, %rcx
movq %rdx, %r10
movq %rdx, %r9
shrq %r9
movq %r9, %r11
shlq $0x5, %r11
cmpl %r8d, (%rcx,%r11)
jge 0x7a09
notq %r9
addq %r10, %r9
addq %r11, %rcx
addq $0x20, %rcx
movq %r9, %r10
testq %r9, %r9
jg 0x79ec
movq %rcx, %r8
jmp 0x7a1c
movq %rsi, %r8
movq %rsi, %rcx
subq %rsi, %r8
sarq $0x5, %r8
movq %rdx, %r9
shrq $0x3f, %r9
addq %rdx, %r9
sarq %r9
cmpq %r9, %r8
jg 0x7ab9
movq %rsi, %r10
subq %rdi, %r10
sarq $0x5, %r10
cmpq %r8, %r10
jle 0x7ab9
movq %rdi, %r8
testq %r10, %r10
jle 0x7a81
movl -0x20(%rax), %eax
movq %rdi, %r8
movq %r10, %r11
movq %r10, %r9
shrq %r9
movq %r9, %rbx
shlq $0x5, %rbx
cmpl %eax, (%r8,%rbx)
jge 0x7a79
notq %r9
addq %r11, %r9
addq %rbx, %r8
addq $0x20, %r8
movq %r9, %r11
testq %r9, %r9
jg 0x7a5c
testq %rdx, %rdx
jle 0x7ac3
movl (%r8), %eax
movq %rsi, %r9
movq %rdx, %r11
shrq %r11
movq %r11, %rbx
shlq $0x5, %rbx
cmpl %eax, (%r9,%rbx)
jge 0x7aac
notq %r11
addq %rdx, %r11
addq %rbx, %r9
addq $0x20, %r9
movq %r11, %rdx
testq %r11, %r11
jg 0x7a8f
movq %r9, %rax
jmp 0x7ac9
movq %rdi, %rax
movq %rcx, %rdx
popq %rbx
popq %r14
retq
movq %rsi, %rax
movq %rsi, %r9
movq %rsi, %rdx
subq %r8, %rdx
movq %rdx, %r11
sarq $0x5, %r11
movq %r10, %rbx
shrq $0x3f, %rbx
addq %r10, %rbx
sarq %rbx
cmpq %rbx, %r11
jg 0x7bfb
subq %rsi, %rax
cmpq %rax, %rdx
jge 0x7bfb
movq %rcx, %rdx
movq %rdi, %rax
movq %rax, %rdi
movq %rdx, %rcx
movq %r8, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
testq %rdx, %rdx
jle 0x7b83
movq %rdx, %rax
shlq $0x4, %rax
andq $-0x20, %rax
movl (%rdi,%rax), %r10d
movq %rdi, %rax
movq %rdx, %rbx
movq %rdx, %r11
shrq %r11
movq %r11, %r14
shlq $0x5, %r14
cmpl %r10d, (%rax,%r14)
jge 0x7b48
notq %r11
addq %rbx, %r11
addq %r14, %rax
addq $0x20, %rax
movq %r11, %rbx
testq %r11, %r11
jg 0x7b2b
cmpq %rdi, %rax
jne 0x7b88
movl (%rax), %r10d
movq %rdi, %rax
movq %rdx, %r11
shrq %r11
movq %r11, %rbx
shlq $0x5, %rbx
cmpl (%rax,%rbx), %r10d
jl 0x7b7b
notq %r11
addq %rdx, %r11
addq %rbx, %rax
addq $0x20, %rax
movq %r11, %rdx
testq %r11, %r11
jg 0x7b5e
cmpq %r8, %rax
je 0x7c06
movq %r9, %rbx
subq %rcx, %rbx
sarq $0x5, %rbx
testq %rbx, %rbx
jle 0x7bca
movl (%rax), %r10d
movq %rcx, %rdx
movq %rbx, %r11
shrq %r11
movq %r11, %r14
shlq $0x5, %r14
cmpl %r10d, (%rdx,%r14)
jge 0x7bbd
notq %r11
addq %rbx, %r11
addq %r14, %rdx
addq $0x20, %rdx
movq %r11, %rbx
testq %r11, %r11
jg 0x7ba0
movq %rdx, %r10
jmp 0x7bd0
movq %rcx, %r10
movq %rcx, %rdx
movq %rsi, %r11
subq %rax, %r11
sarq $0x5, %r11
subq %rsi, %r10
sarq $0x5, %r10
subq %r10, %r11
jg 0x7afe
movq %rax, %r8
movq %rdx, %r9
js 0x7af8
jmp 0x7abf
movq %r8, %rax
movq %r9, %rdx
jmp 0x7abf
movq %rsi, %rax
subq %rdi, %rax
shrq $0x5, %rax
movq %rcx, %rdx
subq %rsi, %rdx
shrq $0x5, %rdx
subq %rdx, %rax
shlq $0x5, %rax
addq %rdi, %rax
cmpq %r8, %rax
jbe 0x7abc
movq %r9, %rax
subq %rsi, %rax
subq %r8, %rsi
shrq $0x5, %rsi
shrq $0x5, %rax
subq %rax, %rsi
shlq $0x5, %rsi
movq %rcx, %rax
subq %rsi, %rax
addq %r9, %rsi
cmpq %r9, %rax
cmovbeq %r8, %rdi
cmovaq %rcx, %rsi
movq %rdi, %rax
movq %rsi, %rdx
jmp 0x7abf