// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
cmpl %ecx, %edx
movl %ecx, %eax
cmovll %edx, %eax
cmpl $0x5, %eax
jle 0x408305
movq %r8, %rbx
movl %ecx, %ebp
movl %eax, %esi
shrl %esi
cmpl $0xc, %eax
movl $0x5, %eax
cmovael %esi, %eax
movl %eax, %r8d
subl %ecx, %r8d
movl %edx, %esi
subl %eax, %esi
movslq %edx, %r13
movl %ecx, %edi
cmpl %esi, %r8d
movq %rdi, 0x10(%rsp)
jle 0x4080bd
movsd 0x17bf78(%rip), %xmm8   # 0x584030
jmp 0x408218
movslq %r8d, %r15
negl %eax
addl %edx, %eax
incl %eax
movl %eax, 0x8(%rsp)
leal 0x1(%rbp), %r12d
leaq -0x1(%rdi), %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm4     # xmm4 = xmm0[0,1,0,1]
shrl %r12d
shlq $0x3, %r12
movsd 0x17bf44(%rip), %xmm8   # 0x584030
movdqa 0x17c05c(%rip), %xmm5   # 0x584150
pxor %xmm5, %xmm4
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
pcmpeqd %xmm6, %xmm6
movdqa 0x17c056(%rip), %xmm7   # 0x584160
movdqa %xmm4, 0x30(%rsp)
movl %r8d, 0xc(%rsp)
movsd %xmm8, 0x28(%rsp)
movq %r15, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
xorl %eax, %eax
movdqa 0x17c010(%rip), %xmm1   # 0x584140
movdqa %xmm1, %xmm2
pxor %xmm5, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm4, %xmm3
pcmpeqd %xmm4, %xmm2
pshufd $0xf5, %xmm2, %xmm2     # xmm2 = xmm2[1,1,3,3]
pand %xmm3, %xmm2
pshufd $0xf5, %xmm3, %xmm3     # xmm3 = xmm3[1,1,3,3]
por %xmm2, %xmm3
movdqa %xmm1, %xmm2
paddq %xmm0, %xmm2
movd %xmm3, %edx
notl %edx
testb $0x1, %dl
je 0x408183
movq %xmm2, %rsi
cmpq %r13, %rsi
movd %xmm2, %edx
cmovgel %r14d, %edx
testq %rsi, %rsi
cmovsl %r14d, %edx
movl %edx, (%rbx,%rax)
pxor %xmm6, %xmm3
pextrw $0x4, %xmm3, %edx
testb $0x1, %dl
je 0x4081b1
pshufd $0xee, %xmm2, %xmm2     # xmm2 = xmm2[2,3,2,3]
movq %xmm2, %rsi
cmpq %r13, %rsi
movd %xmm2, %edx
cmovgel %r14d, %edx
testq %rsi, %rsi
cmovsl %r14d, %edx
movl %edx, 0x4(%rbx,%rax)
paddq %xmm7, %xmm1
addq $0x8, %rax
cmpq %rax, %r12
jne 0x408130
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl %ebp, %ecx
movq %rbx, %r8
callq 0x407a58
movdqa 0x17bf82(%rip), %xmm7   # 0x584160
pcmpeqd %xmm6, %xmm6
movdqa 0x17bf66(%rip), %xmm5   # 0x584150
movdqa 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm8
ucomisd %xmm8, %xmm0
movl 0xc(%rsp), %r8d
cmovael %r15d, %r8d
maxsd %xmm0, %xmm8
incq %r15
cmpl %r15d, 0x8(%rsp)
jne 0x408110
movslq %r8d, %rax
incl %ebp
andl $-0x2, %ebp
movq 0x10(%rsp), %rdx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq %rax, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movdqa 0x17befc(%rip), %xmm2   # 0x584140
xorl %eax, %eax
movdqa 0x17bf02(%rip), %xmm3   # 0x584150
pxor %xmm3, %xmm0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
pcmpeqd %xmm4, %xmm4
movdqa 0x17befd(%rip), %xmm5   # 0x584160
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pand %xmm7, %xmm6
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
por %xmm6, %xmm7
movdqa %xmm2, %xmm6
paddq %xmm1, %xmm6
movd %xmm7, %edx
notl %edx
testb $0x1, %dl
je 0x4082b4
movq %xmm6, %rdx
cmpq %r13, %rdx
movd %xmm6, %esi
cmovgel %edi, %esi
testq %rdx, %rdx
cmovsl %edi, %esi
movl %esi, (%rbx,%rax,4)
pxor %xmm4, %xmm7
pextrw $0x4, %xmm7, %edx
testb $0x1, %dl
je 0x4082e0
pshufd $0xee, %xmm6, %xmm6     # xmm6 = xmm6[2,3,2,3]
movq %xmm6, %rdx
cmpq %r13, %rdx
movd %xmm6, %esi
cmovgel %edi, %esi
testq %rdx, %rdx
cmovsl %edi, %esi
movl %esi, 0x4(%rbx,%rax,4)
addq $0x2, %rax
paddq %xmm5, %xmm2
cmpq %rax, %rbp
jne 0x408263
movapd %xmm8, %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17bf48(%rip), %rdi    # 0x584254
callq 0x404708