// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
testl %ecx, %ecx
jle 0x407c4e
movq 0x1faab7(%rip), %rax    # 0x602618
movq 0x1faab8(%rip), %rdx    # 0x602620
movq 0x1faa71(%rip), %r9     # 0x6025e0
movq 0x1faa72(%rip), %r10    # 0x6025e8
movl %ecx, %ecx
xorl %r11d, %r11d
movq $0x0, -0x30(%rbp)
movslq (%r8,%r11,4), %rbx
testq %rbx, %rbx
js 0x407c37
movq (%rdi,%rbx,8), %rbx
movsd (%rbx), %xmm0
movq -0x30(%rbp), %r12
movslq %r12d, %r12
movq (%rax,%r12,8), %r14
movsd %xmm0, (%r14)
movsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%r14)
movsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%r14)
movq (%rsi,%r11,8), %r14
movsd (%r14), %xmm0
movq (%rdx,%r12,8), %r15
movsd %xmm0, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x10(%r15)
movsd (%rbx), %xmm0
movq (%r9,%r12,8), %r15
movsd %xmm0, (%r15)
movsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%r15)
movsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%r15)
movsd (%r14), %xmm0
movq (%r10,%r12,8), %rbx
movsd %xmm0, (%rbx)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x10(%rbx)
incl %r12d
movq %r12, -0x30(%rbp)
jmp 0x407c40
cmpl $-0x1, %ebx
jne 0x40811d
incq %r11
cmpq %r11, %rcx
jne 0x407b83
jmp 0x407c56
movq $0x0, -0x30(%rbp)
movq 0x1fa9bb(%rip), %rdi    # 0x602618
movq 0x1fa9bc(%rip), %rsi    # 0x602620
subq $0x8, %rsp
leaq 0x1fa9e1(%rip), %rax    # 0x602650
leaq 0x1fa9ba(%rip), %r9     # 0x602630
leaq -0x80(%rbp), %r8
movq -0x30(%rbp), %rbx
movl %ebx, %edx
movl $0x1, %ecx
pushq %rax
callq 0x406168
addq $0x10, %rsp
movq %rsp, -0x88(%rbp)
movl %ebx, %r13d
movq %rsp, %r12
leaq 0xf(,%r13,8), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movsd 0x1fa8d2(%rip), %xmm0   # 0x602588
movsd %xmm0, -0x48(%rbp)
movsd 0x1fa8bd(%rip), %xmm0   # 0x602580
mulsd %xmm0, %xmm0
testl %ebx, %ebx
movsd %xmm0, -0x78(%rbp)
jle 0x407d77
movq 0x1fa905(%rip), %rbx    # 0x6025e0
movq 0x1fa906(%rip), %r14    # 0x6025e8
movsd 0x17c31e(%rip), %xmm1   # 0x584008
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
xorpd %xmm2, %xmm2
xorl %r15d, %r15d
movsd %xmm2, -0x40(%rbp)
movq (%rbx,%r15,8), %rdx
leaq 0x1fa926(%rip), %rdi    # 0x602630
leaq 0x1fa93f(%rip), %rsi    # 0x602650
leaq -0x70(%rbp), %rcx
callq 0x4058ff
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
movsd -0x40(%rbp), %xmm2
mulpd %xmm1, %xmm1
addsd %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd %xmm1, (%r12,%r15,8)
mulsd -0x38(%rbp), %xmm1
movsd 0x17c2a7(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %r15
cmpq %r15, %r13
jne 0x407cfa
jmp 0x407d7b
xorpd %xmm2, %xmm2
movsd -0x48(%rbp), %xmm3
mulsd %xmm3, %xmm3
movapd %xmm3, %xmm0
movq -0x30(%rbp), %r11
testl %r11d, %r11d
jle 0x407e20
movq 0x1fa844(%rip), %rax    # 0x6025e0
movq 0x1fa875(%rip), %rcx    # 0x602618
movq 0x1fa83e(%rip), %rsi    # 0x6025e8
xorl %edi, %edi
movq 0x1fa86d(%rip), %r8     # 0x602620
xorl %edx, %edx
ucomisd (%r12,%rdi,8), %xmm0
jb 0x407e16
movq (%rax,%rdi,8), %r9
movsd (%r9), %xmm1
movslq %edx, %rdx
movq (%rcx,%rdx,8), %r10
movsd %xmm1, (%r10)
movsd 0x8(%r9), %xmm1
movsd %xmm1, 0x8(%r10)
movsd 0x10(%r9), %xmm1
movsd %xmm1, 0x10(%r10)
movq (%rsi,%rdi,8), %r9
movsd (%r9), %xmm1
movq (%r8,%rdx,8), %r10
movsd %xmm1, (%r10)
movsd 0x8(%r9), %xmm1
movsd %xmm1, 0x8(%r10)
movsd 0x10(%r9), %xmm1
movsd %xmm1, 0x10(%r10)
incl %edx
incq %rdi
cmpq %rdi, %r13
jne 0x407db5
jmp 0x407e22
xorl %edx, %edx
cmpl $0x2, %edx
jg 0x407e3a
cmpl $0x4, %r11d
jl 0x407e3a
addsd 0x17c1e3(%rip), %xmm0   # 0x584018
jmp 0x407d8c
movapd %xmm2, %xmm1
movapd %xmm2, %xmm0
cmpl %edx, %r11d
je 0x4080ff
movsd %xmm3, -0x48(%rbp)
movsd %xmm2, -0x40(%rbp)
movq 0x1fa7bc(%rip), %r14    # 0x602618
movq 0x1fa7bd(%rip), %r15    # 0x602620
subq $0x8, %rsp
leaq 0x1fa7c2(%rip), %r9     # 0x602630
leaq -0x80(%rbp), %r8
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %ecx
leaq 0x1fa7cc(%rip), %rax    # 0x602650
pushq %rax
movq %r11, %rbx
callq 0x406168
addq $0x10, %rsp
testl %ebx, %ebx
jle 0x407f66
movq 0x1fa740(%rip), %rax    # 0x6025e0
movq %rax, -0x50(%rbp)
movq 0x1fa73d(%rip), %rax    # 0x6025e8
movq %rax, -0x98(%rbp)
movsd 0x17c14e(%rip), %xmm0   # 0x584008
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq (%rax,%rbx,8), %rdx
leaq 0x1fa74f(%rip), %rdi    # 0x602630
leaq 0x1fa768(%rip), %rsi    # 0x602650
leaq -0x70(%rbp), %rcx
callq 0x4058ff
movq -0x98(%rbp), %rax
movq (%rax,%rbx,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, (%r12,%rbx,8)
mulsd -0x90(%rbp), %xmm1
movsd 0x17c0cb(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
incq %rbx
cmpq %rbx, %r13
jne 0x407ecd
jmp 0x407f6a
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x48(%rbp), %xmm1
addsd 0x17c08c(%rip), %xmm1   # 0x584008
movq -0x30(%rbp), %r10
movsd 0x17c090(%rip), %xmm2   # 0x584018
testl %r10d, %r10d
jle 0x408004
movq 0x1fa64c(%rip), %rax    # 0x6025e0
xorl %ecx, %ecx
movq 0x1fa64b(%rip), %rsi    # 0x6025e8
xorl %edx, %edx
ucomisd (%r12,%rcx,8), %xmm1
jb 0x407ffa
movq (%rax,%rcx,8), %rdi
movsd (%rdi), %xmm0
movslq %edx, %rdx
movq (%r14,%rdx,8), %r8
movsd %xmm0, (%r8)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%r8)
movsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%r8)
movq (%rsi,%rcx,8), %rdi
movsd (%rdi), %xmm0
movq (%r15,%rdx,8), %r8
movsd %xmm0, (%r8)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%r8)
movsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%r8)
incl %edx
incq %rcx
cmpq %rcx, %r13
jne 0x407f9f
jmp 0x408006
xorl %edx, %edx
cmpl $0x2, %edx
jg 0x40801a
cmpl $0x4, %r10d
jl 0x40801a
addsd %xmm2, %xmm1
jmp 0x407f88
subq $0x8, %rsp
leaq 0x1fa60b(%rip), %r9     # 0x602630
leaq -0x80(%rbp), %r8
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %ecx
leaq 0x1fa615(%rip), %rax    # 0x602650
pushq %rax
movq %r10, %rbx
callq 0x406168
addq $0x10, %rsp
testl %ebx, %ebx
jle 0x4080f1
movq 0x1fa589(%rip), %r12    # 0x6025e0
movq 0x1fa58a(%rip), %rbx    # 0x6025e8
movsd 0x17bfa2(%rip), %xmm0   # 0x584008
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x70(%rbp), %r15
movsd %xmm1, -0x30(%rbp)
movq (%r12,%r14,8), %rdx
leaq 0x1fa5a5(%rip), %rdi    # 0x602630
leaq 0x1fa5be(%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 -0x50(%rbp), %xmm1
movsd 0x17bf32(%rip), %xmm0   # 0x584008
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
incq %r14
cmpq %r14, %r13
jne 0x40807b
jmp 0x4080f5
xorpd %xmm1, %xmm1
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm0
maxsd %xmm2, %xmm0
maxsd %xmm1, %xmm0
movq -0x88(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17c134(%rip), %rdi    # 0x584258
callq 0x404708