// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x20(%rsp)
movl %r8d, %r14d
movq %rcx, 0x8(%rsp)
movq %rdx, %rbp
movl %esi, %r15d
movq %rdi, %r12
movslq 0x80(%rsp), %rbx
movq %rbx, %rdi
shlq $0x2, %rdi
callq 0x21d0
xorl %edx, %edx
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
cmpq %rdx, %rcx
je 0x218d7
orl $-0x1, (%rax,%rdx,4)
incq %rdx
jmp 0x218c9
xorl %esi, %esi
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq 0x8(%rsp), %r8
cmpq %rsi, %rcx
je 0x218fc
movslq (%rbp,%rsi,4), %rdx
movl %esi, (%rax,%rdx,4)
incq %rsi
jmp 0x218ea
leal (%r15,%r15,2), %r9d
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %edx
cmovgl %r9d, %edx
cmpq %rdx, %rcx
je 0x2192d
xorl %esi, %esi
cmpq %rsi, %r9
je 0x21928
movq (%r12,%rcx,8), %rdi
andq $0x0, (%rdi,%rsi,8)
incq %rsi
jmp 0x21915
incq %rcx
jmp 0x2190e
xorl %r10d, %r10d
testl %r14d, %r14d
cmovlel %r10d, %r14d
movq %r14, 0x18(%rsp)
movq %rax, 0x10(%rsp)
cmpq %r14, %r10
je 0x21aff
imulq $0xc8, %r10, %r9
movslq (%r8,%r9), %rcx
movl (%rax,%rcx,4), %edx
testl %edx, %edx
js 0x21af7
movslq 0x4(%r8,%r9), %rsi
movl (%rax,%rsi,4), %edi
testl %edi, %edi
js 0x21af7
movq %r10, 0x28(%rsp)
addq %r8, %r9
leal (%rdi,%rdi,2), %r15d
leal (%rdx,%rdx,2), %r13d
imulq $0x70, %rcx, %rcx
imulq $0x70, %rsi, %rdx
movq 0x20(%rsp), %rsi
movupd (%rsi,%rdx), %xmm0
movupd (%rsi,%rcx), %xmm1
subpd %xmm1, %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x10(%rsi,%rdx), %xmm0
subsd 0x10(%rsi,%rcx), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x28(%r9), %xmm0
movsd %xmm0, (%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r14, %rsi
callq 0xf96f
movsd (%rsp), %xmm4
movapd 0x296e5(%rip), %xmm3    # 0x4b0c0
divsd %xmm0, %xmm4
leaq (,%r15,8), %rax
movq %r15, (%rsp)
leaq (%r12,%r15,8), %rcx
leaq (,%r13,8), %rdx
movq %r13, %rbx
leaq (%r12,%r13,8), %rsi
movq %r14, %rdi
pushq $0x18
popq %r8
xorl %r9d, %r9d
cmpq $0x3, %r9
je 0x21ae3
leaq (%r9,%rbx), %r10
movq (%rsp), %r11
addq %r9, %r11
xorl %r15d, %r15d
cmpq %r15, %r8
je 0x21ac3
movsd 0x30(%rsp,%r9,8), %xmm0
mulsd (%rdi,%r15), %xmm0
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm1
movq (%r12,%r10,8), %r13
leaq (%r13,%rax), %r14
movlpd %xmm1, (%r15,%r14)
movq (%rcx,%r15), %r14
movlpd %xmm1, (%r14,%r10,8)
addq %rdx, %r13
movsd (%r15,%r13), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%r15,%r13)
movsd (%r14,%r11,8), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%r14,%r11,8)
testq %r15, %r15
je 0x21aba
movq (%rsi,%r15), %r14
movsd %xmm1, (%r14,%r11,8)
movq (%r12,%r11,8), %r13
leaq (%rdx,%r13), %rbp
movsd %xmm1, (%r15,%rbp)
movsd (%r14,%r10,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r10,8)
addq %rax, %r13
addsd (%r15,%r13), %xmm0
movsd %xmm0, (%r15,%r13)
addq $0x8, %r15
jmp 0x21a20
incq %r9
addq $-0x8, %r8
addq $0x8, %rdi
addq $0x8, %rax
addq $0x8, %rcx
addq $0x8, %rdx
addq $0x8, %rsi
jmp 0x21a08
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %r10
incq %r10
jmp 0x21941
movq %rax, %rdi
callq 0x2050
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq