// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_min
int Interactions_min(struct interaction *Int_list, float thr,
		     atom *atoms, int N_atoms, int N_res)
{
  // All pairs of atoms tested, only the pair at minimal distance 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, d2_min;
  int res1, res2, ij;

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

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

    for(res2=res1+1; res2<N_res; res2++){ // Omit i+1 because covalent
      while(atoms[i2_start].res< res2)i2_start++;

      int i1_min=i1_start, i2_min=i2_start, ncheck=0;
      d2_min=10000; ij++;

      // Check if contact
      for(i1=i1_start; i1<N_atoms; i1++){
	atom1=atoms+i1; if(atom1->res != res1)break;
	//if(atom1->name[0]=='H')continue;
	//int ib; if(ij<IJ_MIN)ib=Backbone(atom1->name);
	for(i2=i2_start; i2<N_atoms; i2++){
	  atom2=atoms+i2; if(atom2->res != res2)break;
	  //if(atom2->name[0]=='H')continue;

	  // Check if covalent
	  if((NOCOV) && Covalent(res1, res2, atom1, atom2))continue;
	  //if((ij<IJ_MIN)&&(ib)&&(Backbone(atom2->name)))continue;
	  ncheck++;

	  // Interatomic distance
	  d=atom2->r[0]-atom1->r[0];
	  d2 =d*d; // if(d2>thr2){continue;}//if(d2 > t_max2)goto next2;  
	  d=atom2->r[1]-atom1->r[1];
	  d2+=d*d; // if(d2>thr2){continue;} //if(d2 > t_max2)goto next2; 
	  d=atom2->r[2]-atom1->r[2];
	  d2+=d*d; // if(d2>thr2){continue;} //if(d2 > t_max2)goto next2; 
	  if(d2 < d2_min){d2_min=d2; i1_min=i1; i2_min=i2;}
	}
      }

      /*  if((res1==29)&&(res2==104)){
	atom2=atoms+i1_min;
	printf("d=%.5g ", sqrt(d2_min));
	printf("a1: %s %d r %d  ",atom2->name, i1_min, atom2->res);
	atom2=atoms+i2_min;
	printf("a1: %s %d r %d\n",atom2->name, i2_min, atom2->res);
	exit(8);
      }
      */

      // store interaction
      if(d2_min < thr2){
	Int_list[N_int].i1=i1_min; Int_list[N_int].i2=i2_min;
	Int_list[N_int].r0=sqrt(d2_min); 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);
	}
      }
      //next2: continue;
    }
  }
  return(N_int);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movss -0xc(%rbp), %xmm0
mulss -0xc(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x20243
jmp 0x1ff5c
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x5c(%rbp), %eax
jge 0x1ff7e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1ff5c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x20233
jmp 0x1ffa5
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x60(%rbp), %eax
jge 0x1ffc7
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1ffa5
movl -0x30(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movss 0x5c012(%rip), %xmm0    # 0x7bff4
movss %xmm0, -0x58(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x20169
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x5c(%rbp), %eax
je 0x20026
jmp 0x20169
movl -0x34(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x20159
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x60(%rbp), %eax
je 0x2005c
jmp 0x20159
leaq 0x6b55d(%rip), %rax     # 0x8b5c0
cmpl $0x0, (%rax)
je 0x20085
movl -0x5c(%rbp), %edi
movl -0x60(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x215f0
cmpl $0x0, %eax
je 0x20085
jmp 0x2014b
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movsd (%rax), %xmm0
movq -0x40(%rbp), %rax
subsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x50(%rbp), %xmm0
mulss -0x50(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x48(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x50(%rbp), %xmm2
movss -0x54(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x48(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x50(%rbp), %xmm2
movss -0x54(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x20149
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x2014b
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2002c
jmp 0x2015b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1fff6
movss -0x58(%rbp), %xmm1
movss -0x4c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x20223
movl -0x68(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x6c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movss -0x58(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd 0x55e5e(%rip), %xmm0    # 0x76048
movsd %xmm0, 0x28(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x7c096(%rip), %rcx     # 0x9c298
cmpl (%rcx), %eax
jl 0x20221
movl -0x24(%rbp), %esi
leaq 0x5becb(%rip), %rdi     # 0x7c0db
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x20223
jmp 0x20225
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1ff97
jmp 0x20235
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1ff4e
movl -0x24(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)