// File: /workspace/github_c_makefile_star2_O1/asford[P]tmalign/./TMalign.h
// Function: get_initial(double**, double**, int, int, int*)
double get_initial( double **x, 
                    double **y, 
                    int x_len,
                    int y_len, 
                    int *y2x
                   )
{
    int min_len=getmin(x_len, y_len);
    if(min_len<=5) PrintErrorAndQuit("Sequence is too short <=5!\n");
    
    int min_ali= min_len/2;              //minimum size of considered fragment 
    if(min_ali<=5)  min_ali=5;    
    int n1, n2;
    n1 = -y_len+min_ali; 
    n2 = x_len-min_ali;

    int i, j, k, k_best;
    double tmscore, tmscore_max=-1;

    k_best=n1;
    for(k=n1; k<=n2; k++)
    {
        //get the map
        for(j=0; j<y_len; j++)
        {
            i=j+k;
            if(i>=0 && i<x_len)
            {
                y2x[j]=i;
            }
            else
            {
                y2x[j]=-1;
            }
        }
        
        //evaluate the map quickly in three iterations
		//this is not real tmscore, it is used to evaluate the goodness of the initial alignment
        tmscore=get_score_fast(x, y, x_len, y_len, y2x); 
        if(tmscore>=tmscore_max)
        {
            tmscore_max=tmscore;
            k_best=k;
        }
    }
    
    //extract the best map
    k=k_best;
    for(j=0; j<y_len; j++)
    {
        i=j+k;
        if(i>=0 && i<x_len)
        {
            y2x[j]=i;
        }
        else
        {
            y2x[j]=-1;
        }
    }    

    return tmscore_max;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
cmpl %ecx, %edx
movl %ecx, %eax
cmovll %edx, %eax
cmpl $0x5, %eax
jle 0x408257
movq %r8, %rbx
movl %eax, %esi
shrl %esi
cmpl $0xc, %eax
movl $0x5, %eax
cmovgel %esi, %eax
movl %eax, %edi
subl %ecx, %edi
movl %edx, %esi
subl %eax, %esi
movslq %edx, %r12
movl %ecx, %r13d
cmpl %esi, %edi
jle 0x408182
movsd 0x17beb3(%rip), %xmm1   # 0x584030
jmp 0x40820f
movslq %edi, %r15
negl %eax
addl %edx, %eax
incl %eax
movl %eax, 0x4(%rsp)
movl %edi, %ebp
movsd 0x17be97(%rip), %xmm1   # 0x584030
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %ecx, 0x8(%rsp)
movl %edi, 0xc(%rsp)
movsd %xmm1, 0x20(%rsp)
testl %ecx, %ecx
jle 0x4081d6
xorl %eax, %eax
leaq (%r15,%rax), %rsi
leal (%rax,%rbp), %edx
cmpq %r12, %rsi
cmovgel %r14d, %edx
movq %r15, %rsi
addq %rax, %rsi
cmovsl %r14d, %edx
movl %edx, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x4081b3
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %r8
callq 0x407b41
movl 0x8(%rsp), %ecx
movsd 0x20(%rsp), %xmm1
ucomisd %xmm1, %xmm0
movl 0xc(%rsp), %edi
cmovael %r15d, %edi
maxsd %xmm0, %xmm1
incq %r15
incq %rbp
cmpl %r15d, 0x4(%rsp)
jne 0x4081a3
testl %ecx, %ecx
jle 0x408244
movslq %edi, %rax
movl %eax, %ecx
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq (%rax,%rdx), %rdi
leal (%rcx,%rdx), %r8d
cmpq %r12, %rdi
cmovgel %esi, %r8d
movq %rax, %rdi
addq %rdx, %rdi
cmovsl %esi, %r8d
movl %r8d, (%rbx,%rdx,4)
incq %rdx
cmpq %rdx, %r13
jne 0x40821f
movapd %xmm1, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17c006(%rip), %rdi    # 0x584264
callq 0x404708