// File: /workspace/github_c_makefile_star2_O1/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 0x21d0
movq %rax, %r14
testq %rbx, %rbx
jle 0x24106
movl %ebx, %edx
shlq $0x2, %rdx
movq %r14, %rdi
movl $0xff, %esi
callq 0x2110
testl %r13d, %r13d
jle 0x24121
movl %r13d, %eax
xorl %ecx, %ecx
movslq (%rbp,%rcx,4), %rdx
movl %ecx, (%r14,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x24110
movq %r14, 0x10(%rsp)
testl %r13d, %r13d
movq 0x8(%rsp), %r12
jle 0x24161
leal (%r13,%r13,2), %eax
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 0x2414b
movl (%rsp), %eax
testl %eax, %eax
movq 0x10(%rsp), %rdi
jle 0x24356
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 0x2434a
movslq 0x4(%r15,%rax), %rsi
movl (%rdi,%rsi,4), %r8d
testl %r8d, %r8d
js 0x2434a
movq %r10, 0x30(%rsp)
addq %r15, %rax
leaq (%r8,%r8,2), %rbp
leaq (%rdx,%rdx,2), %r14
imulq $0x70, %rcx, %rcx
imulq $0x70, %rsi, %rdx
movq 0x28(%rsp), %rsi
movsd (%rsi,%rdx), %xmm0
subsd (%rsi,%rcx), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x8(%rsi,%rdx), %xmm0
subsd 0x8(%rsi,%rcx), %xmm0
movsd %xmm0, 0x48(%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), %rbx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x108e3
movsd (%rsp), %xmm4
movapd 0x2ce6f(%rip), %xmm3    # 0x51090
divsd %xmm0, %xmm4
movl %r14d, %eax
movq %rax, (%rsp)
movl %ebp, %eax
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rcx
leaq (%rcx,%r14,8), %rdx
shlq $0x3, %r14
leaq (%rcx,%rbp,8), %rsi
shlq $0x3, %rbp
movl $0x18, %edi
movq %rbx, %r8
xorl %r9d, %r9d
movq (%rsp), %rax
leaq (%r9,%rax), %r10
movq 0x38(%rsp), %rax
leaq (%r9,%rax), %r11
movq (%rcx,%r10,8), %r12
leaq (%r12,%r14), %rbx
addq %rbp, %r12
xorl %r13d, %r13d
movsd 0x40(%rsp,%r9,8), %xmm0
mulsd (%r8,%r13), %xmm0
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm1
movlpd %xmm1, (%r12,%r13)
movq (%rsi,%r13), %rax
movlpd %xmm1, (%rax,%r10,8)
movsd (%rbx,%r13), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rbx,%r13)
movsd (%rax,%r11,8), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rax,%r11,8)
testq %r13, %r13
je 0x24304
movq (%rdx,%r13), %rax
movsd %xmm1, (%rax,%r11,8)
movq 0x8(%rsp), %rcx
movq (%rcx,%r11,8), %rcx
leaq (%rcx,%r14), %r15
movsd %xmm1, (%r13,%r15)
movsd (%rax,%r10,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r10,8)
addq %rbp, %rcx
addsd (%r13,%rcx), %xmm0
movsd %xmm0, (%r13,%rcx)
movq 0x8(%rsp), %rcx
addq $0x8, %r13
cmpq %r13, %rdi
jne 0x24272
incq %r9
addq $0x8, %r14
addq $0x8, %rdx
addq $0x8, %rbp
addq $0x8, %rsi
addq $0x8, %r8
addq $-0x8, %rdi
cmpq $0x3, %r9
jne 0x24253
movq 0x20(%rsp), %r15
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r10
incq %r10
cmpq %r9, %r10
jne 0x24181
callq 0x2050
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq