// File: /workspace/github_c_makefile_star2_O3/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 $0x2c8, %rsp            # imm = 0x2C8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rsp, -0x38(%rbp)
leal (%rcx,%rcx,2), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %r12
subq %rdx, %r12
movq %r12, %rsp
movq %rcx, -0x30(%rbp)
testl %ecx, %ecx
jle 0x4eaab
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
shlq $0x3, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x21b0
leaq -0x1c0(%rbp), %rdi
movq %r15, %rsi
movq -0x30(%rbp), %r13
movl %r13d, %edx
movq %rbx, %rcx
callq 0x4f424
leaq -0x1a0(%rbp), %rdi
movq %r14, %rsi
movl %r13d, %edx
movq %rbx, %rcx
callq 0x4f424
movsd 0x760f(%rip), %xmm6     # 0x560f0
testl %r13d, %r13d
jle 0x4eb7e
movapd -0x1c0(%rbp), %xmm1
movsd -0x1b0(%rbp), %xmm2
leaq 0x10(%r12), %rax
movl %r13d, %ecx
movupd -0x10(%rax), %xmm0
subpd %xmm1, %xmm0
movupd %xmm0, -0x10(%rax)
movsd (%rax), %xmm0
subsd %xmm2, %xmm0
movsd %xmm0, (%rax)
addq $0x18, %rax
decl %ecx
jne 0x4eb02
movsd %xmm2, -0x78(%rbp)
movapd %xmm1, -0x150(%rbp)
movapd -0x1a0(%rbp), %xmm0
movsd -0x190(%rbp), %xmm1
leaq 0x10(%r14), %rax
movq -0x30(%rbp), %rcx
movupd -0x10(%rax), %xmm2
subpd %xmm0, %xmm2
movupd %xmm2, -0x10(%rax)
movsd (%rax), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rax)
addq $0x18, %rax
decl %ecx
jne 0x4eb49
cmpl $0x1, -0x30(%rbp)
jne 0x4eb87
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r12
jmp 0x4f2e5
movq -0x38(%rbp), %r12
jmp 0x4f3f6
testq %rbx, %rbx
je 0x4ec7b
movl -0x30(%rbp), %eax
addq $0x10, %r12
leaq 0x10(%r14), %rcx
xorl %edx, %edx
xorpd %xmm0, %xmm0
leaq (%rdx,%rdx,2), %rsi
leaq -0xf0(,%rsi,8), %rsi
addq %rbp, %rsi
movupd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %rcx, %rdi
movq %r12, %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpl $0x2, %edx
je 0x4ec12
cmpl $0x1, %edx
je 0x4ec04
testl %edx, %edx
jne 0x4ec51
movsd (%rbx,%r9,8), %xmm1
mulsd -0x10(%r8), %xmm1
movupd -0x10(%rdi), %xmm2
movupd (%rsi), %xmm3
movapd %xmm1, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
mulpd %xmm2, %xmm4
addpd %xmm3, %xmm4
movupd %xmm4, (%rsi)
movq %rdi, %r11
jmp 0x4ec42
movsd (%rbx,%r9,8), %xmm1
mulsd -0x8(%r8), %xmm1
jmp 0x4ec1d
movsd (%rbx,%r9,8), %xmm1
mulsd (%r8), %xmm1
movupd -0x10(%rdi), %xmm2
movupd (%rsi), %xmm3
movapd %xmm1, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
mulpd %xmm2, %xmm4
addpd %xmm3, %xmm4
movupd %xmm4, (%rsi)
leaq (%r14,%r10,8), %r11
addq $0x10, %r11
mulsd (%r11), %xmm1
addsd 0x10(%rsi), %xmm1
movsd %xmm1, 0x10(%rsi)
addq $0x3, %r10
incq %r9
addq $0x18, %r8
addq $0x18, %rdi
cmpq %r9, %rax
jne 0x4ebc8
incq %rdx
cmpq $0x3, %rdx
jne 0x4eba1
jmp 0x4ed4d
addq $0x10, %r12
leaq 0x10(%r14), %rax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
leaq (%rcx,%rcx,2), %rsi
leaq -0xf0(,%rsi,8), %rsi
addq %rbp, %rsi
movupd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movslq %edx, %rdx
leaq (%r12,%rdx,8), %rdi
leaq (%rax,%rdx,8), %r8
movq -0x30(%rbp), %r9
cmpl $0x2, %ecx
je 0x4ecf2
cmpl $0x1, %ecx
je 0x4eceb
testl %ecx, %ecx
jne 0x4ed2b
movsd -0x10(%rdi), %xmm1
movupd -0x10(%r8), %xmm2
movupd (%rsi), %xmm3
movapd %xmm1, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
mulpd %xmm2, %xmm4
addpd %xmm3, %xmm4
movupd %xmm4, (%rsi)
movq %r8, %r10
jmp 0x4ed1c
movsd -0x8(%rdi), %xmm1
jmp 0x4ecf6
movsd (%rdi), %xmm1
movupd -0x10(%r8), %xmm2
movupd (%rsi), %xmm3
movapd %xmm1, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
mulpd %xmm2, %xmm4
addpd %xmm3, %xmm4
movupd %xmm4, (%rsi)
leaq (%r14,%rdx,8), %r10
addq $0x10, %r10
mulsd (%r10), %xmm1
addsd 0x10(%rsi), %xmm1
movsd %xmm1, 0x10(%rsi)
addq $0x3, %rdx
addq $0x18, %rdi
addq $0x18, %r8
decl %r9d
jne 0x4ecb5
incq %rcx
cmpq $0x3, %rcx
jne 0x4ec8b
leaq -0x250(%rbp), %rax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movupd %xmm0, -0x250(%rbp,%rcx)
movq $0x0, -0x240(%rbp,%rcx)
movq %rdx, (%rax)
addq $0x18, %rcx
addq $0x20, %rax
cmpq $0x48, %rcx
jne 0x4ed64
leaq -0xf0(%rbp), %r10
movsd (%r10), %xmm15
movsd 0x20(%r10), %xmm14
movapd %xmm15, %xmm11
addsd %xmm14, %xmm11
movsd 0x40(%r10), %xmm13
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
addsd %xmm13, %xmm11
xorpd %xmm7, %xmm7
xorl %r9d, %r9d
movsd 0x2376(%rip), %xmm8     # 0x51148
movsd 0xf215(%rip), %xmm9     # 0x5dff0
movapd 0x22ac(%rip), %xmm10    # 0x51090
leaq -0x140(%rbp), %r11
leaq -0x250(%rbp), %r12
leaq -0x2a0(%rbp), %r13
xorpd %xmm12, %xmm12
imull $-0x55, %r9d, %eax
movapd %xmm12, %xmm0
cmpb $0x55, %al
ja 0x4ee21
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movapd %xmm8, %xmm0
movupd -0xb8(%rbp), %xmm1
movhpd -0xe0(%rbp), %xmm1      # xmm1 = xmm1[0],mem[0]
movupd -0xc8(%rbp), %xmm4
subpd %xmm1, %xmm4
movapd %xmm4, -0x200(%rbp)
movsd -0xe8(%rbp), %xmm3
subsd -0xd8(%rbp), %xmm3
movsd %xmm3, -0x1f0(%rbp)
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
movapd %xmm5, %xmm1
mulsd %xmm5, %xmm1
movapd %xmm4, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm1, %xmm2
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
xorps %xmm12, %xmm12
sqrtsd %xmm1, %xmm12
ucomisd %xmm12, %xmm9
ja 0x4f298
movapd %xmm12, %xmm1
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd -0x70(%rbp,%rax,8), %xmm2
mulsd %xmm1, %xmm2
addsd -0x200(%rbp,%rax,8), %xmm2
movsd %xmm2, -0x70(%rbp,%rax,8)
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rax
cmpq $0x3, %rax
jne 0x4eeac
movapd %xmm3, -0x180(%rbp)
ucomisd %xmm7, %xmm0
movapd %xmm4, -0x170(%rbp)
movapd %xmm5, -0x160(%rbp)
jb 0x4eefd
sqrtsd %xmm0, %xmm0
jmp 0x4ef9e
movq %r9, %r13
movq %r10, %r12
movsd %xmm11, -0xa0(%rbp)
movsd %xmm12, -0x98(%rbp)
movsd %xmm13, -0x90(%rbp)
movsd %xmm14, -0x88(%rbp)
movsd %xmm15, -0x80(%rbp)
callq 0x22a0
movsd -0x80(%rbp), %xmm15
movsd -0x88(%rbp), %xmm14
movsd -0x90(%rbp), %xmm13
movsd -0x98(%rbp), %xmm12
movsd -0xa0(%rbp), %xmm11
leaq -0x140(%rbp), %r11
movapd 0x2124(%rip), %xmm10    # 0x51090
movsd 0xf07b(%rip), %xmm9     # 0x5dff0
movsd 0x21ca(%rip), %xmm8     # 0x51148
movq %r12, %r10
leaq -0x250(%rbp), %r12
movq %r13, %r9
leaq -0x2a0(%rbp), %r13
xorpd %xmm7, %xmm7
movsd 0x7152(%rip), %xmm6     # 0x560f0
movapd %xmm8, %xmm1
divsd %xmm0, %xmm1
xorl %eax, %eax
movsd -0x70(%rbp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x4efa9
movsd -0x50(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
xorpd %xmm0, %xmm0
movsd -0x40(%rbp), %xmm1
movq %r10, %rax
xorl %ecx, %ecx
movsd -0x50(%rbp,%rcx,8), %xmm4
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm5
mulsd %xmm4, %xmm5
mulsd -0x50(%rbp,%rdx,8), %xmm5
addsd %xmm5, %xmm0
incq %rdx
cmpq $0x3, %rdx
jne 0x4efe2
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4efda
movapd -0x160(%rbp), %xmm4
mulsd %xmm3, %xmm4
movapd -0x170(%rbp), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movapd -0x180(%rbp), %xmm4
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
addsd %xmm15, %xmm14
addsd %xmm14, %xmm13
subsd %xmm0, %xmm13
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm13, %xmm1
mulsd %xmm13, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
divsd %xmm0, %xmm13
divsd %xmm0, %xmm4
ucomisd %xmm7, %xmm13
jbe 0x4f092
movapd %xmm4, %xmm0
xorpd %xmm10, %xmm0
maxsd %xmm4, %xmm0
movsd 0xf260(%rip), %xmm1     # 0x5e2e8
ucomisd %xmm0, %xmm1
ja 0x4f298
movapd %xmm8, %xmm0
subsd %xmm13, %xmm0
movq %r11, %rax
xorl %ecx, %ecx
movsd -0x50(%rbp,%rcx,8), %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
xorl %edx, %edx
movsd -0x50(%rbp,%rdx,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%rax,%rdx,8)
incq %rdx
cmpq $0x3, %rdx
jne 0x4f0b1
leaq (%rcx,%rcx,2), %rdx
leaq -0x140(,%rdx,8), %rdx
addq %rbp, %rdx
movsd (%rdx,%rcx,8), %xmm2
addsd %xmm13, %xmm2
movsd %xmm2, (%rdx,%rcx,8)
mulsd %xmm4, %xmm1
movsd %xmm1, -0x1e0(%rbp,%rcx,8)
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4f0a1
movsd -0x138(%rbp), %xmm0
movsd -0x1e0(%rbp), %xmm1
movsd -0x108(%rbp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, -0x108(%rbp)
movupd -0x1d8(%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
movq %r12, %rdx
xorl %esi, %esi
xorpd %xmm0, %xmm0
movq %rdx, %rdi
xorl %r8d, %r8d
movsd (%rax,%r8,8), %xmm1
mulsd (%rdi), %xmm1
addsd %xmm1, %xmm0
incq %r8
addq $0x18, %rdi
cmpq $0x3, %r8
jne 0x4f17d
leaq (%rcx,%rcx,2), %rdi
leaq -0x2a0(,%rdi,8), %rdi
addq %rbp, %rdi
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
addq $0x8, %rdx
cmpq $0x3, %rsi
jne 0x4f173
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4f16e
movl $0x9, %ecx
movq %r12, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r11, %rax
xorl %ecx, %ecx
movq %r10, %rdx
xorl %esi, %esi
xorpd %xmm0, %xmm0
movq %rdx, %rdi
xorl %r8d, %r8d
movsd (%rax,%r8,8), %xmm1
mulsd (%rdi), %xmm1
addsd %xmm1, %xmm0
incq %r8
addq $0x18, %rdi
cmpq $0x3, %r8
jne 0x4f1e8
leaq (%rcx,%rcx,2), %rdi
leaq -0x2a0(,%rdi,8), %rdi
addq %rbp, %rdi
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
addq $0x8, %rdx
cmpq $0x3, %rsi
jne 0x4f1de
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4f1d9
movl $0x9, %ecx
movq %r10, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movsd -0xf0(%rbp), %xmm15
movsd -0xd0(%rbp), %xmm14
movapd %xmm15, %xmm0
addsd %xmm14, %xmm0
movsd -0xb0(%rbp), %xmm13
addsd %xmm13, %xmm0
movapd %xmm0, %xmm1
subsd %xmm11, %xmm1
movapd %xmm1, %xmm2
xorpd %xmm10, %xmm2
maxsd %xmm1, %xmm2
ucomisd %xmm2, %xmm9
ja 0x4f298
incl %r9d
movapd %xmm0, %xmm11
cmpl $0x1e, %r9d
jne 0x4edfe
leaq -0x2f0(%rbp), %rax
leaq -0x250(%rbp), %rcx
xorl %edx, %edx
movq -0x38(%rbp), %r12
movq -0x30(%rbp), %r8
movq %rax, %rsi
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm0
movsd %xmm0, (%rsi)
incq %rdi
addq $0x18, %rsi
cmpq $0x3, %rdi
jne 0x4f2b5
incq %rdx
addq $0x8, %rax
addq $0x18, %rcx
cmpq $0x3, %rdx
jne 0x4f2b0
testl %r8d, %r8d
jle 0x4f3f6
xorl %eax, %eax
leaq -0x2e0(%rbp), %rcx
xorl %edx, %edx
movsd (%r14,%rax,8), %xmm0
movsd 0x8(%r14,%rax,8), %xmm1
movsd 0x10(%r14,%rax,8), %xmm2
movq %rcx, %rsi
xorl %edi, %edi
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, -0x250(%rbp,%rdi,8)
incq %rdi
addq $0x18, %rsi
cmpq $0x3, %rdi
jne 0x4f309
movaps -0x250(%rbp), %xmm0
movups %xmm0, (%r14,%rax,8)
movsd -0x240(%rbp), %xmm0
movsd %xmm0, 0x10(%r14,%rax,8)
addq $0x3, %rax
incl %edx
cmpl %r8d, %edx
jne 0x4f2f0
testl %r8d, %r8d
jle 0x4f3f6
leaq 0x10(%r14), %rax
movl %r8d, %ecx
movapd -0x150(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movupd -0x10(%rax), %xmm0
addpd %xmm1, %xmm0
movupd %xmm0, -0x10(%rax)
movsd (%rax), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rax)
addq $0x18, %rax
decl %ecx
jne 0x4f384
movl %r8d, %eax
xorpd %xmm6, %xmm6
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movsd (%rbx,%rcx,8), %xmm1
xorl %edx, %edx
movsd (%r15,%rdx,8), %xmm2
subsd (%r14,%rdx,8), %xmm2
movapd %xmm1, %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm3, %xmm6
incq %rdx
cmpl $0x3, %edx
jne 0x4f3ba
addq $0x18, %r15
addsd %xmm1, %xmm0
addq $0x18, %r14
incq %rcx
cmpq %rax, %rcx
jne 0x4f3b3
divsd %xmm0, %xmm6
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm6
jb 0x4f409
xorps %xmm0, %xmm0
sqrtsd %xmm6, %xmm0
jmp 0x4f412
movapd %xmm6, %xmm0
callq 0x22a0
movq %r12, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq