// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl %ecx, 0x4(%rsp)
testl %ecx, %ecx
jle 0x18c1d
movaps %xmm0, %xmm3
mulss %xmm0, %xmm3
addss 0x3e4da(%rip), %xmm0    # 0x56eac
mulss %xmm0, %xmm0
movslq %edx, %rax
movq %rax, 0x48(%rsp)
leaq 0x64(%rsi), %rax
movq %rax, 0x38(%rsp)
xorl %edi, %edi
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, 0x40(%rsp)
movss %xmm0, 0x34(%rsp)
movss %xmm3, 0x30(%rsp)
movl %edi, %ebx
movslq 0x20(%rsp), %r14
leal -0x1(%r14), %r9d
imulq $0x70, %r14, %rax
addq 0x38(%rsp), %rax
incq %r14
incl %r9d
leaq 0x70(%rax), %rcx
cmpl %ebx, (%rax)
movq %rcx, %rax
jl 0x18a24
leal 0x1(%rbx), %eax
leaq -0x1(%r14), %rcx
movq %rcx, 0x20(%rsp)
cmpl 0x4(%rsp), %eax
movq %rax, 0x50(%rsp)
jge 0x18c0c
movl %eax, %r15d
movl %r9d, 0x2c(%rsp)
movslq %r14d, %r14
imulq $0x70, %r14, %rax
decq %r14
movq 0x38(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %rax, %r11
incq %r14
leaq 0x70(%rcx), %r8
addq $0x70, %rax
cmpl %r15d, (%rcx)
movq %r8, %rcx
jl 0x18a6d
cmpl %edx, %r9d
jge 0x18bf0
movq %r11, 0x60(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
imulq $0x70, 0x18(%rsp), %r13
movq 0x40(%rsp), %rax
cmpl %ebx, 0x64(%rax,%r13)
jne 0x18bf0
cmpl 0x14(%rsp), %r14d
jge 0x18bd8
addq %rax, %r13
movq 0x60(%rsp), %rbp
movq %r14, %r12
cmpl %r15d, 0x64(%rbp)
jne 0x18bd8
leaq 0x4fb28(%rip), %rax     # 0x68600
cmpl $0x0, (%rax)
je 0x18b01
movl %ebx, %edi
movl %r15d, %esi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x18742
movss 0x30(%rsp), %xmm3
movss 0x34(%rsp), %xmm0
testl %eax, %eax
jne 0x18bc6
movsd (%rbp), %xmm1
subsd (%r13), %xmm1
xorps %xmm2, %xmm2
cvtsd2ss %xmm1, %xmm2
mulss %xmm2, %xmm2
ucomiss %xmm3, %xmm2
jbe 0x18b2a
ucomiss %xmm0, %xmm2
jbe 0x18bc6
jmp 0x18bf0
movsd 0x8(%rbp), %xmm1
subsd 0x8(%r13), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm3, %xmm1
jbe 0x18b50
ucomiss %xmm0, %xmm1
jbe 0x18bc6
jmp 0x18bf0
movsd 0x10(%rbp), %xmm2
subsd 0x10(%r13), %xmm2
cvtsd2ss %xmm2, %xmm2
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
ucomiss %xmm3, %xmm2
ja 0x18b1c
ucomiss %xmm2, %xmm3
jbe 0x18bc6
movq 0x8(%rsp), %r8
movslq %r8d, %r8
imulq $0xc8, %r8, %rax
movq 0x58(%rsp), %rcx
movq 0x18(%rsp), %rsi
movl %esi, (%rcx,%rax)
movl %r12d, 0x4(%rcx,%rax)
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
movsd %xmm1, 0x20(%rcx,%rax)
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, 0x28(%rcx,%rax)
incl %r8d
movq %r8, 0x8(%rsp)
leaq 0x60717(%rip), %rax     # 0x792d8
cmpl (%rax), %r8d
jge 0x18c3a
incq %r12
addq $0x70, %rbp
cmpq 0x48(%rsp), %r12
jl 0x18ac7
movq 0x18(%rsp), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
cmpq 0x48(%rsp), %rcx
jl 0x18a9b
incl %r15d
cmpl 0x4(%rsp), %r15d
movl 0x14(%rsp), %edx
movq 0x40(%rsp), %rsi
movl 0x2c(%rsp), %r9d
jne 0x18a58
movq 0x50(%rsp), %rdi
cmpl 0x4(%rsp), %edi
jne 0x18a10
jmp 0x18c26
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e342(%rip), %rdi     # 0x56f83
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280