// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_hnm
int Interactions_hnm(struct interaction *Int_list, char *atom_type, float thr,
		     atom *atoms, int N_atoms, int N_res)
{
  int N_int=0, i1=0, i2;
  atom *atom1=atoms, *atom2;
  float thr2=thr*thr;
  float d, d2;
  int res1, res2;

  for(res1=0; res1<N_res; res1++){

    if(Find_atom(atoms, &i1, res1, N_atoms, atom_type)< 0)continue;
    atom1=atoms+i1; i2=i1+1;

    for(res2=res1+1; res2<N_res; res2++){
      if(Find_atom(atoms, &i2, res2, N_atoms, atom_type)< 0)continue;
      atom2=atoms+i2;

      // Interatomic distance
      d=atom2->r[0]-atom1->r[0]; d2 =d*d; if(d2>thr2)continue;
      d=atom2->r[1]-atom1->r[1]; d2+=d*d; if(d2>thr2)continue;
      d=atom2->r[2]-atom1->r[2]; d2+=d*d; if(d2>thr2)continue;

      // store interaction
      Int_list[N_int].i1=i1; Int_list[N_int].i2=i2;
      Int_list[N_int].r0=sqrt(d2);
      if(d2<=4){
	Int_list[N_int].sec_der=205*sqrt(d2)-571.2;
      }else{
	Int_list[N_int].sec_der=305.9*pow(d2, -3);
      }
      N_int++;
      if(N_int >= INT_MAX){
	printf("ERROR, too many interactions %d\n", N_int); exit(8);
      }

    }
  }
  return(N_int);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x0, 0x8(%rsp)
testl %r8d, %r8d
jle 0x176b7
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, %r14
mulss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
xorl %r12d, %r12d
movl $0x0, (%rsp)
movl %ecx, 0x10(%rsp)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl %r12d, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
callq 0x18d9f
testl %eax, %eax
movq %r12, 0x30(%rsp)
js 0x176a4
movslq 0x8(%rsp), %r15
leal 0x1(%r15), %eax
movl %eax, 0x4(%rsp)
leal 0x1(%r12), %r13d
cmpl %ebx, %r13d
jge 0x176a4
imulq $0x70, %r15, %r12
addq %r14, %r12
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
movl %r13d, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
callq 0x18d9f
testl %eax, %eax
js 0x17698
movslq 0x4(%rsp), %rax
imulq $0x70, %rax, %rcx
movsd (%r14,%rcx), %xmm0
subsd (%r12), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
movss 0x14(%rsp), %xmm2
ucomiss %xmm2, %xmm0
ja 0x17698
addq %r14, %rcx
movsd 0x8(%rcx), %xmm1
subsd 0x8(%r12), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm2, %xmm1
ja 0x17698
movsd 0x10(%rcx), %xmm0
subsd 0x10(%r12), %xmm0
xorps %xmm3, %xmm3
cvtsd2ss %xmm0, %xmm3
mulss %xmm3, %xmm3
addss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x17698
movslq (%rsp), %rcx
imulq $0xc8, %rcx, %rbp
movq 0x18(%rsp), %rcx
movl %r15d, (%rcx,%rbp)
movl %eax, 0x4(%rcx,%rbp)
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
ucomisd 0x39a6e(%rip), %xmm1    # 0x51060
jb 0x175fd
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x1761e
movapd %xmm1, %xmm0
movss %xmm3, 0xc(%rsp)
movsd %xmm1, 0x28(%rsp)
callq 0x2290
movsd 0x28(%rsp), %xmm1
movss 0xc(%rsp), %xmm3
addq 0x18(%rsp), %rbp
movsd %xmm0, 0x20(%rbp)
movss 0x3f8b8(%rip), %xmm0    # 0x56ee8
ucomiss %xmm3, %xmm0
jae 0x17650
movapd %xmm1, %xmm0
movsd 0x3f8cf(%rip), %xmm1    # 0x56f10
callq 0x20a0
mulsd 0x3f8ca(%rip), %xmm0    # 0x56f18
jmp 0x1767c
ucomisd 0x39a08(%rip), %xmm1    # 0x51060
jb 0x17663
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x1766c
movapd %xmm1, %xmm0
callq 0x2290
mulsd 0x3f88c(%rip), %xmm0    # 0x56f00
addsd 0x3f88c(%rip), %xmm0    # 0x56f08
movsd %xmm0, 0x28(%rbp)
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
leaq 0x61c48(%rip), %rcx     # 0x792d8
cmpl (%rcx), %eax
jge 0x176d0
movl 0x10(%rsp), %ebp
incl %r13d
cmpl %r13d, %ebx
jne 0x17538
movq 0x30(%rsp), %r12
incl %r12d
cmpl %ebx, %r12d
jne 0x174f2
jmp 0x176be
movl $0x0, (%rsp)
movl (%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f8ec(%rip), %rdi     # 0x56fc3
movl (%rsp), %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270