// File: /workspace/github_cpp_makefile_star2_O1/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 $0x208, %rsp            # imm = 0x208
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %r12
subq %rdi, %r12
sarq $0x5, %r12
cmpq $0x21, %r12
jl 0x6c36
leaq 0xda15(%rip), %rsi      # 0x14320
leaq 0x20(%rsp), %r15
movl $0x1e8, %edx            # imm = 0x1E8
movq %r15, %rdi
callq 0x2160
cvtsi2sd %r12, %xmm0
movq $0xa, 0x8(%r15)
movl $0x2, %eax
xorl %r15d, %r15d
movsd 0xd6de(%rip), %xmm1     # 0x14018
xorps %xmm2, %xmm2
cvtsi2sdq 0x18(%rsp,%rax,8), %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jb 0x6954
leaq -0x1(%rax), %r15
jmp 0x695e
cvttsd2si %xmm2, %rcx
movq %rcx, 0x20(%rsp,%rax,8)
ucomisd %xmm0, %xmm2
jae 0x6971
leaq 0x1(%rax), %rcx
cmpq $0x3c, %rax
movq %rcx, %rax
jne 0x693a
testq %r15, %r15
jle 0x6b1b
movq 0x20(%rsp,%r15,8), %r13
cmpq %r12, %r13
jge 0x6ab9
movq %r13, %rax
negq %rax
movq %r13, %rcx
shlq $0x5, %rcx
leaq (%r14,%rcx), %rdx
negq %rcx
xorl %r8d, %r8d
shlq $0x5, %rax
movq %r14, %rsi
movq %r13, %rdi
movq %rdi, %r10
shlq $0x5, %r10
leaq (%r14,%r10), %r9
movl (%r14,%r10), %r10d
cmpl (%rax,%r9), %r10d
jge 0x6a9d
leaq (%r9,%rax), %r8
movl (%r9), %r10d
movl %r10d, (%rsp)
movl 0x4(%r9), %r10d
movl %r10d, 0x4(%rsp)
movl $0x2, %r10d
movl (%rdx,%r10,4), %r11d
movl %r11d, (%rsp,%r10,4)
incq %r10
cmpq $0x8, %r10
jne 0x69dc
movl (%r8), %r10d
movl %r10d, (%r9)
movl 0x4(%r8), %r8d
movl %r8d, 0x4(%r9)
movl $0x2, %r8d
movl (%rsi,%r8,4), %r9d
movl %r9d, (%rdx,%r8,4)
incq %r8
cmpq $0x8, %r8
jne 0x6a01
movq %rdi, %r8
subq %r13, %r8
cmpq %r13, %r8
jl 0x6a69
movq %rsi, %r9
movq %r8, %r10
shlq $0x5, %r10
addq %r14, %r10
movl (%rax,%r10), %r11d
cmpl %r11d, (%rsp)
jge 0x6a69
leaq (%r10,%rax), %rbp
movl %r11d, (%r10)
movl 0x4(%rbp), %r11d
movl %r11d, 0x4(%r10)
leaq (%r9,%rcx), %r10
movl $0x2, %r11d
movl (%r10,%r11,4), %ebp
movl %ebp, (%r9,%r11,4)
incq %r11
cmpq $0x8, %r11
jne 0x6a4d
subq %r13, %r8
movq %r10, %r9
cmpq %r13, %r8
jge 0x6a20
shlq $0x5, %r8
leaq (%r14,%r8), %r9
movl (%rsp), %r10d
movl %r10d, (%r14,%r8)
movl 0x4(%rsp), %r10d
movl %r10d, 0x4(%r14,%r8)
movl $0x2, %r8d
movl (%rsp,%r8,4), %r10d
movl %r10d, (%r9,%r8,4)
incq %r8
cmpq $0x8, %r8
jne 0x6a89
movb $0x1, %r8b
incq %rdi
addq $0x20, %rdx
addq $0x20, %rsi
cmpq %r12, %rdi
jne 0x69a9
movb $0x1, %cl
testb $0x1, %r8b
jne 0x6b02
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x6c52
cmpq %rbx, %rax
setne %cl
je 0x6b02
subq %r14, %rax
sarq $0x5, %rax
leaq (,%r13,2), %rdx
cmpq %rdx, %rax
jl 0x6b02
cqto
idivq %r13
decq %rax
imulq %r13, %rax
shlq $0x5, %rax
addq %rax, %r14
movq %rbx, %r12
subq %r14, %r12
sarq $0x5, %r12
testb %cl, %cl
je 0x6c24
leaq -0x1(%r15), %rax
cmpq $0x2, %r15
movq %rax, %r15
jge 0x697a
movq 0x28(%rsp), %rsi
shlq $0x5, %rsi
addq %r14, %rsi
movq %r14, %rdi
callq 0x6678
movq 0x28(%rsp), %rax
shlq $0x5, %rax
addq %r14, %rax
cmpq %rbx, %rax
jae 0x6c24
leaq 0x8(%rsp), %rcx
xorl %edx, %edx
movq %rax, %rsi
movl (%rsi), %r8d
cmpl -0x20(%rsi), %r8d
jge 0x6c14
leaq -0x20(%rsi), %rdi
movq %rdx, %r9
shlq $0x5, %r9
movl %r8d, (%rsp)
movl 0x4(%rsi), %r8d
movl %r8d, 0x4(%rsp)
movq 0x18(%rax,%r9), %r8
movq %r8, 0x10(%rcx)
movupd 0x8(%rax,%r9), %xmm0
movupd %xmm0, (%rcx)
movq -0x20(%rsi), %r8
movq %r8, (%rsi)
movq $-0x18, %r8
movl (%rsi,%r8), %r9d
movl %r9d, 0x20(%rsi,%r8)
addq $0x4, %r8
jne 0x6b95
movl (%rsp), %r11d
movl -0x40(%rsi), %r10d
cmpl %r10d, %r11d
jge 0x6bf1
leaq -0x40(%rsi), %r9
movq %rsi, %r8
movl %r10d, (%rdi)
movl -0x1c(%rdi), %r10d
movl %r10d, 0x4(%rdi)
movq %r9, %rdi
movq $-0x18, %r9
movl -0x20(%r8,%r9), %r10d
movl %r10d, (%r8,%r9)
addq $0x4, %r9
jne 0x6bcd
leaq -0x20(%rdi), %r9
movl (%rsp), %r11d
movl -0x20(%rdi), %r10d
addq $-0x20, %r8
cmpl %r10d, %r11d
jl 0x6bb8
movl %r11d, (%rdi)
movl 0x4(%rsp), %r8d
movl %r8d, 0x4(%rdi)
movl $0x2, %r8d
movl (%rsp,%r8,4), %r9d
movl %r9d, (%rdi,%r8,4)
incq %r8
cmpq $0x8, %r8
jne 0x6c03
addq $0x20, %rsi
incq %rdx
cmpq %rbx, %rsi
jb 0x6b4e
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbx, %rsi
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6678