// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
movl %ecx, 0x8(%rsp)
testl %ecx, %ecx
jle 0x19404
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
addss 0x3dd55(%rip), %xmm2    # 0x56eec
mulss %xmm2, %xmm2
movslq %edx, %rax
movq %rax, 0x50(%rsp)
leaq 0x64(%rsi), %rax
movq %rax, 0x30(%rsp)
xorl %edi, %edi
movl $0x0, 0x4(%rsp)
movq $0x0, 0x20(%rsp)
movss %xmm2, 0x14(%rsp)
movss %xmm3, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, 0x40(%rsp)
movslq 0x20(%rsp), %r14
leal -0x1(%r14), %r9d
imulq $0x70, %r14, %rax
addq 0x30(%rsp), %rax
incq %r14
incl %r9d
leaq 0x70(%rax), %rcx
cmpl %edi, (%rax)
movq %rcx, %rax
jl 0x191e6
leal 0x1(%rdi), %eax
leaq -0x1(%r14), %rcx
movq %rcx, 0x20(%rsp)
cmpl 0x8(%rsp), %eax
movq %rax, 0x58(%rsp)
jge 0x193f3
movl %eax, %ebx
movq %rdi, 0x48(%rsp)
movl %r9d, 0x2c(%rsp)
movslq %r14d, %r14
imulq $0x70, %r14, %rax
decq %r14
movq 0x30(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %rax, %r13
incq %r14
leaq 0x70(%rcx), %r8
addq $0x70, %rax
cmpl %ebx, (%rcx)
movq %r8, %rcx
jl 0x19233
cmpl %edx, %r9d
jge 0x193d9
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
imulq $0x70, 0x18(%rsp), %r15
movq 0x40(%rsp), %rax
cmpl %edi, 0x64(%rax,%r15)
jne 0x193d9
cmpl 0xc(%rsp), %r14d
jge 0x193c1
addq %rax, %r15
movq %r13, %rbp
movq %r14, %r12
cmpl %ebx, 0x64(%rbp)
jne 0x193c1
leaq 0x4f36b(%rip), %rax     # 0x68600
cmpl $0x0, (%rax)
je 0x192c0
movl %ebx, %esi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x18e79
movq 0x48(%rsp), %rdi
movss 0x10(%rsp), %xmm3
movss 0x14(%rsp), %xmm2
testl %eax, %eax
jne 0x193af
movsd (%rbp), %xmm0
subsd (%r15), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
ucomiss %xmm3, %xmm0
jbe 0x192e5
ucomiss %xmm2, %xmm0
jbe 0x193af
jmp 0x193d9
movsd 0x8(%rbp), %xmm1
subsd 0x8(%r15), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm3, %xmm1
jbe 0x1930f
ucomiss %xmm2, %xmm1
jbe 0x193af
jmp 0x193d9
movsd 0x10(%rbp), %xmm0
subsd 0x10(%r15), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm3, %xmm0
ja 0x192d7
ucomiss %xmm0, %xmm3
jbe 0x193af
movslq 0x4(%rsp), %rax
imulq $0xc8, %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x18(%rsp), %rcx
movl %ecx, (%rax,%rdx)
movl %r12d, 0x4(%rax,%rdx)
cvtss2sd %xmm0, %xmm0
ucomisd 0x37d06(%rip), %xmm0    # 0x51060
jb 0x19362
sqrtsd %xmm0, %xmm0
jmp 0x19382
movq %rdx, 0x60(%rsp)
callq 0x2290
movq 0x60(%rsp), %rdx
movq 0x48(%rsp), %rdi
movss 0x10(%rsp), %xmm3
movss 0x14(%rsp), %xmm2
addq 0x38(%rsp), %rdx
movsd %xmm0, 0x20(%rdx)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x28(%rdx)
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
leaq 0x5ff2d(%rip), %rcx     # 0x792d8
cmpl (%rcx), %eax
jge 0x1941f
incq %r12
addq $0x70, %rbp
cmpq 0x50(%rsp), %r12
jl 0x19285
movq 0x18(%rsp), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
cmpq 0x50(%rsp), %rcx
jl 0x1925b
incl %ebx
cmpl 0x8(%rsp), %ebx
movl 0xc(%rsp), %edx
movq 0x40(%rsp), %rsi
movl 0x2c(%rsp), %r9d
jne 0x1921e
movq 0x58(%rsp), %rdi
cmpl 0x8(%rsp), %edi
jne 0x191d4
jmp 0x1940c
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3db9d(%rip), %rdi     # 0x56fc3
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270