// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_min_M
int Interactions_min_M(struct interaction *Int_list, float thr,
		     atom *atoms, int N_atoms, int N_res)
{
  //  For each pair of residues only N_RESRES atoms
  //  with smallest 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;
  int res1, res2, k;

  float *d2_min=malloc(N_RESRES*sizeof(float));
  int *i1_min=malloc(N_RESRES*sizeof(int));
  int *i2_min=malloc(N_RESRES*sizeof(int));

  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++;
      int n_int=0;

      // 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((n_int<N_RESRES)||(d2 < d2_min[n_int-1])){
	    int j, n;
	    for(k=0; k<n_int; k++)if(d2<d2_min[k])break;
	    if(n_int<N_RESRES){n=n_int-1; n_int++;}else{n=N_RESRES-1;}
	    for(j=n; j>k; j--){
	      d2_min[j]=d2_min[j-1];
	      i1_min[j]=i1_min[j-1];
	      i2_min[j]=i2_min[j-1];
	    }
	    d2_min[k]=d2; i1_min[k]=i1; i2_min[k]=i2;
	  }
	}
      }

      // store interaction
      for(k=0; k<n_int; k++){
	Int_list[N_int].i1=i1_min[k]; Int_list[N_int].i2=i2_min[k];
	Int_list[N_int].r0=sqrt(d2_min[k]); 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;
    }
  }
  free(d2_min); free(i1_min); free(i2_min);
  return(N_int);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %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)
movss 0x5bd4e(%rip), %xmm0    # 0x7bff0
addss -0xc(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x50(%rbp), %xmm0
mulss -0x50(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
leaq 0x6bdea(%rip), %rax     # 0x8c0ac
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x70(%rbp)
leaq 0x6bdd3(%rip), %rax     # 0x8c0ac
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x78(%rbp)
leaq 0x6bdbc(%rip), %rax     # 0x8c0ac
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x80(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x207a2
jmp 0x20315
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x5c(%rbp), %eax
jge 0x20337
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x20315
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x20792
jmp 0x20357
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x60(%rbp), %eax
jge 0x20379
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x20357
movl $0x0, -0x84(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2069d
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 0x203b9
jmp 0x2069d
movl -0x34(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2068d
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 0x203ef
jmp 0x2068d
leaq 0x6b1ca(%rip), %rax     # 0x8b5c0
cmpl $0x0, (%rax)
je 0x20418
movl -0x5c(%rbp), %edi
movl -0x60(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x215f0
cmpl $0x0, %eax
je 0x20418
jmp 0x2067f
movq -0x48(%rbp), %rax
movsd (%rax), %xmm0
movq -0x40(%rbp), %rax
subsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm0
mulss -0x54(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
ucomiss -0x4c(%rbp), %xmm0
jbe 0x20460
movss -0x58(%rbp), %xmm0
ucomiss -0x50(%rbp), %xmm0
jbe 0x2045b
jmp 0x20782
jmp 0x2067f
movq -0x48(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm0
movss -0x54(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
ucomiss -0x4c(%rbp), %xmm0
jbe 0x204b7
movss -0x58(%rbp), %xmm0
ucomiss -0x50(%rbp), %xmm0
jbe 0x204b2
jmp 0x20782
jmp 0x2067f
movq -0x48(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm0
movss -0x54(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
ucomiss -0x4c(%rbp), %xmm0
jbe 0x2050e
movss -0x58(%rbp), %xmm0
ucomiss -0x50(%rbp), %xmm0
jbe 0x20509
jmp 0x20782
jmp 0x2067f
movl -0x84(%rbp), %eax
leaq 0x6bb91(%rip), %rcx     # 0x8c0ac
cmpl (%rcx), %eax
jl 0x20542
movss -0x58(%rbp), %xmm1
movq -0x70(%rbp), %rax
movl -0x84(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2067d
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x2057a
movss -0x58(%rbp), %xmm1
movq -0x70(%rbp), %rax
movslq -0x64(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2056d
jmp 0x2057a
jmp 0x2056f
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x20549
movl -0x84(%rbp), %eax
leaq 0x6bb25(%rip), %rcx     # 0x8c0ac
cmpl (%rcx), %eax
jge 0x205ab
movl -0x84(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x205bd
leaq 0x6bafa(%rip), %rax     # 0x8c0ac
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x64(%rbp), %eax
jle 0x2064f
movq -0x70(%rbp), %rax
movl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x78(%rbp), %rax
movl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x78(%rbp), %rax
movslq -0x88(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x80(%rbp), %rax
movl -0x88(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movslq -0x88(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x88(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x205c9
movss -0x58(%rbp), %xmm0
movq -0x70(%rbp), %rax
movslq -0x64(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x28(%rbp), %edx
movq -0x78(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %edx
movq -0x80(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2067f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x203bf
jmp 0x2068f
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x20389
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x20780
movq -0x78(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x80(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x70(%rbp), %rax
movslq -0x64(%rbp), %rcx
movss (%rax,%rcx,4), %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 0x5590f(%rip), %xmm0    # 0x76048
movsd %xmm0, 0x28(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x7bb47(%rip), %rcx     # 0x9c298
cmpl (%rcx), %eax
jl 0x20770
movl -0x24(%rbp), %esi
leaq 0x5b97c(%rip), %rdi     # 0x7c0db
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x20772
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x206a4
jmp 0x20782
jmp 0x20784
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x20349
jmp 0x20794
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x20307
movq -0x70(%rbp), %rdi
callq 0x1040
movq -0x78(%rbp), %rdi
callq 0x1040
movq -0x80(%rbp), %rdi
callq 0x1040
movl -0x24(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)