// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/McLachlan_float.c
// Function: rmsd_mclachlan_f
double rmsd_mclachlan_f(float *x1, float *x2, float *wt1, int n)
{

    int i=0,j=0,m=0;
    double cent1[3], cent2[3], rm[3][3];
    double tmpcent[3];
    double rmsd;

    // 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);

    // centre both structures in their centres of masses
    tmpcent[0] = -1.0 * cent1[0];
    tmpcent[1] = -1.0 * cent1[1];
    tmpcent[2] = -1.0 * cent1[2];

    float *tmpatom1=(float *)malloc(3*n*sizeof(float));
    float *x=tmpatom1, *y=x1;
    for(i=0; i<(3*n); i++){*x=*y; x++; y++;}
    TranslateVector(tmpatom1,tmpcent,n);

    tmpcent[0] = -1.0 * cent2[0];
    tmpcent[1] = -1.0 * cent2[1];
    tmpcent[2] = -1.0 * cent2[2];
    TranslateVector(x2,tmpcent,n);

    // compute the superposition
    matfit(tmpatom1,x2,rm,n,wt1,1);
    free(tmpatom1);

    // Print rotation matrix
    if(DBG){
      double sum=0;
      for(i=0; i<n; i++)sum+=wt1[i];
      printf("Average mass: %.2f\n", sum/n);
      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]);
      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(0){
      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(0)printf("\t mass-weighted RMS: %.4f\n", rmsd);


    return (rmsd);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x70d20
leaq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x70d20
movsd 0x54e1(%rip), %xmm0     # 0x76030
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd 0x54cc(%rip), %xmm0     # 0x76030
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x54b7(%rip), %xmm0     # 0x76030
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
imull $0x3, -0x1c(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
imull $0x3, -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x70c0d
movq -0xf0(%rbp), %rax
movss (%rax), %xmm0
movq -0xe8(%rbp), %rax
movss %xmm0, (%rax)
movq -0xe8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xe8(%rbp)
movq -0xf0(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xf0(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x70bbd
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x70e80
movsd 0x5405(%rip), %xmm0     # 0x76030
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd 0x53f0(%rip), %xmm0     # 0x76030
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x53db(%rip), %xmm0     # 0x76030
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x70e80
movq -0xe0(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %r8
movl $0x1, %r9d
callq 0x70f40
movq -0xe0(%rbp), %rdi
callq 0x1040
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x70ce3
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x71640
movl -0x28(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x70cac
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x70e80
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x71730
movsd %xmm0, -0xd8(%rbp)
movsd -0xd8(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq