// File: /workspace/github_c_makefile_star2_O3/asford[P]tmalign/./TMalign.h
// Function: get_score_fast(double**, double**, int, int, int*)
double get_score_fast(double **x, double **y, int x_len, int y_len, int invmap[])
{
    double rms, tmscore, tmscore1, tmscore2;
    int i, j, k;

    k=0;
    for(j=0; j<y_len; j++)
    {
        i=invmap[j];
        if(i>=0)
        {
            r1[k][0]=x[i][0];
            r1[k][1]=x[i][1];
            r1[k][2]=x[i][2];

            r2[k][0]=y[j][0];
            r2[k][1]=y[j][1];
            r2[k][2]=y[j][2];
            
            xtm[k][0]=x[i][0];
            xtm[k][1]=x[i][1];
            xtm[k][2]=x[i][2];
            
            ytm[k][0]=y[j][0];
            ytm[k][1]=y[j][1];
            ytm[k][2]=y[j][2];                  
            
            k++;
        }
        else if(i!=-1)
        {
            PrintErrorAndQuit("Wrong map!\n");
        }       
    }
    Kabsch(r1, r2, k, 1, &rms, t, u);
    
    //evaluate score   
    double di;
	const int len=k;
    double dis[len];    
	double d00=d0_search;
	double d002=d00*d00;
	double d02=d0*d0;
	
    int n_ali=k;
	double xrot[3];
	tmscore=0;
	for(k=0; k<n_ali; k++)
	{
        transform(t, u, &xtm[k][0], xrot);        
        di=dist(xrot, &ytm[k][0]);
        dis[k]=di;
        tmscore += 1/(1+di/d02);
    }
	
   
   
   //second iteration 
    double d002t=d002;
    while(1)
    {
		j=0;
        for(k=0; k<n_ali; k++)
        {            
            if(dis[k]<=d002t)
            {
                r1[j][0]=xtm[k][0];
                r1[j][1]=xtm[k][1];
                r1[j][2]=xtm[k][2];
                
                r2[j][0]=ytm[k][0];
                r2[j][1]=ytm[k][1];
                r2[j][2]=ytm[k][2];
                
                j++;
            }
        }
        //there are not enough feasible pairs, relieve the threshold 
        if(j<3 && n_ali>3)
        {
            d002t += 0.5;
        }
        else
        {
            break;
        }
    }
    
    if(n_ali!=j)
    {
        Kabsch(r1, r2, j, 1, &rms, t, u);
    	tmscore1=0;
    	for(k=0; k<n_ali; k++)
    	{
            transform(t, u, &xtm[k][0], xrot);        
            di=dist(xrot, &ytm[k][0]);
            dis[k]=di;
            tmscore1 += 1/(1+di/d02);
        }
        
        //third iteration
        d002t=d002+1;
       
        while(1)
        {
			j=0;
            for(k=0; k<n_ali; k++)
            {            
                if(dis[k]<=d002t)
                {
                    r1[j][0]=xtm[k][0];
                    r1[j][1]=xtm[k][1];
                    r1[j][2]=xtm[k][2];
                    
                    r2[j][0]=ytm[k][0];
                    r2[j][1]=ytm[k][1];
                    r2[j][2]=ytm[k][2];
                                        
                    j++;
                }
            }
            //there are not enough feasible pairs, relieve the threshold 
            if(j<3 && n_ali>3)
            {
                d002t += 0.5;
            }
            else
            {
                break;
            }
        }

        //evaluate the score
        Kabsch(r1, r2, j, 1, &rms, t, u);
        tmscore2=0;
        for(k=0; k<n_ali; k++)
        {
            transform(t, u, &xtm[k][0], xrot);
            di=dist(xrot, &ytm[k][0]);
            tmscore2 += 1/(1+di/d02);
        }    
    }
    else
    {
        tmscore1=tmscore;
        tmscore2=tmscore;
    }
    
      
    if(tmscore1>=tmscore) tmscore=tmscore1;
    if(tmscore2>=tmscore) tmscore=tmscore2;

    
    return tmscore; // no need to normalize this score because it will not be used for latter scoring
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rax
movq %rdi, %rdx
movq 0x1faba2(%rip), %rdi    # 0x602618
movq 0x1faba3(%rip), %rsi    # 0x602620
testl %ecx, %ecx
jle 0x407b7a
movq 0x1fab54(%rip), %r9     # 0x6025e0
movq 0x1fab55(%rip), %r10    # 0x6025e8
movl %ecx, %ecx
xorl %r11d, %r11d
xorl %ebx, %ebx
movslq (%r8,%r11,4), %r14
testq %r14, %r14
js 0x407b54
movq (%rdx,%r14,8), %r14
movsd (%r14), %xmm0
movslq %ebx, %rbx
movq (%rdi,%rbx,8), %r15
movsd %xmm0, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x10(%r15)
movq (%rax,%r11,8), %r15
movsd (%r15), %xmm0
movq (%rsi,%rbx,8), %r12
movsd %xmm0, (%r12)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x8(%r12)
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%r12)
movsd (%r14), %xmm0
movq (%r9,%rbx,8), %r12
movsd %xmm0, (%r12)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r12)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x10(%r12)
movsd (%r15), %xmm0
movq (%r10,%rbx,8), %r14
movsd %xmm0, (%r14)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x8(%r14)
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%r14)
incl %ebx
jmp 0x407b5e
cmpl $-0x1, %r14d
jne 0x40804e
incq %r11
cmpq %r11, %rcx
jne 0x407a9a
movq 0x1faaa7(%rip), %rdi    # 0x602618
movq 0x1faaa8(%rip), %rsi    # 0x602620
jmp 0x407b7c
xorl %ebx, %ebx
subq $0x8, %rsp
leaq 0x1faac9(%rip), %rax    # 0x602650
leaq 0x1faaa2(%rip), %r9     # 0x602630
leaq -0x58(%rbp), %r8
movl %ebx, %edx
movl $0x1, %ecx
pushq %rax
callq 0x406142
addq $0x10, %rsp
movq %rsp, -0x80(%rbp)
movl %ebx, %r12d
movq %rsp, %r13
leaq 0xf(,%r12,8), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movsd 0x1fa9c1(%rip), %xmm0   # 0x602588
movsd %xmm0, -0x40(%rbp)
movsd 0x1fa9ac(%rip), %xmm0   # 0x602580
mulsd %xmm0, %xmm0
testl %ebx, %ebx
movsd %xmm0, -0x78(%rbp)
jle 0x407c89
movq 0x1fa9f4(%rip), %rbx    # 0x6025e0
movq 0x1fa9f5(%rip), %r14    # 0x6025e8
movsd 0x17c40d(%rip), %xmm1   # 0x584008
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
xorpd %xmm3, %xmm3
xorl %r15d, %r15d
movsd %xmm3, -0x38(%rbp)
movq (%rbx,%r15,8), %rdx
leaq 0x1faa15(%rip), %rdi    # 0x602630
leaq 0x1faa2e(%rip), %rsi    # 0x602650
leaq -0x70(%rbp), %rcx
callq 0x4058ff
movsd -0x38(%rbp), %xmm3
movq (%r14,%r15,8), %rax
movsd -0x70(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movupd -0x68(%rbp), %xmm1
movupd 0x8(%rax), %xmm2
subpd %xmm2, %xmm1
mulpd %xmm1, %xmm1
addsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd %xmm1, (%r13,%r15,8)
mulsd -0x30(%rbp), %xmm1
movsd 0x17c395(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm3
incq %r15
cmpq %r15, %r12
jne 0x407c0b
jmp 0x407c8d
xorpd %xmm3, %xmm3
movsd -0x40(%rbp), %xmm4
mulsd %xmm4, %xmm4
testl %r12d, %r12d
jle 0x407d49
movsd 0x17c371(%rip), %xmm0   # 0x584018
movapd %xmm4, %xmm1
movq 0x1fa92e(%rip), %rax    # 0x6025e0
movq 0x1fa95f(%rip), %rcx    # 0x602618
movq 0x1fa928(%rip), %rsi    # 0x6025e8
xorl %edi, %edi
movq 0x1fa957(%rip), %r8     # 0x602620
xorl %edx, %edx
ucomisd (%r13,%rdi,8), %xmm1
jb 0x407d2d
movq (%rax,%rdi,8), %r9
movsd (%r9), %xmm2
movslq %edx, %rdx
movq (%rcx,%rdx,8), %r10
movsd %xmm2, (%r10)
movsd 0x8(%r9), %xmm2
movsd %xmm2, 0x8(%r10)
movsd 0x10(%r9), %xmm2
movsd %xmm2, 0x10(%r10)
movq (%rsi,%rdi,8), %r9
movsd (%r9), %xmm2
movq (%r8,%rdx,8), %r10
movsd %xmm2, (%r10)
movsd 0x8(%r9), %xmm2
movsd %xmm2, 0x8(%r10)
movsd 0x10(%r9), %xmm2
movsd %xmm2, 0x10(%r10)
incl %edx
incq %rdi
cmpq %rdi, %r12
jne 0x407ccb
cmpl $0x2, %edx
jg 0x407d4b
cmpl $0x4, %r12d
jl 0x407d4b
addsd %xmm0, %xmm1
jmp 0x407cab
xorl %edx, %edx
movapd %xmm3, %xmm1
movapd %xmm3, %xmm0
cmpl %edx, %r12d
je 0x408033
movsd %xmm4, -0x40(%rbp)
movsd %xmm3, -0x38(%rbp)
movq 0x1fa8ab(%rip), %r14    # 0x602618
movq 0x1fa8ac(%rip), %rbx    # 0x602620
subq $0x8, %rsp
leaq 0x1fa8b1(%rip), %r9     # 0x602630
leaq -0x58(%rbp), %r8
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
leaq 0x1fa8bb(%rip), %rax    # 0x602650
pushq %rax
callq 0x406142
addq $0x10, %rsp
testl %r12d, %r12d
jle 0x407e71
movq 0x1fa831(%rip), %rax    # 0x6025e0
movq %rax, -0x50(%rbp)
movq 0x1fa82e(%rip), %rax    # 0x6025e8
movq %rax, -0x48(%rbp)
movsd 0x17c242(%rip), %xmm0   # 0x584008
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
movsd %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rax
movq (%rax,%r15,8), %rdx
leaq 0x1fa842(%rip), %rdi    # 0x602630
leaq 0x1fa85b(%rip), %rsi    # 0x602650
leaq -0x70(%rbp), %rcx
callq 0x4058ff
movq -0x48(%rbp), %rax
movq (%rax,%r15,8), %rax
movsd -0x70(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movupd -0x68(%rbp), %xmm1
movupd 0x8(%rax), %xmm2
subpd %xmm2, %xmm1
mulpd %xmm1, %xmm1
addsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd %xmm1, (%r13,%r15,8)
mulsd -0x88(%rbp), %xmm1
movsd 0x17c1c0(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
incq %r15
cmpq %r15, %r12
jne 0x407dda
jmp 0x407e75
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
testl %r12d, %r12d
jle 0x407ff8
movsd -0x40(%rbp), %xmm2
addsd 0x17c178(%rip), %xmm2   # 0x584008
movsd 0x17c180(%rip), %xmm0   # 0x584018
movq 0x1fa741(%rip), %rax    # 0x6025e0
xorl %ecx, %ecx
movq 0x1fa740(%rip), %rsi    # 0x6025e8
xorl %edx, %edx
ucomisd (%r13,%rcx,8), %xmm2
jb 0x407f06
movq (%rax,%rcx,8), %rdi
movsd (%rdi), %xmm1
movslq %edx, %rdx
movq (%r14,%rdx,8), %r8
movsd %xmm1, (%r8)
movsd 0x8(%rdi), %xmm1
movsd %xmm1, 0x8(%r8)
movsd 0x10(%rdi), %xmm1
movsd %xmm1, 0x10(%r8)
movq (%rsi,%rcx,8), %rdi
movsd (%rdi), %xmm1
movq (%rbx,%rdx,8), %r8
movsd %xmm1, (%r8)
movsd 0x8(%rdi), %xmm1
movsd %xmm1, 0x8(%r8)
movsd 0x10(%rdi), %xmm1
movsd %xmm1, 0x10(%r8)
incl %edx
incq %rcx
cmpq %rcx, %r12
jne 0x407eaa
cmpl $0x2, %edx
jg 0x407f22
cmpl $0x4, %r12d
jl 0x407f22
addsd %xmm0, %xmm2
jmp 0x407e98
subq $0x8, %rsp
leaq 0x1fa703(%rip), %r9     # 0x602630
leaq -0x58(%rbp), %r8
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
leaq 0x1fa70d(%rip), %rax    # 0x602650
pushq %rax
callq 0x406142
addq $0x10, %rsp
testl %r12d, %r12d
jle 0x408025
movq 0x1fa683(%rip), %r13    # 0x6025e0
movq 0x1fa684(%rip), %rbx    # 0x6025e8
movsd 0x17c09c(%rip), %xmm0   # 0x584008
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x70(%rbp), %r15
movsd %xmm1, -0x50(%rbp)
movq (%r13,%r14,8), %rdx
leaq 0x1fa69e(%rip), %rdi    # 0x602630
leaq 0x1fa6b7(%rip), %rsi    # 0x602650
movq %r15, %rcx
callq 0x4058ff
movq (%rbx,%r14,8), %rax
movsd -0x70(%rbp), %xmm0
subsd (%rax), %xmm0
movupd -0x68(%rbp), %xmm1
movupd 0x8(%rax), %xmm2
mulsd %xmm0, %xmm0
subpd %xmm2, %xmm1
mulpd %xmm1, %xmm1
addsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
mulsd -0x48(%rbp), %xmm1
movsd 0x17c02b(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movsd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
incq %r14
cmpq %r14, %r12
jne 0x407f81
jmp 0x408029
subq $0x8, %rsp
leaq 0x1fa62d(%rip), %r9     # 0x602630
leaq -0x58(%rbp), %r8
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
leaq 0x1fa635(%rip), %rax    # 0x602650
pushq %rax
callq 0x406142
addq $0x10, %rsp
xorpd %xmm1, %xmm1
movsd -0x38(%rbp), %xmm3
movsd -0x30(%rbp), %xmm0
maxsd %xmm3, %xmm0
maxsd %xmm1, %xmm0
movq -0x80(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17c1f3(%rip), %rdi    # 0x584248
callq 0x404708