// File: /workspace/github_c_makefile_star2_O0/asford[P]tmalign/./TMalign.h
// Function: TMscore8_search(double**, double**, int, double*, double (*) [3], int, int, double*)
double TMscore8_search( double **xtm, 
                        double **ytm,
                        int Lali, 
                        double t0[3],
                        double u0[3][3],
                        int simplify_step,
                        int score_sum_method,
                        double *Rcomm
                       )
{   
    int i, m;
    double score_max, score, rmsd;    
    const int kmax=Lali;    
    int k_ali[kmax], ka, k;
    double t[3];
    double u[3][3];
	double d;
	

	//iterative parameters
	int n_it=20;            //maximum number of iterations
    const int n_init_max=6; //maximum number of different fragment length 
    int L_ini[n_init_max];  //fragment lengths, Lali, Lali/2, Lali/4 ... 4   
    int L_ini_min=4;
    if(Lali<4) L_ini_min=Lali;   
    int n_init=0, i_init;      
    for(i=0; i<n_init_max-1; i++)
    {
        n_init++;
        L_ini[i]=(int) (Lali/pow(2.0, (double) i));
        if(L_ini[i]<=L_ini_min)
        {
            L_ini[i]=L_ini_min;
            break;
        }
    }
    if(i==n_init_max-1)
    {
        n_init++;
        L_ini[i]=L_ini_min;
    }
    
    score_max=-1;
    //find the maximum score starting from local structures superposition
    int i_ali[kmax], n_cut;
    int L_frag; //fragment length
    int iL_max; //maximum starting postion for the fragment
    for(i_init=0; i_init<n_init; i_init++)
    {
        L_frag=L_ini[i_init];
        iL_max=Lali-L_frag;
      
        i=0;   
        while(1)
        {
            //extract the fragment starting from position i 
            ka=0;
            for(k=0; k<L_frag; k++)
            {
				int kk=k+i;
                r1[k][0]=xtm[kk][0];  
                r1[k][1]=xtm[kk][1]; 
                r1[k][2]=xtm[kk][2];   
                
                r2[k][0]=ytm[kk][0];  
                r2[k][1]=ytm[kk][1]; 
                r2[k][2]=ytm[kk][2];
                
                k_ali[ka]=kk;
                ka++;
            }
            
            //extract rotation matrix based on the fragment
            Kabsch(r1, r2, L_frag, 1, &rmsd, t, u);
            if(i_init==0)
            {
                *Rcomm=sqrt(rmsd/Lali);
            }
            do_rotation(xtm, xt, Lali, t, u);
            
            //get subsegment of this fragment
            d=d0_search-1;
            n_cut=score_fun8(xt, ytm, Lali, d, i_ali, &score, score_sum_method);
            if(score>score_max)
            {
                score_max=score;
                
                //save the rotation matrix
                for(k=0; k<3; k++)
                {
                    t0[k]=t[k];
                    u0[k][0]=u[k][0];
                    u0[k][1]=u[k][1];
                    u0[k][2]=u[k][2];
                }
            }
            
            //try to extend the alignment iteratively            
            d=d0_search+1;
            for(int it=0; it<n_it; it++)            
            {
                ka=0;
                for(k=0; k<n_cut; k++)
                {
                    m=i_ali[k];
                    r1[k][0]=xtm[m][0];  
                    r1[k][1]=xtm[m][1]; 
                    r1[k][2]=xtm[m][2];
                    
                    r2[k][0]=ytm[m][0];  
                    r2[k][1]=ytm[m][1]; 
                    r2[k][2]=ytm[m][2];
                    
                    k_ali[ka]=m;
                    ka++;
                } 
                //extract rotation matrix based on the fragment                
                Kabsch(r1, r2, n_cut, 1, &rmsd, t, u);
                do_rotation(xtm, xt, Lali, t, u);
                n_cut=score_fun8(xt, ytm, Lali, d, i_ali, &score, score_sum_method);
                if(score>score_max)
                {
                    score_max=score;

                    //save the rotation matrix
                    for(k=0; k<3; k++)
                    {
                        t0[k]=t[k];
                        u0[k][0]=u[k][0];
                        u0[k][1]=u[k][1];
                        u0[k][2]=u[k][2];
                    }                     
                }
                
                //check if it converges                 
			
                if(n_cut==ka)
                {				
                    for(k=0; k<n_cut; k++)
                    {
                        if(i_ali[k]!=k_ali[k])
						{
							break;
						}
                    }
                    if(k==n_cut)
                    {						
                        break; //stop iteration
                    }
                }                                                               
            } //for iteration            

			if(i<iL_max)
			{
				i=i+simplify_step; //shift the fragment		
				if(i>iL_max) i=iL_max;  //do this to use the last missed fragment
			}
			else if(i>=iL_max)
			{
				break;
			}
        }//while(1)
        //end of one fragment
    }//for(i_init
    return score_max;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x60(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x148(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl $0x14, -0xec(%rbp)
movl $0x6, -0xf0(%rbp)
movl $0x4, -0x114(%rbp)
cmpl $0x4, -0x14(%rbp)
jge 0x409876
movl -0x14(%rbp), %eax
movl %eax, -0x114(%rbp)
movl $0x0, -0x118(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x5, -0x30(%rbp)
jge 0x409913
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
cvtsi2sdl -0x14(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
cvtsi2sdl -0x30(%rbp), %xmm1
movsd 0x182776(%rip), %xmm0   # 0x58c030
callq 0x4b0d10
movaps %xmm0, %xmm1
movsd -0x150(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq -0x30(%rbp), %rax
movl %ecx, -0x110(%rbp,%rax,4)
movslq -0x30(%rbp), %rax
movl -0x110(%rbp,%rax,4), %eax
cmpl -0x114(%rbp), %eax
jg 0x409903
movl -0x114(%rbp), %ecx
movslq -0x30(%rbp), %rax
movl %ecx, -0x110(%rbp,%rax,4)
jmp 0x409913
jmp 0x409905
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x409887
cmpl $0x5, -0x30(%rbp)
jne 0x409939
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
movl -0x114(%rbp), %ecx
movslq -0x30(%rbp), %rax
movl %ecx, -0x110(%rbp,%rax,4)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movl -0x54(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x158(%rbp)
movq %rcx, %rsp
movq %rax, -0x128(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0x118(%rbp), %eax
jge 0x40a01d
movslq -0x11c(%rbp), %rax
movl -0x110(%rbp,%rax,4), %eax
movl %eax, -0x130(%rbp)
movl -0x14(%rbp), %eax
subl -0x130(%rbp), %eax
movl %eax, -0x134(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x4099b5
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x130(%rbp), %eax
jge 0x409af5
movq -0x148(%rbp), %rax
movl -0x70(%rbp), %ecx
addl -0x30(%rbp), %ecx
movl %ecx, -0x138(%rbp)
movq -0x8(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x200c19(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, (%rcx)
movq -0x8(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x8(%rcx), %xmm0
movq 0x200bf2(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x8(%rcx)
movq -0x8(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x200bca(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x10(%rcx)
movq -0x10(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x200bab(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, (%rcx)
movq -0x10(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x8(%rcx), %xmm0
movq 0x200b84(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x8(%rcx)
movq -0x10(%rbp), %rcx
movslq -0x138(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x200b5c(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x10(%rcx)
movl -0x138(%rbp), %edx
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x4099c3
movq 0x200b1c(%rip), %rdi    # 0x60a618
movq 0x200b1d(%rip), %rsi    # 0x60a620
movl -0x130(%rbp), %edx
leaq -0x90(%rbp), %r9
leaq -0xe0(%rbp), %rax
movl $0x1, %ecx
leaq -0x50(%rbp), %r8
subq $0x10, %rsp
movq %rax, (%rsp)
callq 0x4070f0
addq $0x10, %rsp
cmpl $0x0, -0x11c(%rbp)
jne 0x409b54
movsd -0x50(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rdi
movq 0x200a91(%rip), %rsi    # 0x60a5f0
movl -0x14(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xe0(%rbp), %r8
callq 0x4061b0
movq -0x158(%rbp), %rcx
movsd 0x200a04(%rip), %xmm0   # 0x60a588
movsd 0x18247c(%rip), %xmm1   # 0x58c008
subsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movq 0x200a51(%rip), %rdi    # 0x60a5f0
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movsd -0xe8(%rbp), %xmm0
movl 0x10(%rbp), %r9d
leaq -0x48(%rbp), %r8
callq 0x4095f0
movl %eax, -0x12c(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x409c95
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x70(%rbp)
cmpl $0x3, -0x70(%rbp)
jge 0x409c93
movslq -0x70(%rbp), %rax
movsd -0x90(%rbp,%rax,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x70(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x409be2
jmp 0x409c95
movsd 0x18236b(%rip), %xmm0   # 0x58c008
addsd 0x2008e3(%rip), %xmm0   # 0x60a588
movsd %xmm0, -0xe8(%rbp)
movl $0x0, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
cmpl -0xec(%rbp), %eax
jge 0x409fc9
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x409df9
movq -0x148(%rbp), %rax
movq -0x158(%rbp), %rcx
movslq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x34(%rbp)
movq -0x8(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x200903(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, (%rcx)
movq -0x8(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x8(%rcx), %xmm0
movq 0x2008df(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x8(%rcx)
movq -0x8(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x2008ba(%rip), %rcx    # 0x60a618
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x10(%rcx)
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x20089e(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, (%rcx)
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x8(%rcx), %xmm0
movq 0x20087a(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x8(%rcx)
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x200855(%rip), %rcx    # 0x60a620
movslq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x10(%rcx)
movl -0x34(%rbp), %edx
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x409cd7
movq 0x200818(%rip), %rdi    # 0x60a618
movq 0x200819(%rip), %rsi    # 0x60a620
movl -0x12c(%rbp), %edx
leaq -0x90(%rbp), %r9
leaq -0xe0(%rbp), %rax
movl $0x1, %ecx
leaq -0x50(%rbp), %r8
subq $0x10, %rsp
movq %rax, (%rsp)
callq 0x4070f0
addq $0x10, %rsp
movq -0x8(%rbp), %rdi
movq 0x2007b0(%rip), %rsi    # 0x60a5f0
movl -0x14(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xe0(%rbp), %r8
callq 0x4061b0
movq -0x158(%rbp), %rcx
movq 0x20078c(%rip), %rdi    # 0x60a5f0
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movsd -0xe8(%rbp), %xmm0
movl 0x10(%rbp), %r9d
leaq -0x48(%rbp), %r8
callq 0x4095f0
movl %eax, -0x12c(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x409f5a
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x70(%rbp)
cmpl $0x3, -0x70(%rbp)
jge 0x409f58
movslq -0x70(%rbp), %rax
movsd -0x90(%rbp,%rax,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x70(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movslq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x409ea7
jmp 0x409f5a
movl -0x12c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x409fb3
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x409fa4
movq -0x148(%rbp), %rcx
movq -0x158(%rbp), %rax
movslq -0x70(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movslq -0x70(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x409f97
jmp 0x409fa4
jmp 0x409f99
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x409f6c
movl -0x70(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jne 0x409fb1
jmp 0x409fc9
jmp 0x409fb3
jmp 0x409fb5
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x409cb7
movl -0x30(%rbp), %eax
cmpl -0x134(%rbp), %eax
jge 0x409ff3
movl -0x30(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x134(%rbp), %eax
jle 0x409ff1
movl -0x134(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x40a002
movl -0x30(%rbp), %eax
cmpl -0x134(%rbp), %eax
jl 0x40a000
jmp 0x40a007
jmp 0x40a002
jmp 0x4099b3
jmp 0x40a009
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x409977
movsd -0x40(%rbp), %xmm0
movq -0x60(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nop