// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::tsort_tagsortfastirec(alglib_impl::ae_vector*, alglib_impl::ae_vector*, alglib_impl::ae_vector*, alglib_impl::ae_vector*, long, long, alglib_impl::ae_state*)
static void tsort_tagsortfastirec(/* Real    */ ae_vector* a,
     /* Integer */ ae_vector* b,
     /* Real    */ ae_vector* bufa,
     /* Integer */ ae_vector* bufb,
     ae_int_t i1,
     ae_int_t i2,
     ae_state *_state)
{
    ae_int_t i;
    ae_int_t j;
    ae_int_t k;
    ae_int_t cntless;
    ae_int_t cnteq;
    ae_int_t cntgreater;
    double tmpr;
    ae_int_t tmpi;
    double v0;
    double v1;
    double v2;
    double vp;


    
    /*
     * Fast exit
     */
    if( i2<=i1 )
    {
        return;
    }
    
    /*
     * Non-recursive sort for small arrays
     */
    if( i2-i1<=16 )
    {
        for(j=i1+1; j<=i2; j++)
        {
            
            /*
             * Search elements [I1..J-1] for place to insert Jth element.
             *
             * This code stops immediately if we can leave A[J] at J-th position
             * (all elements have same value of A[J] larger than any of them)
             */
            tmpr = a->ptr.p_double[j];
            tmpi = j;
            for(k=j-1; k>=i1; k--)
            {
                if( a->ptr.p_double[k]<=tmpr )
                {
                    break;
                }
                tmpi = k;
            }
            k = tmpi;
            
            /*
             * Insert Jth element into Kth position
             */
            if( k!=j )
            {
                tmpr = a->ptr.p_double[j];
                tmpi = b->ptr.p_int[j];
                for(i=j-1; i>=k; i--)
                {
                    a->ptr.p_double[i+1] = a->ptr.p_double[i];
                    b->ptr.p_int[i+1] = b->ptr.p_int[i];
                }
                a->ptr.p_double[k] = tmpr;
                b->ptr.p_int[k] = tmpi;
            }
        }
        return;
    }
    
    /*
     * Quicksort: choose pivot
     * Here we assume that I2-I1>=2
     */
    v0 = a->ptr.p_double[i1];
    v1 = a->ptr.p_double[i1+(i2-i1)/2];
    v2 = a->ptr.p_double[i2];
    if( v0>v1 )
    {
        tmpr = v1;
        v1 = v0;
        v0 = tmpr;
    }
    if( v1>v2 )
    {
        tmpr = v2;
        v2 = v1;
        v1 = tmpr;
    }
    if( v0>v1 )
    {
        tmpr = v1;
        v1 = v0;
        v0 = tmpr;
    }
    vp = v1;
    
    /*
     * now pass through A/B and:
     * * move elements that are LESS than VP to the left of A/B
     * * move elements that are EQUAL to VP to the right of BufA/BufB (in the reverse order)
     * * move elements that are GREATER than VP to the left of BufA/BufB (in the normal order
     * * move elements from the tail of BufA/BufB to the middle of A/B (restoring normal order)
     * * move elements from the left of BufA/BufB to the end of A/B
     */
    cntless = 0;
    cnteq = 0;
    cntgreater = 0;
    for(i=i1; i<=i2; i++)
    {
        v0 = a->ptr.p_double[i];
        if( v0<vp )
        {
            
            /*
             * LESS
             */
            k = i1+cntless;
            if( i!=k )
            {
                a->ptr.p_double[k] = v0;
                b->ptr.p_int[k] = b->ptr.p_int[i];
            }
            cntless = cntless+1;
            continue;
        }
        if( v0==vp )
        {
            
            /*
             * EQUAL
             */
            k = i2-cnteq;
            bufa->ptr.p_double[k] = v0;
            bufb->ptr.p_int[k] = b->ptr.p_int[i];
            cnteq = cnteq+1;
            continue;
        }
        
        /*
         * GREATER
         */
        k = i1+cntgreater;
        bufa->ptr.p_double[k] = v0;
        bufb->ptr.p_int[k] = b->ptr.p_int[i];
        cntgreater = cntgreater+1;
    }
    for(i=0; i<=cnteq-1; i++)
    {
        j = i1+cntless+cnteq-1-i;
        k = i2+i-(cnteq-1);
        a->ptr.p_double[j] = bufa->ptr.p_double[k];
        b->ptr.p_int[j] = bufb->ptr.p_int[k];
    }
    for(i=0; i<=cntgreater-1; i++)
    {
        j = i1+cntless+cnteq+i;
        k = i1+i;
        a->ptr.p_double[j] = bufa->ptr.p_double[k];
        b->ptr.p_int[j] = bufb->ptr.p_int[k];
    }
    
    /*
     * Sort left and right parts of the array (ignoring middle part)
     */
    tsort_tagsortfastirec(a, b, bufa, bufb, i1, i1+cntless-1, _state);
    tsort_tagsortfastirec(a, b, bufa, bufb, i1+cntless+cnteq, i2, _state);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1(%r9), %rax
movq %rax, (%rsp)
movq %rbx, %rax
subq %r8, %rax
jle 0x14787
cmpq $0x10, %rax
jle 0x146e2
movq 0x28(%r15), %rcx
leaq (%rcx,%r8,8), %rdx
movsd (%rdx), %xmm1
andq $-0x2, %rax
movsd (%rdx,%rax,4), %xmm2
movsd (%rcx,%rbx,8), %xmm3
movapd %xmm2, %xmm0
minsd %xmm1, %xmm0
maxsd %xmm2, %xmm1
minsd %xmm1, %xmm3
maxsd %xmm3, %xmm0
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movq %r8, %rsi
cmpq %rbx, %rsi
jg 0x1461b
movq 0x28(%r15), %rdi
movsd (%rdi,%rsi,8), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x145c7
leaq (%rcx,%r8), %r9
cmpq %r9, %rsi
je 0x145c2
movsd %xmm1, (%rdi,%r9,8)
movq 0x28(%r14), %rdi
movq (%rdi,%rsi,8), %r10
movq %r10, (%rdi,%r9,8)
incq %rcx
jmp 0x14613
ucomisd %xmm0, %xmm1
movq 0x28(%r13), %rdi
jne 0x145f5
jp 0x145f5
movq %rbx, %r9
subq %rdx, %r9
movsd %xmm1, (%rdi,%r9,8)
movq 0x28(%r14), %rdi
movq (%rdi,%rsi,8), %rdi
movq 0x28(%r12), %r10
movq %rdi, (%r10,%r9,8)
incq %rdx
jmp 0x14613
leaq (%rax,%r8), %r9
movsd %xmm1, (%rdi,%r9,8)
movq 0x28(%r14), %rdi
movq (%rdi,%rsi,8), %rdi
movq 0x28(%r12), %r10
movq %rdi, (%r10,%r9,8)
incq %rax
incq %rsi
jmp 0x1458f
leaq (%rcx,%r8), %r9
testq %rdx, %rdx
movl $0x0, %esi
cmovgq %rdx, %rsi
leaq (%r9,%rdx), %rbp
negq %rsi
movq (%rsp), %rdi
subq %rdx, %rdi
shlq $0x3, %rdx
leaq (%rdx,%r8,8), %rdx
leaq (%rdx,%rcx,8), %rcx
addq $-0x8, %rcx
xorl %edx, %edx
cmpq %rdx, %rsi
je 0x14683
movq 0x28(%r13), %r10
movsd (%r10,%rdi,8), %xmm0
movq 0x28(%r15), %r10
addq %rcx, %r10
movsd %xmm0, (%r10,%rdx,8)
movq 0x28(%r12), %r10
movq (%r10,%rdi,8), %r10
movq 0x28(%r14), %r11
addq %rcx, %r11
movq %r10, (%r11,%rdx,8)
decq %rdx
incq %rdi
jmp 0x1464b
testq %rax, %rax
movl $0x0, %ecx
cmovleq %rcx, %rax
movq %r8, %rcx
movq %rbp, %rdx
subq $0x1, %rax
jb 0x146c6
movq 0x28(%r13), %rsi
movsd (%rsi,%rcx,8), %xmm0
movq 0x28(%r15), %rsi
movsd %xmm0, (%rsi,%rdx,8)
movq 0x28(%r12), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x28(%r14), %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
incq %rcx
jmp 0x14695
decq %r9
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x14520
movq %rbp, %r8
jmp 0x14542
leaq (,%r8,8), %rax
movq %r8, %rcx
notq %rcx
movq %r8, %rsi
cmpq %rbx, %rsi
jge 0x14787
leaq 0x1(%rsi), %rdx
movq 0x28(%r15), %r9
movsd (%r9,%rdx,8), %xmm0
addq %rax, %r9
xorl %r10d, %r10d
movq %r10, %rdi
addq %rsi, %r10
cmpq %r8, %r10
jl 0x14727
leaq -0x1(%rdi), %r10
ucomisd (%r9,%rdi,8), %xmm0
jb 0x14710
testq %rdi, %rdi
je 0x14778
movq %rdi, %r10
subq %rcx, %r10
movq 0x28(%r14), %r9
movq (%r9,%rdx,8), %r9
movq 0x28(%r15), %r11
cmpq %r10, %rsi
jl 0x14762
movsd (%r11,%rsi,8), %xmm1
movsd %xmm1, 0x8(%r11,%rsi,8)
movq 0x28(%r14), %r11
movq (%r11,%rsi,8), %r12
movq %r12, 0x8(%r11,%rsi,8)
decq %rsi
jmp 0x1473a
addq %rax, %r11
movsd %xmm0, 0x8(%r11,%rdi,8)
movq 0x28(%r14), %rsi
addq %rax, %rsi
movq %r9, 0x8(%rsi,%rdi,8)
addq $0x8, %rax
decq %rcx
movq %rdx, %rsi
jmp 0x146f3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq