// File: /workspace/github_cpp_makefile_star2_O3/Baobaobear[P]sort/./sortlib.hpp
// Function: void baobao::internal::shell_sort<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
void shell_sort(RandomAccessIterator beg, RandomAccessIterator end, Comp compare)
{
    if (end - beg > shellsort_insertion_sort_threshold)
    {
        typedef typename std::iterator_traits<RandomAccessIterator>::difference_type diff_type;
        typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
        diff_type len = end - beg;
        diff_type incre_list[61] = { 0, 9, 34, 182, 836, 4025, 19001, 90358, 428481, 2034035, 9651787, 45806244, 217378076, 1031612713 };
        const double incre_factor = 2.9; // simple and fast enought

        if (!util::is_scalar<value_type>::value)
        {
            incre_list[1] = 10;
        }
        diff_type incre_index = 0;
        for (diff_type i = 1; i < 60; ++i)
        {
            diff_type mul = incre_list[i];
            if (mul * incre_factor >= len)
            {
                incre_index = i;
                break;
            }
            if (!util::is_scalar<value_type>::value || incre_list[i + 1] == 0)
            {
                incre_list[i + 1] = (diff_type)(mul * incre_factor);
            }
        }

        for (; incre_index > 0; --incre_index)
        {
            bool swaped = false;
            diff_type incre = incre_list[incre_index];
            for (diff_type i = incre; i < len; i++)
            {
                if (compare(*(beg + i), *(beg + i - incre)))
                {
                    value_type val = *(beg + i);
                    *(beg + i) = *(beg + i - incre);
                    diff_type pos = i - incre;
                    for (; pos >= incre && compare(val, *(beg + pos - incre)); pos -= incre)
                    {
                        *(beg + pos) = *(beg + pos - incre);
                    }
                    *(beg + pos) = val;
                    swaped = true;
                }
            }
            if (!swaped)
            {
                RandomAccessIterator last = insert_sort_limit(beg, end, compare, 1);
                if (last == end)
                {
                    return;
                }
                if (last - beg >= incre << 1)
                {
                    beg += ((last - beg) / incre - 1) * incre;
                    len = end - beg;
                }
            }
        }

        insert_sort(beg, beg + incre_list[1], compare);
        unguarded_insert_sort(beg + incre_list[1], end, compare);
    }
    else
    {
        insert_sort(beg, end, compare);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %r12
subq %rdi, %r12
sarq $0x5, %r12
cmpq $0x21, %r12
jl 0x68a6
leaq 0xdac6(%rip), %rsi      # 0x14310
leaq 0x40(%rsp), %r15
movl $0x1e8, %edx            # imm = 0x1E8
movq %r15, %rdi
callq 0x2150
cvtsi2sd %r12, %xmm0
movq $0xa, 0x8(%r15)
movl $0xa, %eax
movl $0x2, %r15d
movsd 0xd79c(%rip), %xmm1     # 0x14018
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jae 0x68c2
cvttsd2si %xmm2, %rax
movq %rax, 0x40(%rsp,%r15,8)
incq %r15
cmpq $0x3d, %r15
jne 0x687c
jmp 0x6aa4
movq %r14, %rdi
movq %rbx, %rsi
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x65b3
decq %r15
movq %rbx, 0x20(%rsp)
movq 0x40(%rsp,%r15,8), %r13
cmpq %r12, %r13
jge 0x6a49
movq %r13, %rax
negq %rax
leaq 0x8(%r14), %rdi
movq %r13, %rdx
shlq $0x5, %rdx
movq %r14, %r10
subq %rdx, %r10
negq %rdx
movq %r13, %rcx
shlq $0x6, %rcx
movq %r14, %r11
subq %rcx, %r11
xorl %ebp, %ebp
shlq $0x5, %rax
movq %r13, %r8
movq %r10, 0x30(%rsp)
movq %r11, 0x28(%rsp)
movq %r8, %r9
shlq $0x5, %r9
leaq (%rdi,%r9), %rsi
addq %r9, %r10
addq %r11, %r9
movq %r8, %r11
shlq $0x5, %r11
leaq (%r14,%r11), %rcx
movl (%r14,%r11), %r11d
cmpl (%rax,%rcx), %r11d
jl 0x6951
incq %r8
addq $0x20, %rsi
addq $0x20, %r10
addq $0x20, %r9
cmpq %r12, %r8
jne 0x6923
jmp 0x6a43
movq %rdi, 0x38(%rsp)
leaq (%rcx,%rax), %rbp
movl %r11d, (%rsp)
movl 0x4(%rcx), %r11d
movl %r11d, 0x4(%rsp)
movl $0x2, %ebx
movq %rsi, %r11
movl (%r11), %edi
movl %edi, (%rsp,%rbx,4)
incq %rbx
addq $0x4, %r11
cmpq $0x8, %rbx
jne 0x696f
movl (%rbp), %edi
movl %edi, (%rcx)
movl 0x4(%rbp), %edi
movl %edi, 0x4(%rcx)
leaq (%rsi,%rdx), %rcx
xorl %r11d, %r11d
movl (%rcx,%r11,4), %edi
movl %edi, (%rsi,%r11,4)
incq %r11
cmpq $0x6, %r11
jne 0x6994
movq %r8, %r11
subq %r13, %r11
cmpq %r13, %r11
movq 0x20(%rsp), %rbx
jl 0x69f7
movq %r11, %rcx
shlq $0x5, %rcx
addq %r14, %rcx
movl (%rax,%rcx), %esi
cmpl %esi, (%rsp)
jge 0x69f7
leaq (%rcx,%rax), %rdi
movl %esi, (%rcx)
movl 0x4(%rdi), %esi
movl %esi, 0x4(%rcx)
movl $0x2, %ecx
movl (%r9,%rcx,4), %esi
movl %esi, (%r10,%rcx,4)
incq %rcx
cmpq $0x8, %rcx
jne 0x69d8
subq %r13, %r11
addq %rdx, %r10
addq %rdx, %r9
cmpq %r13, %r11
jge 0x69b5
shlq $0x5, %r11
leaq (%r14,%r11), %rcx
movl (%rsp), %esi
movl %esi, (%r14,%r11)
movl 0x4(%rsp), %esi
movl %esi, 0x4(%r14,%r11)
movl $0x2, %esi
movl (%rsp,%rsi,4), %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
cmpq $0x8, %rsi
jne 0x6a14
incq %r8
movb $0x1, %bpl
cmpq %r12, %r8
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %r10
movq 0x28(%rsp), %r11
jne 0x6912
jmp 0x6a93
testb $0x1, %bpl
jne 0x6a93
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x6bb2
cmpq %rbx, %rax
je 0x6ba0
subq %r14, %rax
sarq $0x5, %rax
leaq (,%r13,2), %rcx
cmpq %rcx, %rax
jl 0x6a93
cqto
idivq %r13
decq %rax
imulq %r13, %rax
shlq $0x5, %rax
addq %rax, %r14
movq %rbx, %r12
subq %r14, %r12
sarq $0x5, %r12
leaq -0x1(%r15), %rax
cmpq $0x1, %r15
movq %rax, %r15
jg 0x68ca
movq 0x48(%rsp), %r15
shlq $0x5, %r15
addq %r14, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x65b3
cmpq %rbx, %r15
jae 0x6ba0
leaq 0x8(%rsp), %rax
xorl %ecx, %ecx
movq %r15, %rdx
movl -0x20(%rdx), %r9d
movl (%rdx), %edi
cmpl %r9d, %edi
jge 0x6b90
leaq -0x20(%rdx), %rsi
movq %rcx, %r10
shlq $0x5, %r10
movl %edi, (%rsp)
movl 0x4(%rdx), %r8d
movl %r8d, 0x4(%rsp)
movq 0x18(%r15,%r10), %r11
movq %r11, 0x10(%rax)
movupd 0x8(%r15,%r10), %xmm0
movupd %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 0x6b1a
movl -0x40(%rdx), %r10d
cmpl %r10d, %edi
jge 0x6b74
leaq -0x40(%rdx), %r9
movq %rdx, %r8
movl %r10d, (%rsi)
movl -0x1c(%rsi), %edi
movl %edi, 0x4(%rsi)
movq %r9, %rsi
movq $-0x18, %rdi
movl -0x20(%r8,%rdi), %r9d
movl %r9d, (%r8,%rdi)
addq $0x4, %rdi
jne 0x6b4c
leaq -0x20(%rsi), %r9
movl (%rsp), %edi
movl -0x20(%rsi), %r10d
addq $-0x20, %r8
cmpl %r10d, %edi
jl 0x6b39
movl 0x4(%rsp), %r8d
movl %edi, (%rsi)
movl %r8d, 0x4(%rsi)
movl $0x2, %edi
movl (%rsp,%rdi,4), %r8d
movl %r8d, (%rsi,%rdi,4)
incq %rdi
cmpq $0x8, %rdi
jne 0x6b7f
addq $0x20, %rdx
incq %rcx
cmpq %rbx, %rdx
jb 0x6ace
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq