// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/nma.c
// Function: Inertia_tensor_old
int Inertia_tensor_old(atom *atoms, int *atom_ref, int N, double *r_ave,
		       double **corr, double **inertia)
{
  int i, j, k, i_atom;
  double norm_m=0, diag=0;

  for(i=0; i<3; i++){
    r_ave[i]=0;
    for(j=0; j<3; j++)corr[i][j]=0;
  }

  for(i=0; i<N; i++){
    i_atom=atom_ref[i];
    double m=Mass(atoms+i_atom); norm_m+=m;
    double *r=atoms[i_atom].r;
    for(j=0; j<3; j++){
      double mr = m*r[j];   r_ave[j]+= mr;    // center of mass
      for(k=j; k<3; k++)corr[j][k]+=mr*r[k];   // correlation matrix
    }
  }
  for(j=0; j<3; j++)r_ave[j]/=norm_m;

  for(j=0; j<3; j++){
    for(k=j; k<3; k++){
      corr[j][k] -= norm_m*r_ave[j]*r_ave[k];
    }
    diag += corr[j][j];
  }
  for(j=0; j<3; j++){
    inertia[j][j]=diag-corr[j][j];
    for(k=j+1; k<3; k++){
      inertia[j][k]=-corr[j][k];
      inertia[k][j]=inertia[j][k];
    }
  }

  // Printing
  printf("# Inertia tensor:\n");
  for(j=0; j<3; j++){
    for(k=0; k<3; k++)printf("%6.0f ", inertia[j][k]);
    printf("\n");
  }
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
xorl %eax, %eax
xorps %xmm0, %xmm0
xorl %ecx, %ecx
movq %rax, (%r15,%rcx,8)
movq (%r14,%rcx,8), %rsi
movq %rax, 0x10(%rsi)
movups %xmm0, (%rsi)
incq %rcx
cmpq $0x3, %rcx
jne 0x269cf
testl %edx, %edx
jle 0x26a79
movl %edx, %r12d
xorpd %xmm2, %xmm2
xorl %r13d, %r13d
movapd %xmm2, 0x10(%rsp)
movq 0x8(%rsp), %rax
movslq (%rax,%r13,4), %rax
imulq $0x70, %rax, %rbp
addq (%rsp), %rbp
movq %rbp, %rdi
callq 0x25a4d
cvtss2sd %xmm0, %xmm0
xorl %eax, %eax
movsd (%rbp,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%r15,%rax,8), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%r15,%rax,8)
movq (%r14,%rax,8), %rcx
movq %rax, %rdx
movsd (%rbp,%rdx,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%rcx,%rdx,8), %xmm2
movsd %xmm2, (%rcx,%rdx,8)
incq %rdx
cmpq $0x3, %rdx
jne 0x26a3f
incq %rax
cmpq $0x3, %rax
jne 0x26a1e
movapd 0x10(%rsp), %xmm2
addsd %xmm0, %xmm2
incq %r13
cmpq %r12, %r13
jne 0x269f9
jmp 0x26a7d
xorpd %xmm2, %xmm2
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x26a7f
xorpd 0x2a5f0(%rip), %xmm2    # 0x51090
xorps %xmm0, %xmm0
xorl %eax, %eax
movq (%r14,%rax,8), %rcx
movq %rax, %rdx
movsd (%r15,%rax,8), %xmm1
mulsd %xmm2, %xmm1
mulsd (%r15,%rdx,8), %xmm1
addsd (%rcx,%rdx,8), %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq $0x3, %rdx
jne 0x26aac
addsd (%rcx,%rax,8), %xmm0
incq %rax
cmpq $0x3, %rax
jne 0x26aa5
xorl %eax, %eax
movapd 0x2a5a9(%rip), %xmm1    # 0x51090
movq (%r14,%rax,8), %rcx
movapd %xmm0, %xmm2
subsd (%rcx,%rax,8), %xmm2
movq (%rbx,%rax,8), %rdx
movsd %xmm2, (%rdx,%rax,8)
cmpq $0x1, %rax
ja 0x26b29
movq %rax, %rsi
movsd 0x8(%rcx,%rsi,8), %xmm2
xorpd %xmm1, %xmm2
movlpd %xmm2, 0x8(%rdx,%rsi,8)
movq 0x8(%rbx,%rsi,8), %rdi
movlpd %xmm2, (%rdi,%rax,8)
incq %rsi
cmpq $0x2, %rsi
jne 0x26b06
incq %rax
cmpq $0x3, %rax
jne 0x26ae7
leaq 0x329dd(%rip), %rdi     # 0x59516
callq 0x2090
xorl %r15d, %r15d
leaq 0x32280(%rip), %r14     # 0x58dc8
xorl %r12d, %r12d
movq (%rbx,%r15,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %r14, %rdi
movb $0x1, %al
callq 0x20f0
incq %r12
cmpq $0x3, %r12
jne 0x26b4b
movl $0xa, %edi
callq 0x2060
incq %r15
cmpq $0x3, %r15
jne 0x26b48
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq