// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/site_dynamics.c
// Function: Eigen_directions
void Eigen_directions(float *d2, float *lambda, float **v,
		      int *site_res, int nres, char *chain_res,
		      struct Normal_Mode NM, int *atomres, int *iref)
{
  /* Compute the matrix M_kl=sum_a 1/w^2_a x^a_ik x^a_jl
     Returns the eigenvalues lambda and eigenvectors v */

  double **matrix=Allocate_mat2_d(3,3);
  int atom_ref[nres], i, j, a, k, l;
  for(i=0; i<nres; i++){
    if(atomres[site_res[i]]>=0){
      atom_ref[i]=iref[atomres[site_res[i]]];
    }else{
      atom_ref[i]=-1;
    }
  }

  for(a=0; a<NM.N_relevant; a++){
    // For each normal mode
    if((NM.select[a]==0)||(NM.sigma2[a]==0))continue;
    float *Mode=NM.Cart[a];
    float w=1./(NM.omega2[a]);

    for(i=0; i<nres; i++){
      if(atom_ref[i]<0)continue;
      float *Mode_i=Mode+3*atom_ref[i];
      for(k=0; k<3; k++){
	float wx=w*Mode_i[k];
	for(j=0; j<nres; j++){
	  if(atom_ref[j]<0)continue;
	  float *Mode_j=Mode+3*atom_ref[j];
	  for(l=0; l<=k; l++){
	    matrix[k][l]+=wx*Mode_j[l];
	  }
	}
      }
    }
  }
  float norm=nres*nres;
  for(k=0; k<3; k++){
    d2[k]=matrix[k][k]/norm;
    for(l=k+1; l<3; l++)matrix[k][l]=matrix[l][k];
  }
  d_Diagonalize(3, matrix, lambda, v, 1);
  for(k=0; k<3; k++)lambda[k]/=norm;
  Empty_matrix_d(matrix, 3);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, -0x2c(%rbp)
movq %rcx, %r15
movq %rdx, -0x48(%rbp)
movq %rsi, %rbx
movq %rdi, -0x40(%rbp)
movq 0xe8(%rbp), %r13
movq 0xe0(%rbp), %r12
movl $0x3, %edi
movl $0x3, %esi
callq 0x49798
movq %rax, %r14
movl -0x2c(%rbp), %esi
movl %esi, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
subq %rdx, %rcx
movq %rcx, %rsp
testl %esi, %esi
jle 0x48a9d
xorl %edx, %edx
movslq (%r15,%rdx,4), %rsi
movslq (%r12,%rsi,4), %rsi
testq %rsi, %rsi
js 0x48a8d
movl (%r13,%rsi,4), %esi
jmp 0x48a92
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x48a79
leaq 0x10(%rbp), %rsi
movslq 0x10(%rsi), %rdx
movq %rdx, -0x38(%rbp)
testq %rdx, %rdx
jle 0x48bae
movq 0xc0(%rsi), %rdx
movq %rdx, -0x68(%rbp)
movq 0x20(%rsi), %rdx
movq %rdx, -0x58(%rbp)
movq 0x28(%rsi), %rdx
movq %rdx, -0x60(%rbp)
movq 0x38(%rsi), %rdx
movq %rdx, -0x50(%rbp)
xorl %r10d, %r10d
xorps %xmm0, %xmm0
movss 0x852d(%rip), %xmm1     # 0x51010
movq -0x68(%rbp), %rdx
cmpl $0x0, (%rdx,%r10,4)
je 0x48ba1
movq -0x60(%rbp), %rdx
movss (%rdx,%r10,4), %xmm2
ucomiss %xmm0, %xmm2
jne 0x48b07
jnp 0x48ba1
cmpl $0x0, -0x2c(%rbp)
jle 0x48ba1
movq -0x50(%rbp), %rdx
movq (%rdx,%r10,8), %r11
movaps %xmm1, %xmm2
movq -0x58(%rbp), %rdx
divss (%rdx,%r10,4), %xmm2
xorl %r15d, %r15d
movl (%rcx,%r15,4), %edx
testl %edx, %edx
js 0x48b99
leaq (%rdx,%rdx,2), %rdx
leaq (%r11,%rdx,4), %rdi
movl $0x1, %r9d
xorl %r13d, %r13d
movss (%rdi,%r13,4), %xmm3
mulss %xmm2, %xmm3
xorl %r12d, %r12d
movl (%rcx,%r12,4), %edx
testl %edx, %edx
js 0x48b85
leaq (%rdx,%rdx,2), %rdx
leaq (%r11,%rdx,4), %r8
movq (%r14,%r13,8), %rsi
xorl %edx, %edx
movss (%r8,%rdx,4), %xmm4
mulss %xmm3, %xmm4
cvtss2sd %xmm4, %xmm4
addsd (%rsi,%rdx,8), %xmm4
movsd %xmm4, (%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %r9
jne 0x48b65
incq %r12
cmpq %rax, %r12
jne 0x48b4f
incq %r13
incq %r9
cmpq $0x3, %r13
jne 0x48b42
incq %r15
cmpq %rax, %r15
jne 0x48b29
incq %r10
cmpq -0x38(%rbp), %r10
jne 0x48ae3
movl -0x2c(%rbp), %eax
imull %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
xorl %eax, %eax
movq -0x40(%rbp), %rdi
movq (%r14,%rax,8), %rcx
movsd (%rcx,%rax,8), %xmm1
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rdi,%rax,4)
cmpq $0x1, %rax
ja 0x48c02
movq %rax, %rdx
movq 0x8(%r14,%rdx,8), %rsi
movsd (%rsi,%rax,8), %xmm1
movsd %xmm1, 0x8(%rcx,%rdx,8)
incq %rdx
cmpq $0x2, %rdx
jne 0x48be9
incq %rax
cmpq $0x3, %rax
jne 0x48bca
movl $0x3, %edi
movq %r14, %rsi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
movl $0x1, %r8d
callq 0x4a4d2
xorl %eax, %eax
movss -0x38(%rbp), %xmm1
movss (%rbx,%rax,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rbx,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x48c2c
movq %r14, %rdi
movl $0x3, %esi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x49642