// File: /workspace/github_c_makefile_star2_O1/asford[P]tmalign/./TMalign.h
// Function: score_matrix_rmsd(double**, double**, int, int, int*)
void score_matrix_rmsd(  double **x, 
						 double **y, 
						 int x_len,
						 int y_len,
						 int *y2x
						 )
{
	double t[3], u[3][3];
	double rmsd, dij;
	double d01=d0+1.5;
	if(d01 < D0_MIN) d01=D0_MIN;
	double d02=d01*d01;

	double xx[3];
	int i, k=0;
	for(int j=0; j<y_len; j++)
	{
		i=y2x[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];
			
			k++;
		}
	}
	Kabsch(r1, r2, k, 1, &rmsd, t, u);
	//do_rotation(x, xt, x_len, t, u);
	
	
	for(int ii=0; ii<x_len; ii++)
	{		
		transform(t, u, &x[ii][0], xx);
		for(int jj=0; jj<y_len; jj++)
		{
			//dij=dist(&xt[ii][0], &y[jj][0]);   
			dij=dist(xx, &y[jj][0]); 
			score[ii+1][jj+1] = 1.0/(1+dij/d02);
			//	cout << ii+1 << " " << jj+1 << " " << score[ii+1][jj+1]<< endl;
		}
	}		
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movsd 0x1f9aa5(%rip), %xmm0   # 0x602580
addsd 0x17b59d(%rip), %xmm0   # 0x584080
maxsd 0x1f9a7d(%rip), %xmm0   # 0x602568
movsd %xmm0, 0x8(%rsp)
movl %ecx, %r12d
testl %ecx, %ecx
jle 0x408b70
movq 0x1f9b19(%rip), %rax    # 0x602618
movq 0x1f9b1a(%rip), %rcx    # 0x602620
xorl %esi, %esi
xorl %edx, %edx
movslq (%r8,%rsi,4), %rdi
testq %rdi, %rdi
js 0x408b66
movq (%r15,%rdi,8), %rdi
movsd (%rdi), %xmm0
movslq %edx, %rdx
movq (%rax,%rdx,8), %r9
movsd %xmm0, (%r9)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%r9)
movsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%r9)
movq (%r14,%rsi,8), %rdi
movsd (%rdi), %xmm0
movq (%rcx,%rdx,8), %r9
movsd %xmm0, (%r9)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%r9)
movsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%r9)
incl %edx
incq %rsi
cmpq %rsi, %r12
jne 0x408b0a
jmp 0x408b72
xorl %edx, %edx
movq 0x1f9a9f(%rip), %rdi    # 0x602618
movq 0x1f9aa0(%rip), %rsi    # 0x602620
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x78(%rsp), %r8
leaq 0x60(%rsp), %r9
movl $0x1, %ecx
callq 0x406168
testl %ebp, %ebp
jle 0x408cf5
movsd 0x8(%rsp), %xmm10
mulsd %xmm10, %xmm10
movsd 0x60(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movupd 0x28(%rsp), %xmm4
movapd 0x30(%rsp), %xmm5
movupd 0x38(%rsp), %xmm6
movupd 0x68(%rsp), %xmm7
movq 0x1f99b0(%rip), %rax    # 0x602598
movl %ebp, %ecx
movhpd 0x40(%rsp), %xmm4       # xmm4 = xmm4[0],mem[0]
movhpd 0x48(%rsp), %xmm5       # xmm5 = xmm5[0],mem[0]
movhpd 0x50(%rsp), %xmm6       # xmm6 = xmm6[0],mem[0]
movsd 0x17b403(%rip), %xmm8   # 0x584008
movapd %xmm8, %xmm9
divsd %xmm10, %xmm9
xorl %edx, %edx
testl %ebx, %ebx
jle 0x408ce9
movq (%r15,%rdx,8), %rsi
movsd (%rsi), %xmm12
movsd 0x8(%rsi), %xmm13
movapd %xmm12, %xmm14
mulsd %xmm1, %xmm14
addsd %xmm0, %xmm14
movapd %xmm13, %xmm15
mulsd %xmm2, %xmm15
movsd 0x10(%rsi), %xmm10
movapd %xmm10, %xmm11
mulsd %xmm3, %xmm11
addsd %xmm15, %xmm11
addsd %xmm14, %xmm11
unpcklpd %xmm12, %xmm12          # xmm12 = xmm12[0,0]
mulpd %xmm4, %xmm12
addpd %xmm7, %xmm12
unpcklpd %xmm13, %xmm13          # xmm13 = xmm13[0,0]
mulpd %xmm5, %xmm13
unpcklpd %xmm10, %xmm10          # xmm10 = xmm10[0,0]
mulpd %xmm6, %xmm10
addpd %xmm13, %xmm10
addpd %xmm12, %xmm10
movq 0x8(%rax,%rdx,8), %rsi
xorl %edi, %edi
movq (%r14,%rdi,8), %r8
movapd %xmm11, %xmm12
subsd (%r8), %xmm12
mulsd %xmm12, %xmm12
movupd 0x8(%r8), %xmm13
movapd %xmm10, %xmm14
subpd %xmm13, %xmm14
mulpd %xmm14, %xmm14
addsd %xmm14, %xmm12
unpckhpd %xmm14, %xmm14          # xmm14 = xmm14[1,1]
addsd %xmm12, %xmm14
mulsd %xmm9, %xmm14
addsd %xmm8, %xmm14
movapd %xmm8, %xmm12
divsd %xmm14, %xmm12
movsd %xmm12, 0x8(%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %r12
jne 0x408c8f
incq %rdx
cmpq %rcx, %rdx
jne 0x408c11
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq