// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::tagsortfasti(alglib_impl::ae_vector*, alglib_impl::ae_vector*, alglib_impl::ae_vector*, alglib_impl::ae_vector*, long, alglib_impl::ae_state*)
void tagsortfasti(/* Real    */ ae_vector* a,
     /* Integer */ ae_vector* b,
     /* Real    */ ae_vector* bufa,
     /* Integer */ ae_vector* bufb,
     ae_int_t n,
     ae_state *_state)
{
    ae_int_t i;
    ae_int_t j;
    ae_bool isascending;
    ae_bool isdescending;
    double tmpr;
    ae_int_t tmpi;


    
    /*
     * Special case
     */
    if( n<=1 )
    {
        return;
    }
    
    /*
     * Test for already sorted set
     */
    isascending = ae_true;
    isdescending = ae_true;
    for(i=1; i<=n-1; i++)
    {
        isascending = isascending&&a->ptr.p_double[i]>=a->ptr.p_double[i-1];
        isdescending = isdescending&&a->ptr.p_double[i]<=a->ptr.p_double[i-1];
    }
    if( isascending )
    {
        return;
    }
    if( isdescending )
    {
        for(i=0; i<=n-1; i++)
        {
            j = n-1-i;
            if( j<=i )
            {
                break;
            }
            tmpr = a->ptr.p_double[i];
            a->ptr.p_double[i] = a->ptr.p_double[j];
            a->ptr.p_double[j] = tmpr;
            tmpi = b->ptr.p_int[i];
            b->ptr.p_int[i] = b->ptr.p_int[j];
            b->ptr.p_int[j] = tmpi;
        }
        return;
    }
    
    /*
     * General case
     */
    if( bufa->cnt<n )
    {
        ae_vector_set_length(bufa, n, _state);
    }
    if( bufb->cnt<n )
    {
        ae_vector_set_length(bufb, n, _state);
    }
    tsort_tagsortfastirec(a, b, bufa, bufb, 0, n-1, _state);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x2, %r8
jl 0x14469
movq %r9, %rbp
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x1
popq %rax
movb $0x1, %cl
movb $0x1, %dl
cmpq %rax, %r15
je 0x14464
testb $0x1, %dl
je 0x14442
movq 0x28(%r14), %rdx
movsd (%rdx,%rax,8), %xmm0
ucomisd -0x8(%rdx,%rax,8), %xmm0
setae %dl
jmp 0x14444
xorl %edx, %edx
testb $0x1, %cl
je 0x1445d
movq 0x28(%r14), %rcx
movsd -0x8(%rcx,%rax,8), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
setae %cl
jmp 0x1445f
xorl %ecx, %ecx
incq %rax
jmp 0x14424
testb $0x1, %dl
je 0x14478
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, %cl
je 0x144cf
xorl %eax, %eax
testq %r15, %r15
je 0x14469
leaq -0x1(%r15), %rcx
cmpq %rax, %rcx
jle 0x14469
movq 0x28(%r14), %rdx
movsd (%rdx,%rax,8), %xmm0
movsd -0x8(%rdx,%r15,8), %xmm1
movsd %xmm1, (%rdx,%rax,8)
movq 0x28(%r14), %rdx
movsd %xmm0, -0x8(%rdx,%r15,8)
movq 0x28(%rbx), %rdx
movq (%rdx,%rax,8), %rsi
movq -0x8(%rdx,%r15,8), %rdi
movq %rdi, (%rdx,%rax,8)
movq 0x28(%rbx), %rdx
movq %rsi, -0x8(%rdx,%r15,8)
incq %rax
movq %rcx, %r15
jmp 0x1447f
cmpq %r15, (%r13)
jge 0x144e3
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x23add
leaq -0x1(%r15), %r9
cmpq %r15, (%r12)
jge 0x14501
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r9, %r15
callq 0x23add
movq %r15, %r9
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x14520