// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rax
movq %rdx, %rcx
subq %rdi, %rcx
subq %rsi, %rdx
sarq $0x5, %rdx
cmpq $0x1fff, %rcx           # imm = 0x1FFF
jg 0x7a6d
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 0x7a2f
movl (%rdx), %ecx
movq %rsi, %r8
shrq %r8
movq %r8, %r9
shlq $0x5, %r9
cmpl (%rdi,%r9), %ecx
jl 0x7a27
notq %r8
addq %rsi, %r8
addq %r9, %rdi
addq $0x20, %rdi
movq %r8, %rsi
testq %r8, %r8
jg 0x7a0a
subq %rdx, %rax
sarq $0x5, %rax
testq %rax, %rax
jle 0x7a65
movl (%rdi), %ecx
movq %rax, %rsi
shrq %rsi
movq %rsi, %r8
shlq $0x5, %r8
cmpl %ecx, (%rdx,%r8)
jge 0x7a5d
notq %rsi
addq %rax, %rsi
addq %r8, %rdx
addq $0x20, %rdx
movq %rsi, %rax
testq %rsi, %rsi
jg 0x7a40
movq %rdi, %rax
jmp 0x7cf5
movq %rsi, %rcx
testq %rdx, %rdx
jle 0x7aa6
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 0x7a9e
notq %r9
addq %r10, %r9
addq %r11, %rcx
addq $0x20, %rcx
movq %r9, %r10
testq %r9, %r9
jg 0x7a81
movq %rcx, %r8
subq %rsi, %r8
sarq $0x5, %r8
movq %rdx, %r9
shrq $0x3f, %r9
addq %rdx, %r9
sarq %r9
cmpq %r9, %r8
jg 0x7cef
movq %rsi, %r10
subq %rdi, %r10
sarq $0x5, %r10
cmpq %r8, %r10
jle 0x7cef
movq %rdi, %r8
testq %r10, %r10
jle 0x7b12
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 0x7b0a
notq %r9
addq %r11, %r9
addq %rbx, %r8
addq $0x20, %r8
movq %r9, %r11
testq %r9, %r9
jg 0x7aed
movq %rsi, %r9
testq %rdx, %rdx
jle 0x7b48
movl (%r8), %eax
movq %rsi, %r9
movq %rdx, %r11
shrq %r11
movq %r11, %rbx
shlq $0x5, %rbx
cmpl %eax, (%r9,%rbx)
jge 0x7b40
notq %r11
addq %rdx, %r11
addq %rbx, %r9
addq $0x20, %r9
movq %r11, %rdx
testq %r11, %r11
jg 0x7b23
movq %rsi, %rax
subq %r8, %rax
movq %rax, %rdx
sarq $0x5, %rdx
movq %r10, %r11
shrq $0x3f, %r11
addq %r10, %r11
sarq %r11
cmpq %r11, %rdx
jg 0x7cfd
movq %r9, %rdx
subq %rsi, %rdx
cmpq %rdx, %rax
jge 0x7cfd
movq %r8, %r11
subq %rdi, %r11
sarq $0x5, %r11
movq %rdi, %rax
testq %r11, %r11
jle 0x7bc8
movq %r11, %rax
shlq $0x4, %rax
andq $-0x20, %rax
movl (%rdi,%rax), %ebx
movq %rdi, %rax
movq %r11, %r15
movq %r11, %r14
shrq %r14
movq %r14, %r12
shlq $0x5, %r12
cmpl %ebx, (%rax,%r12)
jge 0x7bc0
notq %r14
addq %r15, %r14
addq %r12, %rax
addq $0x20, %rax
movq %r14, %r15
testq %r14, %r14
jg 0x7ba3
cmpq %rdi, %rax
jne 0x7c0a
movq %rdi, %rbx
testq %r11, %r11
jle 0x7c02
movl (%rax), %eax
movq %rdi, %rbx
movq %r11, %r14
shrq %r14
movq %r14, %r15
shlq $0x5, %r15
cmpl (%rbx,%r15), %eax
jl 0x7bfa
notq %r14
addq %r11, %r14
addq %r15, %rbx
addq $0x20, %rbx
movq %r14, %r11
testq %r14, %r14
jg 0x7bdd
movq %rbx, %rax
cmpq %r8, %rbx
je 0x7c78
movq %r9, %r15
subq %rcx, %r15
sarq $0x5, %r15
movq %rcx, %r11
testq %r15, %r15
jle 0x7c49
movl (%rax), %ebx
movq %rcx, %r11
movq %r15, %r14
shrq %r14
movq %r14, %r12
shlq $0x5, %r12
cmpl %ebx, (%r11,%r12)
jge 0x7c41
notq %r14
addq %r15, %r14
addq %r12, %r11
addq $0x20, %r11
movq %r14, %r15
testq %r14, %r14
jg 0x7c24
movq %rsi, %r14
subq %rax, %r14
sarq $0x5, %r14
movq %r11, %r15
subq %rsi, %r15
sarq $0x5, %r15
movb $0x1, %bl
subq %r15, %r14
jle 0x7c6f
movq %r11, %rcx
movq %rax, %rdi
movq %r10, %rax
jmp 0x7cd7
js 0x7ce4
xorl %ebx, %ebx
movq %r11, %rdx
jmp 0x7cd7
movq %rsi, %rax
subq %rdi, %rax
shrq $0x5, %rax
movq %rcx, %r11
subq %rsi, %r11
shrq $0x5, %r11
subq %r11, %rax
shlq $0x5, %rax
addq %rdi, %rax
cmpq %r8, %rax
cmovaq %r10, %rax
cmovbeq %rcx, %rdx
jbe 0x7cd5
movq %rsi, %rdx
subq %r8, %rdx
shrq $0x5, %rdx
movq %r9, %rax
subq %rsi, %rax
shrq $0x5, %rax
subq %rax, %rdx
shlq $0x5, %rdx
movq %rcx, %rax
subq %rdx, %rax
addq %r9, %rdx
cmpq %r9, %rax
movq %r8, %rax
cmovaq %rdi, %rax
cmovaq %rcx, %rdx
xorl %ebx, %ebx
movq %rax, %r10
testb %bl, %bl
jne 0x7b7a
jmp 0x7cf5
movq %rax, %r8
movq %r11, %r9
jmp 0x7c6a
movq %rdi, %rax
movq %rcx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %r8, %rax
movq %r9, %rdx
jmp 0x7cf5