// File: Baobaobear[P]sort/./sortlib.hpp
// Function: baobao::TestClass* baobao::internal::swap_2_part_with_buffer<true, baobao::TestClass*, baobao::TestClass*>(baobao::TestClass*, unsigned long, baobao::TestClass*, baobao::TestClass*, baobao::TestClass*)
RandomAccessIterator swap_2_part_with_buffer(RandomAccessBufferIterator buf, size_t bufsize, RandomAccessIterator beg, RandomAccessIterator mid, RandomAccessIterator end)
{
    RandomAccessIterator ret = beg + (end - mid);
    while (true)
    {
        if (mid - beg <= end - mid)
        {
            if (mid - beg > 0)
            {
                if ((size_t)(mid - beg) > bufsize)
                {
                    swap_2_part_with_same_length(beg, mid);
                    RandomAccessIterator m = mid;
                    mid += mid - beg;
                    beg = m;
                }
                else
                {
                    if (safecopy)
                    {
                        RandomAccessBufferIterator t = buf;
                        for (RandomAccessIterator s = beg; s != mid; ++s, ++t)
                        {
                            *t = *s;
                        }
                        RandomAccessIterator m = beg;
                        for (RandomAccessIterator s = mid; s < end; ++s, ++m)
                        {
                            *m = *s;
                        }
                        for (RandomAccessBufferIterator it = buf; it < t; ++m, ++it)
                        {
                            *m = *it;
                        }
                    }
                    else
                    {
                        memcpy((char*)buf, (char*)&*beg, (char*)&*mid - (char*)&*beg);
                        memmove((char*)&*beg, (char*)&*mid, (char*)&*end - (char*)&*mid);
                        memcpy((char*)&*(beg + (end - mid)), (char*)buf, (char*)&*mid - (char*)&*beg);
                    }
                    return ret;
                }
            }
            else
                return ret;
        }
        else
        {
            if (end - mid > 0)
            {
                if ((size_t)(end - mid) > bufsize)
                {
                    swap_2_part_with_same_length(mid - (end - mid), mid);
                    RandomAccessIterator m = mid;
                    mid -= end - mid;
                    end = m;
                }
                else
                {
                    if (safecopy)
                    {
                        RandomAccessBufferIterator t = buf;
                        for (RandomAccessIterator s = mid; s != end; ++s, ++t)
                        {
                            *t = *s;
                        }
                        RandomAccessIterator m = end - 1;
                        for (RandomAccessIterator s = mid - 1; s >= beg; --s, --m)
                        {
                            *m = *s;
                        }
                        for (--t; t >= buf; --m, --t)
                        {
                            *m = *t;
                        }
                    }
                    else
                    {
                        memcpy((char*)buf, (char*)&*mid, (char*)&*end - (char*)&*mid);
                        memmove((char*)&*(end - (mid - beg)), (char*)&*beg, (char*)&*mid - (char*)&*beg);
                        memcpy((char*)&*beg, (char*)buf, (char*)&*end - (char*)&*mid);
                    }
                    return ret;
                }
            }
            else
                return ret;
        }
    }
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
subq %rdx, %rcx
sarq $0x5, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x60(%rsp)
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
subq %rdx, %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jg 0xfbfe
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
jle 0xfbe7
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq 0x80(%rsp), %rax
jbe 0xfaf0
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0xf3f0
movq 0x70(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
shlq $0x5, %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
jmp 0xfbe5
movq 0x88(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x70(%rsp), %rax
je 0xfb40
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x8710
movq 0x48(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x50(%rsp)
jmp 0xfb07
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0xfb8d
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x8710
movq 0x38(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x40(%rsp)
jmp 0xfb54
movq 0x88(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0xfbd3
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x8710
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x40(%rsp)
movq 0x30(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x30(%rsp)
jmp 0xfb9a
movq 0x60(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0xfdb6
jmp 0xfbf9
movq 0x60(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0xfdb6
jmp 0xfdb1
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
jle 0xfda0
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq 0x80(%rsp), %rax
jbe 0xfca0
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rax
subq %rax, %rcx
sarq $0x5, %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x5, %rax
addq %rax, %rdi
movq 0x70(%rsp), %rsi
callq 0xf3f0
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rax
subq %rax, %rdx
sarq $0x5, %rdx
movq 0x70(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
jmp 0xfd9e
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x68(%rsp), %rax
je 0xfcf0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x8710
movq 0x18(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
jmp 0xfcb7
movq 0x68(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x10(%rsp)
movq 0x70(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x78(%rsp), %rax
jb 0xfd45
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x8710
movq 0x8(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x10(%rsp)
jmp 0xfd0c
movq 0x20(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x88(%rsp), %rax
jb 0xfd8f
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x8710
movq 0x10(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x20(%rsp)
jmp 0xfd53
movq 0x60(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0xfdb6
jmp 0xfdaf
movq 0x60(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0xfdb6
jmp 0xfdb1
jmp 0xfa48
movq 0x90(%rsp), %rax
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)