// File: /workspace/github_cpp_makefile_star2_O2/Baobaobear[P]sort/./sortlib.hpp
// Function: void baobao::internal::merge_2_part_with_buffer<false, baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, unsigned long, baobao::TestClass*, baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
void merge_2_part_with_buffer(RandomAccessBufferIterator buf, size_t bufsize, RandomAccessIterator beg, RandomAccessIterator mid, RandomAccessIterator end, Comp compare)
{
    if (!compare(*mid, *(mid - 1)))
    {
        return;
    }
    while (beg < mid && !compare(*mid, *beg))
    {
        ++beg;
    }
    if (beg < mid)
    {
        RandomAccessIterator mid_last = mid - 1, last = end - 1;
        while (mid_last < last && !compare(*last, *mid_last))
        {
            --last;
        }
        if (mid_last < last)
        {
            end = last + 1;
        }
        else
        {
            return;
        }
    }
    else
    {
        return;
    }

    if (end - beg < merge_2_part_insertion_sort_threshold || end - mid < 3 || mid - beg < 3)
    {
        insert_sort_part(beg, mid, end, compare);
        return;
    }

    if ((size_t)(end - mid) <= bufsize || (size_t)(mid - beg) <= bufsize)
    {
        merge_2_part_force<safecopy>(buf, beg, mid, end, compare);
        return;
    }

    std::pair<RandomAccessIterator, RandomAccessIterator> pair = find_swap_bound(beg, mid, end, compare);

    RandomAccessIterator swap_mid = swap_2_part_with_buffer<safecopy>(buf, bufsize, pair.first, mid, pair.second);
    if (beg < pair.first)
        merge_2_part_with_buffer<safecopy>(buf, bufsize, beg, pair.first, swap_mid, compare);
    if (pair.second < end)
        merge_2_part_with_buffer<safecopy>(buf, bufsize, swap_mid, pair.second, end, compare);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r14
movl -0x20(%r12), %eax
movl (%r12), %edx
cmpl %eax, %edx
jge 0x6618
movq %rbx, %rcx
subq %rbp, %rcx
addq $0x20, %rcx
movq %rbp, %r13
cmpq %r12, %r13
jae 0x6618
cmpl (%r13), %edx
jl 0x653e
addq $0x20, %r13
addq $-0x20, %rcx
jmp 0x6525
movq %rbx, %rdx
subq %r12, %rdx
addq $0x20, %rdx
movq %rbx, %rsi
cmpq %r12, %rsi
jbe 0x6618
leaq -0x20(%rsi), %rbx
addq $-0x20, %rdx
addq $-0x20, %rcx
cmpl %eax, -0x20(%rsi)
movq %rbx, %rsi
jge 0x654b
cmpq $0x400, %rcx            # imm = 0x400
jl 0x6627
sarq $0x5, %rdx
cmpq $0x3, %rdx
jl 0x6627
movq %r12, %rax
subq %r13, %rax
sarq $0x5, %rax
cmpq $0x2, %rax
jle 0x6627
cmpq %r14, %rax
jbe 0x6647
cmpq %r14, %rdx
jbe 0x6647
addq $0x20, %rbx
movq %rdi, %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x6667
movq %rax, %r15
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
movq %rdx, %r14
movq %rax, %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x686a
movq %rax, %rbp
cmpq %r15, %r13
jae 0x6602
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
callq 0x64ed
movq %r14, %r12
cmpq %rbx, %r14
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r14
jb 0x6507
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x20, %rbx
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5e3b
addq $0x20, %rbx
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5ec8