// File: 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:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq 0x50(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq $-0x20, %rdx
leaq 0x77(%rsp), %rdi
callq 0xcd80
testb $0x1, %al
jne 0xe67e
jmp 0xe8a1
jmp 0xe680
movq 0x58(%rsp), %rcx
xorl %eax, %eax
cmpq 0x50(%rsp), %rcx
movb %al, 0xd(%rsp)
jae 0xe6ac
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0x77(%rsp), %rdi
callq 0xcd80
xorb $-0x1, %al
movb %al, 0xd(%rsp)
movb 0xd(%rsp), %al
testb $0x1, %al
jne 0xe6b6
jmp 0xe6c6
movq 0x58(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x58(%rsp)
jmp 0xe680
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0xe75b
movq 0x50(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rcx
xorl %eax, %eax
cmpq 0x38(%rsp), %rcx
movb %al, 0xc(%rsp)
jae 0xe71e
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
leaq 0x77(%rsp), %rdi
callq 0xcd80
xorb $-0x1, %al
movb %al, 0xc(%rsp)
movb 0xc(%rsp), %al
testb $0x1, %al
jne 0xe728
jmp 0xe738
movq 0x38(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x38(%rsp)
jmp 0xe6f2
movq 0x40(%rsp), %rax
cmpq 0x38(%rsp), %rax
jae 0xe754
movq 0x38(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x48(%rsp)
jmp 0xe759
jmp 0xe8a1
jmp 0xe760
jmp 0xe8a1
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x20, %rax
jl 0xe7a5
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x3, %rax
jl 0xe7a5
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x3, %rax
jge 0xe7be
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0xd8b0
jmp 0xe8a1
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq 0x60(%rsp), %rax
jbe 0xe7ee
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq 0x60(%rsp), %rax
ja 0xe80c
movq 0x68(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0xd9b0
jmp 0xe8a1
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0xe8b0
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0xee30
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x20(%rsp), %rax
jae 0xe877
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0xe640
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0xe8a1
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x48(%rsp), %r8
callq 0xe640
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)