// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
testl %r8d, %r8d
jle 0x16fcc
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, %r14
movaps %xmm0, %xmm3
mulss %xmm0, %xmm3
xorl %r12d, %r12d
leaq 0x4(%rsp), %r13
movl $0x0, (%rsp)
movl %ecx, 0x10(%rsp)
movss %xmm3, 0x14(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
callq 0x1867d
testl %eax, %eax
js 0x16fb2
movslq 0x4(%rsp), %rdx
leal 0x1(%rdx), %eax
movl %eax, 0x8(%rsp)
incl %r12d
cmpl %ebx, %r12d
jge 0x16fc1
imulq $0x70, %rdx, %r13
addq %r14, %r13
movl %r12d, 0xc(%rsp)
movq %rdx, %r15
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl %r12d, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
callq 0x1867d
testl %eax, %eax
js 0x16ed5
movslq 0x8(%rsp), %rax
imulq $0x70, %rax, %rcx
movsd (%r14,%rcx), %xmm0
subsd (%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
movss 0x14(%rsp), %xmm3
ucomiss %xmm3, %xmm0
jbe 0x16ee5
movq %r15, %rdx
incl %r12d
cmpl %r12d, %ebx
jne 0x16e8f
jmp 0x16fb7
addq %r14, %rcx
movsd 0x8(%rcx), %xmm1
subsd 0x8(%r13), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm3, %xmm1
movq %r15, %rdx
ja 0x16ed8
movsd 0x10(%rcx), %xmm0
subsd 0x10(%r13), %xmm0
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
ucomiss %xmm3, %xmm2
ja 0x16ed8
movslq (%rsp), %rcx
imulq $0xc8, %rcx, %rbp
movq 0x18(%rsp), %rcx
movl %edx, (%rcx,%rbp)
movl %eax, 0x4(%rcx,%rbp)
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rcx,%rbp)
movss 0x3ff4f(%rip), %xmm4    # 0x56ea8
ucomiss %xmm2, %xmm4
jae 0x16f7c
movapd %xmm1, %xmm0
movsd 0x3ff66(%rip), %xmm1    # 0x56ed0
callq 0x20a0
movq %r15, %rdx
mulsd 0x3ff5e(%rip), %xmm0    # 0x56ed8
jmp 0x16f8c
mulsd 0x3ff3c(%rip), %xmm0    # 0x56ec0
addsd 0x3ff3c(%rip), %xmm0    # 0x56ec8
addq 0x18(%rsp), %rbp
movsd %xmm0, 0x28(%rbp)
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
leaq 0x62333(%rip), %rcx     # 0x792d8
cmpl (%rcx), %eax
jge 0x16fe5
movl 0x10(%rsp), %ebp
jmp 0x16ed8
incl %r12d
jmp 0x16fc1
movl 0xc(%rsp), %r12d
leaq 0x4(%rsp), %r13
cmpl %ebx, %r12d
jne 0x16e4e
jmp 0x16fd3
movl $0x0, (%rsp)
movl (%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3ff97(%rip), %rdi     # 0x56f83
movl (%rsp), %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280