// File: /workspace/github_cpp_makefile_star2_O3/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 0x150e0
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movb $0x1, %dl
movl $0x1, %eax
movb $0x1, %cl
testb $0x1, %dl
je 0x150b7
movq 0x28(%r14), %rdx
movsd (%rdx,%rax,8), %xmm0
ucomisd -0x8(%rdx,%rax,8), %xmm0
setae %dl
jmp 0x150b9
xorl %edx, %edx
testb $0x1, %cl
je 0x150d2
movq 0x28(%r14), %rcx
movsd -0x8(%rcx,%rax,8), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
setae %cl
jmp 0x150d4
xorl %ecx, %ecx
incq %rax
cmpq %rax, %rbp
jne 0x1509e
testb %dl, %dl
je 0x150ef
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1(%rbp), %r13
testb %cl, %cl
je 0x1513f
xorl %eax, %eax
cmpq %rax, %r13
jle 0x150e0
movq 0x28(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd (%rcx,%r13,8), %xmm1
movsd %xmm1, (%rcx,%rax,8)
movq 0x28(%r14), %rcx
movsd %xmm0, (%rcx,%r13,8)
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
movq (%rcx,%r13,8), %rsi
movq %rsi, (%rcx,%rax,8)
movq 0x28(%rbx), %rcx
movq %rdx, (%rcx,%r13,8)
incq %rax
addq $-0x1, %r13
jb 0x150f9
jmp 0x150e0
cmpq %rbp, (%r12)
jge 0x1515b
movq %r12, %rdi
movq %rbp, %rsi
movq %r9, %rdx
movq %r9, (%rsp)
callq 0x25326
movq (%rsp), %r9
cmpq %rbp, (%r15)
jge 0x1516e
movq %r15, %rdi
movq %rbp, %rsi
movq %r9, %rdx
callq 0x25326
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
movq %r13, %r9
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x15190