// File: /workspace/github_c_makefile_star2_O2/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
movl %edx, %r12d
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
xorl %eax, %eax
cmpq $0x3, %rax
je 0x242c9
andq $0x0, (%r15,%rax,8)
movq (%r14,%rax,8), %rcx
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x242c4
andq $0x0, (%rcx,%rdx,8)
incq %rdx
jmp 0x242b4
incq %rax
jmp 0x242a3
xorl %ebp, %ebp
testl %r12d, %r12d
cmovlel %ebp, %r12d
xorpd %xmm2, %xmm2
cmpq %r12, %rbp
je 0x24363
movapd %xmm2, 0x10(%rsp)
movq 0x8(%rsp), %rax
movslq (%rax,%rbp,4), %rax
imulq $0x70, %rax, %r13
addq (%rsp), %r13
movq %r13, %rdi
callq 0x233c9
cvtss2sd %xmm0, %xmm0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x24351
movsd (%r13,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%r15,%rax,8), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%r15,%rax,8)
movq %rax, %rcx
cmpq $0x3, %rcx
je 0x2434c
movq (%r14,%rax,8), %rdx
movsd (%r13,%rcx,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%rdx,%rcx,8), %xmm2
movsd %xmm2, (%rdx,%rcx,8)
incq %rcx
jmp 0x24328
incq %rax
jmp 0x24304
movapd 0x10(%rsp), %xmm2
addsd %xmm0, %xmm2
incq %rbp
jmp 0x242d6
xorl %eax, %eax
cmpq $0x3, %rax
je 0x24380
movsd (%r15,%rax,8), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x24365
xorpd 0x26d38(%rip), %xmm2    # 0x4b0c0
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x243ce
movq %rax, %rcx
cmpq $0x3, %rcx
je 0x243c0
movq (%r14,%rax,8), %rdx
movsd (%r15,%rax,8), %xmm1
mulsd %xmm2, %xmm1
mulsd (%r15,%rcx,8), %xmm1
addsd (%rdx,%rcx,8), %xmm1
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
jmp 0x24397
movq (%r14,%rax,8), %rcx
addsd (%rcx,%rax,8), %xmm0
incq %rax
jmp 0x2438e
xorl %eax, %eax
movapd 0x26ce8(%rip), %xmm1    # 0x4b0c0
cmpq $0x3, %rax
je 0x24421
movq (%r14,%rax,8), %rcx
movapd %xmm0, %xmm2
subsd (%rcx,%rax,8), %xmm2
movq (%rbx,%rax,8), %rdx
movsd %xmm2, (%rdx,%rax,8)
movq %rax, %rsi
cmpq $0x2, %rsi
je 0x2441c
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
jmp 0x243f7
incq %rax
jmp 0x243d8
leaq 0x2f04e(%rip), %rdi     # 0x53476
callq 0x2090
xorl %r15d, %r15d
pushq $0xa
popq %rbp
leaq 0x2e8ee(%rip), %r14     # 0x52d28
cmpq $0x3, %r15
je 0x2446e
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x24462
movq (%rbx,%r15,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %r14, %rdi
movb $0x1, %al
callq 0x20f0
incq %r12
jmp 0x24443
movl %ebp, %edi
callq 0x2060
incq %r15
jmp 0x2443a
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq