// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r12
movl -0x20(%r14), %eax
movl (%r14), %edx
cmpl %eax, %edx
jge 0x78fe
cmpq %r14, %rbp
jae 0x78fe
movq %rbx, %rcx
subq %rbp, %rcx
addq $0x20, %rcx
movq %rbp, %r15
cmpl (%r15), %edx
jl 0x773a
addq $0x20, %r15
addq $-0x20, %rcx
cmpq %r14, %r15
jb 0x7723
jmp 0x78fe
movq %rbx, %rdx
subq %r14, %rdx
addq $0x20, %rdx
movq %rbx, %rsi
cmpq %r14, %rsi
jbe 0x78fe
leaq -0x20(%rsi), %rbx
addq $-0x20, %rdx
addq $-0x20, %rcx
cmpl %eax, -0x20(%rsi)
movq %rbx, %rsi
jge 0x7747
cmpq $0x400, %rcx            # imm = 0x400
jl 0x7819
sarq $0x5, %rdx
cmpq $0x3, %rdx
jl 0x7819
movq %r14, %rax
subq %r15, %rax
sarq $0x5, %rax
cmpq $0x2, %rax
jle 0x7819
cmpq %r12, %rax
jbe 0x790d
cmpq %r12, %rdx
jbe 0x790d
addq $0x20, %rbx
movq %rdi, %rbp
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x792d
movq %rax, %r13
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
movq %r12, 0x8(%rsp)
movq %r12, %rsi
movq %rdx, %r12
movq %rax, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x7c64
movq %rax, %rbp
cmpq %r13, %r15
jae 0x77fe
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
movq %rbp, %r8
callq 0x76e4
movq %r12, %r14
cmpq %rbx, %r12
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r12
jb 0x76fe
jmp 0x78fe
leaq 0x20(%rsp), %rax
addq $0x20, %rbx
xorl %ecx, %ecx
movq %r14, %rdx
movl -0x20(%rdx), %r9d
movl (%rdx), %edi
cmpl %r9d, %edi
jge 0x78ee
leaq -0x20(%rdx), %rsi
movq %rcx, %r10
shlq $0x5, %r10
movl %edi, 0x18(%rsp)
movl 0x4(%rdx), %r8d
movl %r8d, 0x1c(%rsp)
movq 0x18(%r14,%r10), %r11
movq %r11, 0x10(%rax)
movups 0x8(%r14,%r10), %xmm0
movups %xmm0, (%rax)
movl %r9d, (%rdx)
movl -0x1c(%rdx), %r9d
movl %r9d, 0x4(%rdx)
movq $-0x18, %r9
movl (%rdx,%r9), %r10d
movl %r10d, 0x20(%rdx,%r9)
addq $0x4, %r9
jne 0x7872
cmpq %rsi, %r15
je 0x78d1
movq %rdx, %r8
movl 0x18(%rsp), %edi
movl -0x20(%rsi), %r10d
cmpl %r10d, %edi
jge 0x78cc
leaq -0x20(%rsi), %r9
movl %r10d, (%rsi)
movl -0x1c(%rsi), %edi
movl %edi, 0x4(%rsi)
movq $-0x18, %rsi
movl -0x20(%r8,%rsi), %edi
movl %edi, (%r8,%rsi)
addq $0x4, %rsi
jne 0x78aa
addq $-0x20, %r8
movq %r9, %rsi
cmpq %r9, %r15
jne 0x7889
movl 0x18(%rsp), %edi
movq %r9, %rsi
movl 0x1c(%rsp), %r8d
movl %edi, (%rsi)
movl %r8d, 0x4(%rsi)
movl $0x2, %edi
movl 0x18(%rsp,%rdi,4), %r8d
movl %r8d, (%rsi,%rdi,4)
incq %rdi
cmpq $0x8, %rdi
jne 0x78dc
addq $0x20, %rdx
incq %rcx
cmpq %rbx, %rdx
jb 0x7827
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x20, %rbx
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6f00