// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/McLachlan.c
// Function: rmsd_mclachlan
double rmsd_mclachlan(double *x1, double *x2, double *wt1, int n)
{
    
  int i=0,j=0,m=0, ncoord=3*n;
  double cent1[3], cent2[3], rm[3][3];
  double tmpcent[3];
  double rmsd;

  double tmpatom1[ncoord], *x=x1, *t=tmpatom1;
  for(i=0; i<ncoord; i++){*t=*x; x++; t++;}

  if(DBG){
    double sum=0;
    for(i=0; i<n; i++)sum+=wt1[i];
    printf("Average mass: %.2f\n", sum/n);
  }

  // compute centre of masses for the reference
  // and the mobile proteins    
  center_of_mass(cent1,x1,n,wt1);
  center_of_mass(cent2,x2,n,wt1);
  
  if(DBG){
    printf("Centre of Mass for str1\n");
    printf("\t%.4f %.4f %.4f\n",cent1[0],cent1[1],cent1[2]);
    printf("Centre of Mass for str2\n");
    printf("\t%.4f %.4f %.4f\n",cent2[0],cent2[1],cent2[2]);
  }
  
  // centre both structures in their centres of masses
  tmpcent[0] = -cent1[0];
  tmpcent[1] = -cent1[1];
  tmpcent[2] = -cent1[2];
  
  TranslateVector(tmpatom1,tmpcent,n);
  
  tmpcent[0] = -cent2[0];
  tmpcent[1] = -cent2[1];
  tmpcent[2] = -cent2[2];
  
  TranslateVector(x2,tmpcent,n);
    
  // compute the superposition
  matfit(tmpatom1,x2,rm,n,wt1,1);
  
  // Print rotation matrix
  if(DBG){
    printf("Rotation Matrix\n");
    for (i=0;i<3;i++){
      printf("\t");
      for (j=0;j<3;j++)printf("%.4f ",rm[i][j]);
      printf("\n");
    }
  }
 
  for (i=0;i<n;i++){  
    Apply3Matrix2dot(x2+m,rm);
    m+=3;
  }
  TranslateVector(x2,cent1,n);
    
  if(DBG){
    printf("Translation vector (between Centres of masses)\n");
    printf("\t%.4f %.4f %.4f\n",cent1[0]-cent2[0],
	   cent1[1]-cent2[1],cent1[2]-cent2[2]);
  }
  
  // computes weighted rmsd
  rmsd=rmsd_w(x1,x2,n,wt1);
  
  if(DBG)printf("\t mass-weighted RMS: %.4f\n", rmsd);
  
  
  return (rmsd);
  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rsp, -0x58(%rbp)
movq %rcx, -0x30(%rbp)
leal (%rcx,%rcx,2), %eax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
movq %rsp, %r13
subq %rcx, %r13
movq %r13, %rsp
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpl %ecx, %eax
je 0x48606
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%r13,%rcx,8)
incq %rcx
jmp 0x485f0
leaq -0x190(%rbp), %rdi
movq %r15, %rsi
movq -0x30(%rbp), %r12
movl %r12d, %edx
movq %rbx, %rcx
callq 0x48fe6
leaq -0x260(%rbp), %rdi
movq %r14, %rsi
movl %r12d, %edx
movq %rbx, %rcx
callq 0x48fe6
movaps 0x2a85(%rip), %xmm1     # 0x4b0c0
leaq -0x190(%rbp), %rax
movaps (%rax), %xmm0
xorps %xmm1, %xmm0
leaq -0x240(%rbp), %rsi
movaps %xmm0, (%rsi)
movsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm0
movlps %xmm0, 0x10(%rsi)
movq %r13, %rdi
movl %r12d, %edx
callq 0x4906c
leaq -0x260(%rbp), %rax
movapd (%rax), %xmm0
movapd 0x2a44(%rip), %xmm1     # 0x4b0c0
xorpd %xmm1, %xmm0
leaq -0x240(%rbp), %rsi
movapd %xmm0, (%rsi)
movsd 0x10(%rax), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, 0x10(%rsi)
movq %r14, %rdi
movl %r12d, %edx
callq 0x4906c
cmpl $0x2, %r12d
jge 0x487c2
xorl %eax, %eax
movq -0x30(%rbp), %rcx
testl %ecx, %ecx
movl $0x0, %r12d
cmovgl %ecx, %r12d
leaq -0x2f0(%rbp), %rcx
xorl %edx, %edx
cmpl %r12d, %edx
je 0x48744
movsd (%r14,%rax,8), %xmm0
movsd 0x8(%r14,%rax,8), %xmm1
movsd 0x10(%r14,%rax,8), %xmm2
movq %rcx, %rsi
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x48721
movsd -0x8(%rsi), %xmm3
mulsd %xmm1, %xmm3
movsd -0x10(%rsi), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movsd (%rsi), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, -0x220(%rbp,%rdi,8)
incq %rdi
addq $0x18, %rsi
jmp 0x486e7
movaps -0x220(%rbp), %xmm0
movups %xmm0, (%r14,%rax,8)
movsd -0x210(%rbp), %xmm0
movsd %xmm0, 0x10(%r14,%rax,8)
addq $0x3, %rax
incl %edx
jmp 0x486c9
leaq -0x190(%rbp), %rsi
movq %r14, %rdi
movq -0x30(%rbp), %rdx
callq 0x4906c
movl %r12d, %eax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpq %rax, %rcx
je 0x487a7
movsd (%rbx,%rcx,8), %xmm2
xorl %edx, %edx
cmpl $0x3, %edx
je 0x48796
movsd (%r15,%rdx,8), %xmm3
subsd (%r14,%rdx,8), %xmm3
movapd %xmm2, %xmm4
mulsd %xmm3, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm0
incq %rdx
jmp 0x48770
addq $0x18, %r15
addsd %xmm2, %xmm1
addq $0x18, %r14
incq %rcx
jmp 0x48764
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x488d2
sqrtsd %xmm0, %xmm0
jmp 0x488d7
testq %rbx, %rbx
je 0x488ea
leaq -0xd0(%rbp), %rax
movl -0x30(%rbp), %ecx
addq $0x10, %r13
leaq 0x10(%r14), %rdx
xorl %esi, %esi
movapd 0x28d9(%rip), %xmm6     # 0x4b0c0
cmpq $0x3, %rsi
je 0x489f3
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x48803
andq $0x0, (%rax,%rdi,8)
incq %rdi
jmp 0x487f3
imulq $0x18, %rsi, %rdi
addq %rbp, %rdi
addq $-0xd0, %rdi
movq %rdx, %r8
movq %r13, %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpq %r11, %rcx
je 0x488c6
cmpl $0x2, %esi
je 0x48871
cmpl $0x1, %esi
je 0x48863
testl %esi, %esi
jne 0x488b2
movsd (%rbx,%r11,8), %xmm0
mulsd -0x10(%r9), %xmm0
movupd -0x10(%r8), %xmm1
movupd (%rdi), %xmm2
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm1, %xmm3
addpd %xmm2, %xmm3
movupd %xmm3, (%rdi)
movq %r8, %r12
jmp 0x488a2
movsd (%rbx,%r11,8), %xmm0
mulsd -0x8(%r9), %xmm0
jmp 0x4887c
movsd (%rbx,%r11,8), %xmm0
mulsd (%r9), %xmm0
movupd -0x10(%r8), %xmm1
movupd (%rdi), %xmm2
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm1, %xmm3
addpd %xmm2, %xmm3
movupd %xmm3, (%rdi)
leaq (%r14,%r10,8), %r12
addq $0x10, %r12
mulsd (%r12), %xmm0
addsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%rdi)
addq $0x3, %r10
incq %r11
addq $0x18, %r9
addq $0x18, %r8
jmp 0x4881d
incq %rsi
addq $0x18, %rax
jmp 0x487e7
callq 0x2290
movq -0x58(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x10, %r13
leaq 0x10(%r14), %rax
leaq -0xd0(%rbp), %rcx
xorl %edx, %edx
xorl %esi, %esi
movapd 0x27bb(%rip), %xmm6     # 0x4b0c0
cmpq $0x3, %rdx
je 0x489f3
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x48921
andq $0x0, (%rcx,%rdi,8)
incq %rdi
jmp 0x48911
imulq $0x18, %rdx, %rdi
addq %rbp, %rdi
addq $-0xd0, %rdi
movslq %esi, %r8
movq %r8, %rsi
negq %rsi
leaq (,%r8,8), %r9
addq %r13, %r9
leaq (%rax,%r8,8), %r10
movq -0x30(%rbp), %r11
subl $0x1, %r11d
jb 0x489e4
cmpl $0x2, %edx
je 0x48994
cmpl $0x1, %edx
je 0x4898c
testl %edx, %edx
jne 0x489cf
movsd -0x10(%r9), %xmm0
movupd -0x10(%r10), %xmm1
movupd (%rdi), %xmm2
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm1, %xmm3
addpd %xmm2, %xmm3
movupd %xmm3, (%rdi)
movq %r10, %r12
jmp 0x489bf
movsd -0x8(%r9), %xmm0
jmp 0x48999
movsd (%r9), %xmm0
movupd -0x10(%r10), %xmm1
movupd (%rdi), %xmm2
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm1, %xmm3
addpd %xmm2, %xmm3
movupd %xmm3, (%rdi)
leaq (%r14,%r8,8), %r12
addq $0x10, %r12
mulsd (%r12), %xmm0
addsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%rdi)
addq $0x3, %r8
addq $-0x3, %rsi
addq $0x18, %r9
addq $0x18, %r10
jmp 0x4894b
incq %rdx
addq $0x18, %rcx
negq %rsi
jmp 0x48905
leaq -0x220(%rbp), %rax
xorl %ecx, %ecx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
cmpq $0x3, %rcx
je 0x48a39
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x48a1e
andq $0x0, (%rax,%rsi,8)
incq %rsi
jmp 0x48a0e
imulq $0x18, %rcx, %rsi
addq %rbp, %rsi
addq $-0x220, %rsi           # imm = 0xFDE0
movq %rdx, (%rsi,%rcx,8)
incq %rcx
addq $0x18, %rax
jmp 0x48a06
movsd -0xd0(%rbp), %xmm14
movsd -0xb0(%rbp), %xmm13
movsd -0x90(%rbp), %xmm12
xorl %eax, %eax
cmpq $0x3, %rax
je 0x48a6a
andq $0x0, -0xf0(%rbp,%rax,8)
incq %rax
jmp 0x48a56
movapd %xmm14, %xmm10
addsd %xmm13, %xmm10
addsd %xmm12, %xmm10
xorl %r9d, %r9d
xorpd %xmm7, %xmm7
movb $0x3, %r10b
movsd 0x25bc(%rip), %xmm8     # 0x4b048
movsd 0xf4cb(%rip), %xmm9     # 0x57f60
leaq -0xd0(%rbp), %r12
leaq -0x140(%rbp), %r11
leaq -0x220(%rbp), %r13
xorpd %xmm0, %xmm0
cmpl $0x1e, %r9d
je 0x48fa2
movzbl %r9b, %eax
divb %r10b
movzbl %ah, %eax
testb %al, %al
jne 0x48ae1
xorl %eax, %eax
cmpq $0x3, %rax
je 0x48adc
andq $0x0, -0xf0(%rbp,%rax,8)
incq %rax
jmp 0x48ac8
movapd %xmm8, %xmm0
movupd -0x98(%rbp), %xmm1
movhpd -0xc0(%rbp), %xmm1      # xmm1 = xmm1[0],mem[0]
movupd -0xa8(%rbp), %xmm3
subpd %xmm1, %xmm3
movapd %xmm3, -0x1d0(%rbp)
movsd -0xc8(%rbp), %xmm15
subsd -0xb8(%rbp), %xmm15
movsd %xmm15, -0x1c0(%rbp)
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
movapd %xmm1, -0x170(%rbp)
mulsd %xmm1, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movapd %xmm15, %xmm1
mulsd %xmm15, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm11
ucomisd %xmm11, %xmm9
ja 0x48fa2
movapd %xmm11, %xmm1
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x48ba3
movsd -0xf0(%rbp,%rax,8), %xmm2
mulsd %xmm1, %xmm2
addsd -0x1d0(%rbp,%rax,8), %xmm2
movsd %xmm2, -0xf0(%rbp,%rax,8)
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rax
jmp 0x48b71
ucomisd %xmm7, %xmm0
movapd %xmm3, -0x160(%rbp)
jb 0x48bba
sqrtsd %xmm0, %xmm0
jmp 0x48c48
movq %r9, %r12
movq %r11, %r13
movsd %xmm10, -0x80(%rbp)
movsd %xmm11, -0x78(%rbp)
movsd %xmm12, -0x70(%rbp)
movsd %xmm13, -0x68(%rbp)
movsd %xmm14, -0x60(%rbp)
movapd %xmm15, -0x150(%rbp)
callq 0x2290
movapd -0x150(%rbp), %xmm15
movsd -0x60(%rbp), %xmm14
movsd -0x68(%rbp), %xmm13
movsd -0x70(%rbp), %xmm12
movsd -0x78(%rbp), %xmm11
movsd -0x80(%rbp), %xmm10
movq %r13, %r11
leaq -0x220(%rbp), %r13
movsd 0xf33a(%rip), %xmm9     # 0x57f60
movsd 0x2419(%rip), %xmm8     # 0x4b048
movb $0x3, %r10b
xorpd %xmm7, %xmm7
movq %r12, %r9
leaq -0xd0(%rbp), %r12
movapd 0x2478(%rip), %xmm6     # 0x4b0c0
movapd %xmm8, %xmm1
divsd %xmm0, %xmm1
xorl %eax, %eax
cmpq $0x3, %rax
je 0x48c71
movsd -0xf0(%rbp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp,%rax,8)
incq %rax
jmp 0x48c53
movsd -0x50(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
xorpd %xmm0, %xmm0
movsd -0x40(%rbp), %xmm1
movq %r12, %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x48cbe
movsd -0x50(%rbp,%rcx,8), %xmm4
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x48cb5
movsd (%rax,%rdx,8), %xmm5
mulsd %xmm4, %xmm5
mulsd -0x50(%rbp,%rdx,8), %xmm5
addsd %xmm5, %xmm0
incq %rdx
jmp 0x48c97
incq %rcx
addq $0x18, %rax
jmp 0x48c89
movapd -0x170(%rbp), %xmm4
mulsd %xmm3, %xmm4
movapd -0x160(%rbp), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
mulsd %xmm1, %xmm15
addsd %xmm3, %xmm15
addsd %xmm14, %xmm13
addsd %xmm13, %xmm12
subsd %xmm0, %xmm12
movapd %xmm15, %xmm0
mulsd %xmm15, %xmm0
movapd %xmm12, %xmm1
mulsd %xmm12, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
divsd %xmm0, %xmm12
divsd %xmm0, %xmm15
ucomisd %xmm7, %xmm12
jbe 0x48d40
movapd %xmm15, %xmm0
xorpd %xmm6, %xmm0
maxsd %xmm15, %xmm0
movsd 0xf522(%rip), %xmm1     # 0x58258
ucomisd %xmm0, %xmm1
ja 0x48fa2
movapd %xmm8, %xmm0
subsd %xmm12, %xmm0
movq %r11, %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x48db3
movsd -0x50(%rbp,%rcx,8), %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x48d7f
movsd -0x50(%rbp,%rdx,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%rax,%rdx,8)
incq %rdx
jmp 0x48d65
imulq $0x18, %rcx, %rdx
addq %rbp, %rdx
addq $-0x140, %rdx           # imm = 0xFEC0
movsd (%rdx,%rcx,8), %xmm2
addsd %xmm12, %xmm2
movsd %xmm2, (%rdx,%rcx,8)
mulsd %xmm15, %xmm1
movsd %xmm1, -0x1b0(%rbp,%rcx,8)
incq %rcx
addq $0x18, %rax
jmp 0x48d4f
movsd -0x138(%rbp), %xmm0
movsd -0x1b0(%rbp), %xmm1
movsd -0x108(%rbp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, -0x108(%rbp)
movupd -0x1a8(%rbp), %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
subsd %xmm3, %xmm0
movsd %xmm0, -0x138(%rbp)
movupd -0x118(%rbp), %xmm0
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
subpd %xmm1, %xmm0
movupd %xmm0, -0x118(%rbp)
addpd -0x130(%rbp), %xmm2
movapd %xmm2, -0x130(%rbp)
movq %r11, %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x48e7d
movq %r13, %rdx
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x48e74
xorpd %xmm0, %xmm0
movq %rdx, %rdi
xorl %r8d, %r8d
cmpq $0x3, %r8
je 0x48e58
movsd (%rax,%r8,8), %xmm1
mulsd (%rdi), %xmm1
addsd %xmm1, %xmm0
incq %r8
addq $0x18, %rdi
jmp 0x48e3b
imulq $0x18, %rcx, %rdi
addq %rbp, %rdi
addq $-0x2b0, %rdi           # imm = 0xFD50
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
addq $0x8, %rdx
jmp 0x48e2b
incq %rcx
addq $0x18, %rax
jmp 0x48e20
leaq -0x2b0(%rbp), %rax
movq %r13, %rcx
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x48eb3
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x48ea6
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
jmp 0x48e91
incq %rdx
addq $0x18, %rcx
addq $0x18, %rax
jmp 0x48e89
movq %r11, %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x48f15
movq %r12, %rdx
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x48f0c
xorpd %xmm0, %xmm0
movq %rdx, %rdi
xorl %r8d, %r8d
cmpq $0x3, %r8
je 0x48ef0
movsd (%rax,%r8,8), %xmm1
mulsd (%rdi), %xmm1
addsd %xmm1, %xmm0
incq %r8
addq $0x18, %rdi
jmp 0x48ed3
imulq $0x18, %rcx, %rdi
addq %rbp, %rdi
addq $-0x2b0, %rdi           # imm = 0xFD50
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
addq $0x8, %rdx
jmp 0x48ec3
incq %rcx
addq $0x18, %rax
jmp 0x48eb8
leaq -0x2b0(%rbp), %rax
movq %r12, %rcx
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x48f4b
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x48f3e
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
jmp 0x48f29
incq %rdx
addq $0x18, %rcx
addq $0x18, %rax
jmp 0x48f21
movsd -0xd0(%rbp), %xmm14
movsd -0xb0(%rbp), %xmm13
movapd %xmm14, %xmm1
addsd %xmm13, %xmm1
movsd -0x90(%rbp), %xmm12
addsd %xmm12, %xmm1
movapd %xmm1, %xmm0
subsd %xmm10, %xmm0
movapd %xmm0, %xmm2
xorpd %xmm6, %xmm2
maxsd %xmm0, %xmm2
incl %r9d
ucomisd %xmm2, %xmm9
movapd %xmm11, %xmm0
movapd %xmm1, %xmm10
jbe 0x48aae
leaq -0x300(%rbp), %rax
leaq -0x220(%rbp), %rcx
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x486ae
movq %rax, %rsi
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x48fd9
movsd (%rcx,%rdi,8), %xmm0
movsd %xmm0, (%rsi)
incq %rdi
addq $0x18, %rsi
jmp 0x48fc1
incq %rdx
addq $0x8, %rax
addq $0x18, %rcx
jmp 0x48fb2