// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movl %ecx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x40(%rsp), %eax
jle 0x40aaff
movl 0x40(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x40ab07
movl 0x44(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x34(%rsp)
cmpl $0x5, 0x34(%rsp)
jg 0x40ab22
leaq 0x1816fb(%rip), %rdi    # 0x58c218
callq 0x404740
movl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x30(%rsp)
cmpl $0x5, 0x30(%rsp)
jg 0x40ab41
movl $0x5, 0x30(%rsp)
xorl %eax, %eax
subl 0x40(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x44(%rsp), %eax
subl 0x30(%rsp), %eax
movl %eax, 0x28(%rsp)
movsd 0x1814dd(%rip), %xmm0   # 0x58c040
movsd %xmm0, 0x8(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x28(%rsp), %eax
jg 0x40ac3f
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x40(%rsp), %eax
jge 0x40abe9
movl 0x20(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jl 0x40abc9
movl 0x24(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x40abc9
movl 0x24(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x20(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x40abda
movq 0x38(%rsp), %rax
movslq 0x20(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x40abdc
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x40ab8f
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x44(%rsp), %edx
movl 0x40(%rsp), %ecx
movq 0x38(%rsp), %r8
callq 0x40a1f0
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jb 0x40ac2d
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0x40ac2f
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x40ab79
movl 0x18(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x40(%rsp), %eax
jge 0x40aca9
movl 0x20(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jl 0x40ac89
movl 0x24(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x40ac89
movl 0x24(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x20(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x40ac9a
movq 0x38(%rsp), %rax
movslq 0x20(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x40ac9c
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x40ac4f
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)