// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq %r8, 0x10(%rsp)
movq %rcx, (%rsp)
movq %rdx, 0x8(%rsp)
movq %rbp, %r14
subq %r15, %rbp
sarq $0x5, %rbp
movq %r13, %rax
subq %r14, %rax
sarq $0x5, %rax
cmpq %rax, %rbp
jg 0x6dc2
testq %rbp, %rbp
jle 0x6e3c
cmpq %rbx, %rbp
jbe 0x6dea
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a03
shlq $0x5, %rbp
addq %r14, %rbp
movq %r14, %r15
jmp 0x6d84
testq %rax, %rax
jle 0x6e3c
cmpq %rbx, %rax
jbe 0x6e5c
shlq $0x5, %rax
movq %r14, %rbp
subq %rax, %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6a03
movq %r14, %r13
jmp 0x6d84
movq %r12, %rbx
movq %r15, %rbp
cmpq %r14, %rbp
je 0x6e1d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4164
addq $0x20, %rbp
addq $0x20, %rbx
jmp 0x6df0
movq %r15, %rdi
movq %r14, %rsi
callq 0x4164
addq $0x20, %r14
addq $0x20, %r15
cmpq %r13, %r14
jb 0x6e0a
jmp 0x6e37
movq %r15, %rdi
movq %r12, %rsi
callq 0x4164
addq $0x20, %r15
addq $0x20, %r12
cmpq %rbx, %r12
jb 0x6e24
movq 0x10(%rsp), %rcx
subq (%rsp), %rcx
movq 0x8(%rsp), %rax
addq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rbx
movq %r14, %rbp
cmpq %r13, %rbp
je 0x6e7c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4164
addq $0x20, %rbp
addq $0x20, %rbx
jmp 0x6e62
addq $-0x20, %r13
addq $-0x20, %r14
addq $-0x20, %rbx
cmpq %r15, %r14
jb 0x6eb5
movq %r13, %rdi
movq %r14, %rsi
callq 0x4164
addq $-0x20, %r13
addq $-0x20, %r14
jmp 0x6e88
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4164
addq $-0x20, %r13
addq $-0x20, %rbx
cmpq %r12, %rbx
jae 0x6ea2
jmp 0x6e3c