// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_all
int Interactions_all(struct interaction *Int_list, float thr,
		     atom *atoms, int N_atoms, int N_res)
{
  // All pairs of atoms below the thresholds interact
  int N_int=0, i1, i2, i1_start=0, i2_start=0;
  atom *atom1=atoms, *atom2;
  float thr2=thr*thr;
  float t_max2=thr+22; t_max2*=t_max2;
  float d, d2;
  int res1, res2;

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

    while(atoms[i1_start].res< res1)i1_start++;
    i2_start=i1_start+1;

    for(res2=res1+1; res2<N_res; res2++){
      while(atoms[i2_start].res< res2)i2_start++;

      // Check if contact
      for(i1=i1_start; i1<N_atoms; i1++){
	atom1=atoms+i1; if(atom1->res != res1)break;
	for(i2=i2_start; i2<N_atoms; i2++){
	  atom2=atoms+i2; if(atom2->res != res2)break;

	  // Check if covalent
	  if((NOCOV) && Covalent(res1, res2, atom1, atom2))continue;

	  // Interatomic distance
	  d=atom2->r[0]-atom1->r[0];
	  d2 =d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  d=atom2->r[1]-atom1->r[1];
	  d2+=d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  d=atom2->r[2]-atom1->r[2];
	  d2+=d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  if(d2 < thr2){
	    Int_list[N_int].i1=i1; Int_list[N_int].i2=i2;
	    Int_list[N_int].r0=sqrt(d2); Int_list[N_int].sec_der=1;
	    N_int++;
	    if(N_int >= INT_MAX){
	      printf("ERROR, too many interactions %d\n", N_int);
	      exit(8);
	    }
	  } // End store interaction
	}
      }
    next2: continue;
    }
  }
  return(N_int);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
addss 0x399a4(%rip), %xmm0    # 0x50dfc
mulss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
movslq %edx, %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
testl %ecx, %ecx
movl $0x0, %eax
movl %ecx, 0x20(%rsp)
cmovgl %ecx, %eax
movl %eax, 0x18(%rsp)
leaq 0x64(%rsi), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq %rsi, 0x30(%rsp)
movss %xmm2, 0x24(%rsp)
cmpl 0x18(%rsp), %ebp
je 0x17678
movslq 0x10(%rsp), %r14
imulq $0x70, %r14, %rax
addq 0x28(%rsp), %rax
incq %r14
leaq 0x70(%rax), %rcx
cmpl %ebp, (%rax)
movq %rcx, %rax
jl 0x174bc
leal 0x1(%rbp), %ebx
leaq -0x1(%r14), %rax
movq %rax, 0x10(%rsp)
movl %ebx, 0x1c(%rsp)
cmpl 0x20(%rsp), %ebx
jge 0x1766d
movslq %r14d, %r14
imulq $0x70, %r14, %rax
decq %r14
movq 0x28(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %rax, %r15
incq %r14
leaq 0x70(%rcx), %rdx
addq $0x70, %rax
cmpl %ebx, (%rcx)
movq %rdx, %rcx
jl 0x174f9
movq 0x10(%rsp), %rax
movq %r15, 0x50(%rsp)
cmpq 0x40(%rsp), %rax
jge 0x17661
imulq $0x70, %rax, %r13
cmpl %ebp, 0x64(%rsi,%r13)
jne 0x17661
movq %rax, 0x38(%rsp)
addq %rsi, %r13
movq %r14, %r12
cmpq 0x40(%rsp), %r12
jge 0x1764a
cmpl %ebx, 0x64(%r15)
jne 0x1764a
leaq 0x4c0a7(%rip), %rax     # 0x63600
cmpl $0x0, (%rax)
je 0x1757b
movl %ebp, %edi
movl %ebx, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0x171db
movss 0x24(%rsp), %xmm2
testl %eax, %eax
jne 0x1763e
movsd (%r15), %xmm0
subsd (%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
ucomiss %xmm2, %xmm0
jbe 0x175a3
ucomiss 0x4(%rsp), %xmm0
jbe 0x1763e
jmp 0x17661
movsd 0x8(%r15), %xmm1
subsd 0x8(%r13), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm2, %xmm1
jbe 0x175cc
ucomiss 0x4(%rsp), %xmm1
jbe 0x1763e
jmp 0x17661
movsd 0x10(%r15), %xmm0
subsd 0x10(%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
ja 0x17593
ucomiss %xmm0, %xmm2
jbe 0x1763e
movq 0x8(%rsp), %rdi
movslq %edi, %rdi
imulq $0xc8, %rdi, %rax
movq 0x48(%rsp), %rcx
movq 0x38(%rsp), %rsi
movl %esi, (%rcx,%rax)
movl %r12d, 0x4(%rcx,%rax)
cvtss2sd %xmm0, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, 0x20(%rcx,%rax)
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, 0x28(%rcx,%rax)
incl %edi
movq %rdi, 0x8(%rsp)
leaq 0x5cc9e(%rip), %rax     # 0x742d8
cmpl (%rax), %edi
jge 0x1768c
incq %r12
addq $0x70, %r15
jmp 0x1753d
movq 0x38(%rsp), %rax
incq %rax
movq 0x30(%rsp), %rsi
movq 0x50(%rsp), %r15
jmp 0x17518
incl %ebx
movq 0x30(%rsp), %rsi
jmp 0x174da
movl 0x1c(%rsp), %eax
movl %eax, %ebp
jmp 0x174a4
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39840(%rip), %rdi     # 0x50ed3
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270