// File: /workspace/github_c_makefile_star2_O2/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, %ebx
movq %rcx, %r15
movq %rdx, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, -0x40(%rbp)
movq 0xe8(%rbp), %r12
movq 0xe0(%rbp), %r13
pushq $0x3
popq %rdi
movl %edi, %esi
callq 0x43878
movq %rax, %r14
movl %ebx, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
subq %rdx, %rcx
movq %rcx, %rsp
xorl %esi, %esi
testl %ebx, %ebx
movl $0x0, %edx
movl %ebx, -0x34(%rbp)
cmovgl %ebx, %edx
pushq $-0x1
popq %rdi
cmpq %rsi, %rdx
je 0x42bf6
movslq (%r15,%rsi,4), %r8
movslq (%r13,%r8,4), %r9
movl %edi, %r8d
testq %r9, %r9
js 0x42bed
movl (%r12,%r9,4), %r8d
movl %r8d, (%rcx,%rsi,4)
incq %rsi
jmp 0x42bd3
leaq 0x10(%rbp), %r8
movl 0x10(%r8), %esi
movq 0xc0(%r8), %rdi
movq %rdi, -0x70(%rbp)
movq 0x28(%r8), %rdi
movq %rdi, -0x68(%rbp)
movq 0x38(%r8), %rdi
movq %rdi, -0x60(%rbp)
xorl %r10d, %r10d
testl %esi, %esi
cmovlel %r10d, %esi
movq %rsi, -0x30(%rbp)
movq 0x20(%r8), %rsi
movq %rsi, -0x58(%rbp)
xorps %xmm0, %xmm0
movss 0x83d7(%rip), %xmm1     # 0x4b010
cmpq -0x30(%rbp), %r10
je 0x42d03
movq -0x70(%rbp), %rsi
cmpl $0x0, (%rsi,%r10,4)
je 0x42c5f
movq -0x68(%rbp), %rsi
movss (%rsi,%r10,4), %xmm2
ucomiss %xmm0, %xmm2
jne 0x42c64
jp 0x42c64
incq %r10
jmp 0x42c39
movq -0x60(%rbp), %rsi
movq (%rsi,%r10,8), %r13
movaps %xmm1, %xmm2
movq -0x58(%rbp), %rsi
divss (%rsi,%r10,4), %xmm2
xorl %r9d, %r9d
cmpq %rdx, %r9
je 0x42c5f
movl (%rcx,%r9,4), %esi
testl %esi, %esi
js 0x42cfb
imulq $0xc, %rsi, %r11
addq %r13, %r11
xorl %r12d, %r12d
pushq $0x1
popq %r15
cmpq $0x3, %r12
je 0x42cfb
movss (%r11,%r12,4), %xmm3
mulss %xmm2, %xmm3
xorl %edi, %edi
cmpq %rax, %rdi
je 0x42cf3
movl (%rcx,%rdi,4), %esi
testl %esi, %esi
js 0x42cee
leal (%rsi,%rsi,2), %esi
leaq (,%rsi,4), %rbx
addq %r13, %rbx
movq (%r14,%r12,8), %rsi
xorl %r8d, %r8d
cmpq %r8, %r15
je 0x42cee
movss (%rbx,%r8,4), %xmm4
mulss %xmm3, %xmm4
cvtss2sd %xmm4, %xmm4
addsd (%rsi,%r8,8), %xmm4
movsd %xmm4, (%rsi,%r8,8)
incq %r8
jmp 0x42cca
incq %rdi
jmp 0x42ca9
incq %r12
incq %r15
jmp 0x42c97
incq %r9
jmp 0x42c7c
movl -0x34(%rbp), %eax
imull %eax, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
cvtss2sd %xmm0, %xmm0
xorl %eax, %eax
movq -0x50(%rbp), %rbx
movq -0x40(%rbp), %rdi
cmpq $0x3, %rax
je 0x42d5f
movq (%r14,%rax,8), %rcx
movsd (%rcx,%rax,8), %xmm1
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rdi,%rax,4)
movq %rax, %rdx
cmpq $0x2, %rdx
je 0x42d5a
movq 0x8(%r14,%rdx,8), %rsi
movsd (%rsi,%rax,8), %xmm1
movsd %xmm1, 0x8(%rcx,%rdx,8)
incq %rdx
jmp 0x42d3f
incq %rax
jmp 0x42d20
pushq $0x3
popq %rdi
pushq $0x1
popq %r8
movq %r14, %rsi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
callq 0x444de
xorl %eax, %eax
movss -0x30(%rbp), %xmm1
cmpq $0x3, %rax
je 0x42d95
movss (%rbx,%rax,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rbx,%rax,4)
incq %rax
jmp 0x42d7c
pushq $0x3
popq %rsi
movq %r14, %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4372a