// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/nma.c
// Function: Compute_Hessian_ANM
void Compute_Hessian_ANM  (double **Hessian, int N_ref, int *atom_ref,
			  struct interaction *Int_list, int N_int,
			   atom *atoms, int natoms)
{
  int N=3*N_ref;
  int n, i, j;
  int *i_ref=malloc(natoms*sizeof(int));
  for(i=0; i<natoms; i++)i_ref[i]=-1;
  for(i=0; i<N_ref; i++)i_ref[atom_ref[i]]=i;

  // Computing  elements in double precision
  for(i=0; i<N; i++)for(j=0; j<N; j++)Hessian[i][j]=0;
  for(n=0; n<N_int; n++){
    int i1_pdb=Int_list[n].i1, i2_pdb=Int_list[n].i2;
    int i1=3*i_ref[i1_pdb], i2=3*i_ref[i2_pdb], j1, j2;
    if((i1<0)||(i2<0))continue;
    atom *atom1= atoms+i1_pdb, *atom2=atoms+i2_pdb;
    int i1j1, i1j2, i2j1, i2j2;
    double r21[3], h, norm;
    r21[0]=atom2->r[0]-atom1->r[0];
    r21[1]=atom2->r[1]-atom1->r[1];
    r21[2]=atom2->r[2]-atom1->r[2];
    norm=Int_list[n].sec_der/Scalar_product_3_d(r21, r21);

    for(j1=0; j1<3; j1++){
      i1j1 = i1+j1; i2j1=i2+j1;
      for(j2=j1; j2<3; j2++){
	h = r21[j1]*r21[j2]*norm;
	i2j2 =i2+j2; i1j2=i1+j2;
        Hessian[i1j1][i2j2] =-h;
        Hessian[i2j2][i1j1] =-h;
        Hessian[i1j1][i1j2] +=h;
        Hessian[i2j2][i2j1] +=h;
        if(j1!=j2){
          Hessian[i1j2][i2j1] =-h;
          Hessian[i2j1][i1j2] =-h;
          Hessian[i1j2][i1j1]+= h;
          Hessian[i2j1][i2j2]+= h;
        }
      }
    }
  }
  free(i_ref);
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x28(%rsp)
movl %r8d, (%rsp)
movq %rcx, %r15
movq %rdx, %rbp
movl %esi, %r13d
movq %rdi, 0x8(%rsp)
movslq 0x90(%rsp), %rbx
leaq (,%rbx,4), %rdi
callq 0x21e0
movq %rax, %r14
testq %rbx, %rbx
jle 0x23cd9
movl %ebx, %edx
shlq $0x2, %rdx
movq %r14, %rdi
movl $0xff, %esi
callq 0x2110
movq %r14, 0x10(%rsp)
testl %r13d, %r13d
movq 0x8(%rsp), %r12
jle 0x23d3d
leal (%r13,%r13,2), %eax
movl %r13d, %ecx
xorl %edx, %edx
movq 0x10(%rsp), %rdi
movslq (%rbp,%rdx,4), %rsi
movl %edx, (%rdi,%rsi,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x23cf7
testl %r13d, %r13d
movq 0x8(%rsp), %r12
jle 0x23d3d
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
leaq (,%rbx,8), %r13
xorl %r14d, %r14d
movq (%r12,%r14,8), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2110
incq %r14
cmpq %r14, %rbx
jne 0x23d27
movl (%rsp), %eax
testl %eax, %eax
movq 0x10(%rsp), %rdi
jle 0x23f29
movq %r12, %rbx
movl %eax, %r9d
xorl %r10d, %r10d
movq %r15, 0x20(%rsp)
movq %r9, 0x18(%rsp)
imulq $0xc8, %r10, %rax
movslq (%r15,%rax), %rcx
movl (%rdi,%rcx,4), %edx
testl %edx, %edx
js 0x23f1d
movslq 0x4(%r15,%rax), %rsi
movl (%rdi,%rsi,4), %r8d
testl %r8d, %r8d
js 0x23f1d
movq %r10, 0x30(%rsp)
addq %r15, %rax
leaq (%r8,%r8,2), %r15
leaq (%rdx,%rdx,2), %r12
imulq $0x70, %rcx, %rcx
imulq $0x70, %rsi, %rdx
movq 0x28(%rsp), %rsi
movupd (%rsi,%rdx), %xmm0
movupd (%rsi,%rcx), %xmm1
subpd %xmm1, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd 0x10(%rsi,%rdx), %xmm0
subsd 0x10(%rsi,%rcx), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x28(%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r14, %rsi
callq 0x10433
movsd (%rsp), %xmm4
movapd 0x2d29e(%rip), %xmm3    # 0x51090
divsd %xmm0, %xmm4
leaq (,%r12,8), %rax
movq %r12, 0x38(%rsp)
leaq (%rbx,%r12,8), %rcx
leaq (,%r15,8), %rdx
movq %r15, (%rsp)
leaq (%rbx,%r15,8), %rsi
movl $0x18, %edi
movq %r14, %r8
xorl %r9d, %r9d
movq 0x38(%rsp), %r10
addq %r9, %r10
movq (%rsp), %r11
addq %r9, %r11
movq (%rbx,%r10,8), %r14
leaq (%r14,%rax), %r12
addq %rdx, %r14
xorl %r13d, %r13d
movsd 0x40(%rsp,%r9,8), %xmm0
mulsd (%r8,%r13), %xmm0
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm1
movlpd %xmm1, (%r14,%r13)
movq (%rsi,%r13), %rbp
movlpd %xmm1, (%rbp,%r10,8)
movsd (%r12,%r13), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%r12,%r13)
movsd (%rbp,%r11,8), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rbp,%r11,8)
testq %r13, %r13
je 0x23ed7
movq (%rcx,%r13), %rbp
movsd %xmm1, (%rbp,%r11,8)
movq 0x8(%rsp), %rbx
movq (%rbx,%r11,8), %rbx
leaq (%rbx,%rax), %r15
movsd %xmm1, (%r13,%r15)
movsd (%rbp,%r10,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rbp,%r10,8)
addq %rdx, %rbx
addsd (%r13,%rbx), %xmm0
movsd %xmm0, (%r13,%rbx)
movq 0x8(%rsp), %rbx
addq $0x8, %r13
cmpq %r13, %rdi
jne 0x23e3f
incq %r9
addq $0x8, %rax
addq $0x8, %rcx
addq $0x8, %rdx
addq $0x8, %rsi
addq $0x8, %r8
addq $-0x8, %rdi
cmpq $0x3, %r9
jne 0x23e22
movq 0x20(%rsp), %r15
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r10
incq %r10
cmpq %r9, %r10
jne 0x23d60
callq 0x2050
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq