// File: /workspace/github_cpp_makefile_star2_O1/Baobaobear[P]sort/./sortlib.hpp
// Function: baobao::TestClass* baobao::internal::tim_sort_create_run<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
RandomAccessIterator tim_sort_create_run(RandomAccessIterator beg, RandomAccessIterator end, Comp compare)
{
    if (end - beg < timsort_last_run_threshold) // must bigger than timsort_min_run
    {
        insert_sort(beg, end, compare);
        return end;
    }

    bool ascending;
    RandomAccessIterator run_end = beg + 3;

    if (compare(*(beg + 1), *beg))
    {
        if (!compare(*(beg + 2), *beg))
        {
            std::swap(*beg, *(beg + 1));
            ascending = true;
        }
        else if (compare(*(beg + 2), *(beg + 1)))
        {
            ascending = false;
        }
        else
        {
            std::swap(*(beg + 2), *(beg + 1));
            ascending = false;
        }
    }
    else
    {
        if (compare(*(beg + 2), *beg))
        {
            std::swap(*beg, *(beg + 1));
            ascending = false;
        }
        else if (!compare(*(beg + 2), *(beg + 1)))
        {
            ascending = true;
        }
        else
        {
            std::swap(*(beg + 2), *(beg + 1));
            ascending = true;
        }
    }

    if (!ascending)
    {
        while (run_end < end && compare(*run_end, *(run_end - 1)))
        {
            ++run_end;
        }

        if (run_end - beg < timsort_min_run)
        {
            insert_sort_part_rev(beg, run_end, beg + timsort_min_run, compare);
            run_end = beg + timsort_min_run;
            while (run_end < end && compare(*run_end, *(run_end - timsort_insert_gap)))
            {
                unguarded_insert_single_rev(run_end, compare);
                ++run_end;
            }
        }

        // reverse
        typename std::iterator_traits<RandomAccessIterator>::value_type t;
        for (RandomAccessIterator b = beg, e = run_end - 1; b < e; ++b, --e)
        {
            t = *b; *b = *e; *e = t;
        }
    }
    else
    {
        while (run_end < end && !compare(*run_end, *(run_end - 1)))
        {
            ++run_end;
        }

        if (run_end - beg < timsort_min_run)
        {
            insert_sort_part(beg, run_end, beg + timsort_min_run, compare);
            run_end = beg + timsort_min_run;
            while (run_end < end && !compare(*run_end, *(run_end - timsort_insert_gap)))
            {
                unguarded_insert_single(run_end, compare);
                ++run_end;
            }
        }
    }

    return run_end;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movq %rsi, %rax
subq %rdi, %rax
cmpq $0x7ff, %rax            # imm = 0x7FF
jg 0x9466
movq %rbx, %rsi
callq 0x6678
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl (%rdi), %edx
movl 0x20(%rdi), %ecx
movl 0x40(%rdi), %eax
cmpl %edx, %ecx
jge 0x94d6
cmpl %edx, %eax
jge 0x9760
cmpl %ecx, %eax
jl 0x9521
movl 0x44(%rdi), %edx
leaq 0x48(%rdi), %rsi
movq 0x58(%rdi), %r8
movq %r8, 0x10(%rsp)
movups 0x48(%rdi), %xmm0
movaps %xmm0, (%rsp)
movl %ecx, 0x40(%rdi)
movl 0x24(%rdi), %ecx
movl %ecx, 0x44(%rdi)
leaq 0x28(%rdi), %rcx
movq $-0x18, %r8
movl -0x8(%rsi,%r8), %r9d
movl %r9d, 0x18(%rsi,%r8)
addq $0x4, %r8
jne 0x94ae
movl %eax, 0x20(%rdi)
movl %edx, 0x24(%rdi)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rcx)
movaps (%rsp), %xmm0
movups %xmm0, (%rcx)
jmp 0x9521
cmpl %edx, %eax
jge 0x97a5
movl 0x4(%rdi), %eax
movq 0x18(%rdi), %rsi
movq %rsi, 0x10(%rsp)
movups 0x8(%rdi), %xmm0
movaps %xmm0, (%rsp)
movl %ecx, (%rdi)
movl 0x24(%rdi), %ecx
movl %ecx, 0x4(%rdi)
movups 0x28(%rdi), %xmm0
movups %xmm0, 0x8(%rdi)
movq 0x38(%rdi), %rcx
movq %rcx, 0x18(%rdi)
movl %edx, 0x20(%rdi)
movl %eax, 0x24(%rdi)
movaps (%rsp), %xmm0
movups %xmm0, 0x28(%rdi)
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rdi)
leaq 0x60(%rdi), %rdx
movl $0x60, %ecx
cmpq %rbx, %rdx
jae 0x954d
movl (%rdi,%rcx), %eax
cmpl -0x20(%rdi,%rcx), %eax
jge 0x9549
leaq (%rdi,%rcx), %rax
addq $0x20, %rax
addq $0x20, %rcx
cmpq %rbx, %rax
jb 0x952f
leaq (%rdi,%rcx), %rdx
movq %rdx, %rax
subq %rdi, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x9a32
leaq 0x400(%rdi), %rax
cmpq $0x3ff, %rcx            # imm = 0x3FF
ja 0x9668
leaq 0x8(%rsp), %rsi
leaq (%rdi,%rcx), %r8
xorl %r9d, %r9d
movl -0x20(%rdi,%rcx), %r10d
movl (%rdi,%rcx), %ebp
cmpl %r10d, %ebp
jl 0x964d
leaq (%rdi,%rcx), %r14
leaq (%rdi,%rcx), %r11
addq $-0x20, %r11
movq %r9, %r15
shlq $0x5, %r15
movl %ebp, (%rsp)
movl 0x4(%r14), %ebp
movl %ebp, 0x4(%rsp)
movq 0x18(%rdx,%r15), %r12
movq %r12, 0x10(%rsi)
movups 0x8(%rdx,%r15), %xmm0
movups %xmm0, (%rsi)
movl %r10d, (%r14)
movl -0x1c(%r14), %r10d
movl %r10d, 0x4(%r14)
movq $-0x18, %r10
movl (%r8,%r10), %ebp
movl %ebp, 0x20(%r8,%r10)
addq $0x4, %r10
jne 0x95d2
movl (%rsp), %ebp
movq %r8, %r14
movl -0x20(%r11), %r15d
cmpl %r15d, %ebp
jl 0x9623
leaq -0x20(%r11), %r10
movl %r15d, (%r11)
movl -0x1c(%r11), %r15d
movl %r15d, 0x4(%r11)
movq $-0x18, %r11
movl -0x20(%r14,%r11), %r15d
movl %r15d, (%r14,%r11)
addq $0x4, %r11
jne 0x9606
addq $-0x20, %r14
movq %r10, %r11
cmpq %rdi, %r10
jne 0x95e7
jmp 0x9626
movq %r11, %r10
movl (%rsp), %r11d
movl %r11d, (%r10)
movl 0x4(%rsp), %r11d
movl %r11d, 0x4(%r10)
movl $0x2, %r11d
movl (%rsp,%r11,4), %ebp
movl %ebp, (%r10,%r11,4)
incq %r11
cmpq $0x8, %r11
jne 0x963c
leaq 0x20(%rcx), %r10
incq %r9
addq $0x20, %r8
cmpq $0x3e0, %rcx            # imm = 0x3E0
movq %r10, %rcx
jb 0x957f
cmpq %rbx, %rax
jae 0x9a35
leaq 0x8(%rsp), %rcx
leaq 0x408(%rdi), %rdx
leaq 0x3e8(%rdi), %rsi
movl (%rax), %r8d
cmpl -0x100(%rax), %r8d
jge 0x9a35
movl -0x20(%rax), %r11d
cmpl %r11d, %r8d
jl 0x9746
leaq -0x20(%rax), %r9
movl %r8d, (%rsp)
movl 0x4(%rax), %r10d
movl %r10d, 0x4(%rsp)
movq 0x18(%rax), %r14
movq %r14, 0x10(%rcx)
movups 0x8(%rax), %xmm0
movups %xmm0, (%rcx)
movl %r11d, (%rax)
movl -0x1c(%rax), %r11d
movl %r11d, 0x4(%rax)
movq $-0x18, %r11
movl -0x8(%rdx,%r11), %ebp
movl %ebp, 0x18(%rdx,%r11)
addq $0x4, %r11
jne 0x96d3
movl -0x40(%rax), %ebp
cmpl %ebp, %r8d
jl 0x9728
leaq -0x40(%rax), %r14
movq %rsi, %r11
movl %ebp, (%r9)
movl -0x1c(%r9), %ebp
movl %ebp, 0x4(%r9)
movq %r14, %r9
movq $-0x18, %r14
movl -0x8(%r11,%r14), %ebp
movl %ebp, 0x18(%r11,%r14)
addq $0x4, %r14
jne 0x9707
leaq -0x20(%r9), %r14
movl -0x20(%r9), %ebp
addq $-0x20, %r11
cmpl %ebp, %r8d
jge 0x96f2
movl %r8d, (%r9)
movl %r10d, 0x4(%r9)
movl $0x2, %r8d
movl (%rsp,%r8,4), %r10d
movl %r10d, (%r9,%r8,4)
incq %r8
cmpq $0x8, %r8
jne 0x9735
addq $0x20, %rax
addq $0x20, %rdx
addq $0x20, %rsi
cmpq %rbx, %rax
jb 0x9684
jmp 0x9a35
movl 0x4(%rdi), %eax
movq 0x18(%rdi), %rsi
movq %rsi, 0x10(%rsp)
movups 0x8(%rdi), %xmm0
movaps %xmm0, (%rsp)
movl %ecx, (%rdi)
movl 0x24(%rdi), %ecx
movl %ecx, 0x4(%rdi)
movups 0x28(%rdi), %xmm0
movups %xmm0, 0x8(%rdi)
movq 0x38(%rdi), %rcx
movq %rcx, 0x18(%rdi)
movl %edx, 0x20(%rdi)
movl %eax, 0x24(%rdi)
movaps (%rsp), %xmm0
movups %xmm0, 0x28(%rdi)
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rdi)
jmp 0x97fb
cmpl %ecx, %eax
jge 0x97fb
movl 0x44(%rdi), %edx
leaq 0x48(%rdi), %rsi
movq 0x58(%rdi), %r8
movq %r8, 0x10(%rsp)
movups 0x48(%rdi), %xmm0
movaps %xmm0, (%rsp)
movl %ecx, 0x40(%rdi)
movl 0x24(%rdi), %ecx
movl %ecx, 0x44(%rdi)
leaq 0x28(%rdi), %rcx
movq $-0x18, %r8
movl -0x8(%rsi,%r8), %r9d
movl %r9d, 0x18(%rsi,%r8)
addq $0x4, %r8
jne 0x97d5
movl %eax, 0x20(%rdi)
movl %edx, 0x24(%rdi)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rcx)
movaps (%rsp), %xmm0
movups %xmm0, (%rcx)
leaq 0x60(%rdi), %rsi
movl $0x60, %edx
cmpq %rbx, %rsi
jae 0x9827
movl (%rdi,%rdx), %eax
cmpl -0x20(%rdi,%rdx), %eax
jl 0x9823
leaq (%rdi,%rdx), %rax
addq $0x20, %rax
addq $0x20, %rdx
cmpq %rbx, %rax
jb 0x9809
leaq (%rdi,%rdx), %rsi
movq %rsi, %rax
subq %rdi, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x9adc
leaq 0x400(%rdi), %rax
leaq 0x8(%rsp), %rcx
cmpq $0x3ff, %rdx            # imm = 0x3FF
ja 0x9942
leaq (%rdi,%rdx), %r8
xorl %r9d, %r9d
movl -0x20(%rdi,%rdx), %r10d
movl (%rdi,%rdx), %ebp
cmpl %r10d, %ebp
jge 0x9927
leaq (%rdi,%rdx), %r14
leaq (%rdi,%rdx), %r11
addq $-0x20, %r11
movq %r9, %r15
shlq $0x5, %r15
movl %ebp, (%rsp)
movl 0x4(%r14), %ebp
movl %ebp, 0x4(%rsp)
movq 0x18(%rsi,%r15), %r12
movq %r12, 0x10(%rcx)
movups 0x8(%rsi,%r15), %xmm0
movups %xmm0, (%rcx)
movl %r10d, (%r14)
movl -0x1c(%r14), %r10d
movl %r10d, 0x4(%r14)
movq $-0x18, %r10
movl (%r8,%r10), %ebp
movl %ebp, 0x20(%r8,%r10)
addq $0x4, %r10
jne 0x98ac
movl (%rsp), %ebp
movq %r8, %r14
movl -0x20(%r11), %r15d
cmpl %r15d, %ebp
jge 0x98fd
leaq -0x20(%r11), %r10
movl %r15d, (%r11)
movl -0x1c(%r11), %r15d
movl %r15d, 0x4(%r11)
movq $-0x18, %r11
movl -0x20(%r14,%r11), %r15d
movl %r15d, (%r14,%r11)
addq $0x4, %r11
jne 0x98e0
addq $-0x20, %r14
movq %r10, %r11
cmpq %rdi, %r10
jne 0x98c1
jmp 0x9900
movq %r11, %r10
movl (%rsp), %r11d
movl %r11d, (%r10)
movl 0x4(%rsp), %r11d
movl %r11d, 0x4(%r10)
movl $0x2, %r11d
movl (%rsp,%r11,4), %ebp
movl %ebp, (%r10,%r11,4)
incq %r11
cmpq $0x8, %r11
jne 0x9916
leaq 0x20(%rdx), %r10
incq %r9
addq $0x20, %r8
cmpq $0x3e0, %rdx            # imm = 0x3E0
movq %r10, %rdx
jb 0x9859
cmpq %rbx, %rax
jae 0x9459
leaq 0x408(%rdi), %rdx
addq $0x3e8, %rdi            # imm = 0x3E8
movl (%rax), %esi
cmpl -0x100(%rax), %esi
jl 0x9459
movl -0x20(%rax), %r10d
cmpl %r10d, %esi
jge 0x9a18
leaq -0x20(%rax), %r8
movl %esi, (%rsp)
movl 0x4(%rax), %r9d
movl %r9d, 0x4(%rsp)
movq 0x18(%rax), %r11
movq %r11, 0x10(%rcx)
movups 0x8(%rax), %xmm0
movups %xmm0, (%rcx)
movl %r10d, (%rax)
movl -0x1c(%rax), %r10d
movl %r10d, 0x4(%rax)
movq $-0x18, %r10
movl -0x8(%rdx,%r10), %r11d
movl %r11d, 0x18(%rdx,%r10)
addq $0x4, %r10
jne 0x99a5
movl -0x40(%rax), %r11d
cmpl %r11d, %esi
jge 0x99fb
leaq -0x40(%rax), %r14
movq %rdi, %r10
movl %r11d, (%r8)
movl -0x1c(%r8), %r11d
movl %r11d, 0x4(%r8)
movq %r14, %r8
movq $-0x18, %r11
movl -0x8(%r10,%r11), %ebp
movl %ebp, 0x18(%r10,%r11)
addq $0x4, %r11
jne 0x99da
leaq -0x20(%r8), %r14
movl -0x20(%r8), %r11d
addq $-0x20, %r10
cmpl %r11d, %esi
jl 0x99c5
movl %esi, (%r8)
movl %r9d, 0x4(%r8)
movl $0x2, %esi
movl (%rsp,%rsi,4), %r9d
movl %r9d, (%r8,%rsi,4)
incq %rsi
cmpq $0x8, %rsi
jne 0x9a07
addq $0x20, %rax
addq $0x20, %rdx
addq $0x20, %rdi
cmpq %rbx, %rax
jb 0x9959
jmp 0x9459
movq %rdx, %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
leaq -0x20(%rax), %rcx
cmpq %rdi, %rcx
jbe 0x9459
leaq 0x8(%rsp), %rdx
xorl %esi, %esi
movq %rax, %r8
movq %rdi, %r9
movq %rsi, %rbx
shlq $0x5, %rbx
movl (%r9), %r10d
movl %r10d, (%rsp)
movl 0x4(%r9), %r11d
movl %r11d, 0x4(%rsp)
movq 0x18(%rdi,%rbx), %r14
movq %r14, 0x10(%rdx)
movups 0x8(%rdi,%rbx), %xmm0
movups %xmm0, (%rdx)
movl (%rcx), %ebx
movl %ebx, (%r9)
movl -0x1c(%r8), %ebx
movl %ebx, 0x4(%r9)
movq $-0x18, %rbx
movl (%r8,%rbx), %ebp
movl %ebp, 0x20(%r9,%rbx)
addq $0x4, %rbx
jne 0x9a97
movl %r10d, (%rcx)
movl %r11d, -0x1c(%r8)
movq $-0x18, %r10
movl 0x20(%rsp,%r10), %r11d
movl %r11d, (%r8,%r10)
addq $0x4, %r10
jne 0x9ab4
addq $0x20, %r9
addq $-0x20, %rcx
incq %rsi
addq $-0x20, %r8
cmpq %rcx, %r9
jb 0x9a5b
jmp 0x9459
movq %rsi, %rax
jmp 0x9459