// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq %r8, 0x10(%rsp)
movq %rcx, (%rsp)
movq %rdx, 0x8(%rsp)
movq %rbp, %rbx
subq %r13, %rbp
sarq $0x5, %rbp
movq %r14, %rax
subq %rbx, %rax
sarq $0x5, %rax
cmpq %rax, %rbp
jg 0x82e3
testq %rbp, %rbp
jle 0x83b4
cmpq %r15, %rbp
jbe 0x830f
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7e32
shlq $0x5, %rbp
addq %rbx, %rbp
movq %rbx, %r13
jmp 0x82a5
testq %rax, %rax
jle 0x83b4
cmpq %r15, %rax
jbe 0x83d4
shlq $0x5, %rax
movq %rbx, %rbp
subq %rax, %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x7e32
movq %rbx, %r14
jmp 0x82a5
movq %r12, %rax
cmpq %rbx, %r13
je 0x8375
movq %r13, %rcx
movq %r12, %rax
movl (%rcx), %edx
movl %edx, (%rax)
movl 0x4(%rcx), %edx
movl %edx, 0x4(%rax)
movl $0x2, %edx
movl (%rcx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq $0x8, %rdx
jne 0x832c
addq $0x20, %rcx
addq $0x20, %rax
cmpq %rbx, %rcx
jne 0x831d
jmp 0x8375
movl (%rbx), %ecx
movl %ecx, (%r13)
movl 0x4(%rbx), %ecx
movl %ecx, 0x4(%r13)
movl $0x2, %ecx
movl (%rbx,%rcx,4), %edx
movl %edx, (%r13,%rcx,4)
incq %rcx
cmpq $0x8, %rcx
jne 0x835c
addq $0x20, %rbx
addq $0x20, %r13
cmpq %r14, %rbx
jb 0x834a
cmpq %r12, %rax
jbe 0x83b4
movl (%r12), %ecx
movl %ecx, (%r13)
movl 0x4(%r12), %ecx
movl %ecx, 0x4(%r13)
movl $0x2, %ecx
movl (%r12,%rcx,4), %edx
movl %edx, (%r13,%rcx,4)
incq %rcx
cmpq $0x8, %rcx
jne 0x8395
addq $0x20, %r13
addq $0x20, %r12
cmpq %rax, %r12
jb 0x837f
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, %rax
cmpq %r14, %rbx
je 0x840d
movq %rbx, %rcx
movq %r12, %rax
movl (%rcx), %edx
movl %edx, (%rax)
movl 0x4(%rcx), %edx
movl %edx, 0x4(%rax)
movl $0x2, %edx
movl (%rcx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq $0x8, %rdx
jne 0x83f1
addq $0x20, %rcx
addq $0x20, %rax
cmpq %r14, %rcx
jne 0x83e2
leaq -0x20(%r14), %rcx
leaq -0x20(%rbx), %rdx
cmpq %r13, %rdx
jb 0x844b
movl (%rdx), %esi
movl %esi, (%rcx)
movl -0x1c(%rbx), %esi
movl %esi, -0x1c(%r14)
movq $-0x18, %rsi
movl (%rbx,%rsi), %edi
movl %edi, (%r14,%rsi)
addq $0x4, %rsi
jne 0x842c
addq $-0x20, %rcx
addq $-0x20, %rdx
addq $-0x20, %r14
addq $-0x20, %rbx
jmp 0x8415
leaq -0x20(%rax), %rdx
cmpq %r12, %rdx
jb 0x83b4
movl (%rdx), %esi
movl %esi, (%rcx)
movl -0x1c(%rax), %esi
movl %esi, 0x4(%rcx)
movq $-0x6, %rsi
movl (%rax,%rsi,4), %edi
movl %edi, 0x20(%rcx,%rsi,4)
incq %rsi
jne 0x8469
addq $-0x20, %rcx
addq $-0x20, %rdx
addq $-0x20, %rax
jmp 0x844f