// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x36c49
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36c3c
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36c13
jmp 0x36c3e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x36bf6
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x36d53
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x40(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
callq 0x351c0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36d43
movsd -0x58(%rbp), %xmm0
movq -0x60(%rbp), %rax
movslq -0x38(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x36d33
movsd -0x68(%rbp), %xmm0
movq -0x60(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x36cee
jmp 0x36d35
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36cb0
jmp 0x36d45
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x36c50
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36d86
movsd -0x48(%rbp), %xmm1
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36d5a
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36e33
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x36e06
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x36d9d
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36d8d
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36f08
movsd -0x50(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x36ef8
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x36e7c
jmp 0x36efa
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36e3a
leaq 0x4709d(%rip), %rdi     # 0x7dfac
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x36f77
movl $0x0, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x36f5e
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x47073(%rip), %rdi     # 0x7dfbf
movb $0x1, %al
callq 0x10d0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x36f2a
leaq 0x47113(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x36f1d
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nop