// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/interactions_tnm.c
// Function: Purge_interactions_atom_res
void Purge_interactions_atom_res(int *N_int, struct interaction *Int_list,
				 int nres)
{
  int Nnew=0, res1, res2, k; 
  int selected[MINT];
  struct interaction *res12[MINT];
  struct interaction *ptr, *ini=Int_list, *end=Int_list+*N_int;
  struct interaction *tmp=malloc(*N_int*sizeof(struct interaction));

  for(res1=0; res1<nres; res1++){
    for(res2=res1+1; res2<nres; res2++){
      // Make a list of res1-res2 contacts.
      // Find the next value of res2
      int n12=0, res2min=nres;
      for(ptr=ini; ptr<end; ptr++){
	if(ptr->res1 > res1)break;
	if(ptr->res1 == res1){
	  if(ptr->res2 == res2){
	    res12[n12]=ptr; n12++;
	    if(n12 >= MINT){
	      printf("ERROR, more than %d interactions ", MINT);
	      printf("for residues %d and %d\n", res1, res2); exit(8);
	    }
	  }else if((ptr->res2 < res2min)&&(ptr->res2 > res2)){
	    res2min=ptr->res2;
	  }
	}
      } // End list

      if(n12){
	Select_pairs(selected, res12, n12);
	for(k=0; k<n12; k++){
	  if(selected[k]==1){tmp[Nnew]=*res12[k]; Nnew++;}
	}
      }

      // Prepare next value
      if(res2min==nres){ini=ptr; break;} // end res1
      else{res2=res2min-1;}

    }
  }

  for(k=0; k<Nnew; k++){
    Int_list[k]=tmp[k];
  }
  *N_int=Nnew;
  free(tmp);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f18, %rsp           # imm = 0x2F18
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
movslq (%rdi), %rax
imulq $0xc8, %rax, %r13
movq %r13, %rdi
callq 0x21e0
movq %rax, %r14
testl %r12d, %r12d
jle 0x19467
movq %r14, (%rsp)
movq %rbx, 0x10(%rsp)
addq %r15, %r13
movq %r13, 0x20(%rsp)
xorl %ebp, %ebp
xorl %eax, %eax
movq %r15, 0x28(%rsp)
movq %r15, %r14
movl %r12d, 0xc(%rsp)
movq %r14, 0x18(%rsp)
movl %eax, %ebx
leal 0x1(%rbx), %r13d
movl %r13d, 0x8(%rsp)
cmpl %r12d, %r13d
jge 0x19430
movq 0x18(%rsp), %r14
cmpq 0x20(%rsp), %r14
jae 0x19435
xorl %r15d, %r15d
movq 0x20(%rsp), %rsi
cmpl %ebx, 0x8(%r14)
jg 0x193c6
jne 0x193ba
movl 0xc(%r14), %ecx
cmpl %r13d, %ecx
jne 0x193aa
movslq %r15d, %rcx
movq %r14, 0xfd0(%rsp,%rcx,8)
cmpl $0x3e7, %r15d           # imm = 0x3E7
jge 0x1948f
incl %r15d
jmp 0x193ba
cmpl %r12d, %ecx
movl %r12d, %edx
cmovll %ecx, %edx
cmpl %r13d, %ecx
cmovgl %edx, %r12d
addq $0xc8, %r14
cmpq %rsi, %r14
jb 0x1937c
movl %r12d, %r13d
testl %r15d, %r15d
je 0x19420
leaq 0x30(%rsp), %rdi
leaq 0xfd0(%rsp), %rsi
movl %r15d, %edx
callq 0x194bf
testl %r15d, %r15d
jle 0x19420
movl %r15d, %r15d
xorl %r12d, %r12d
cmpl $0x1, 0x30(%rsp,%r12,4)
jne 0x19418
movslq %ebp, %rbp
imulq $0xc8, %rbp, %rdi
addq (%rsp), %rdi
movq 0xfd0(%rsp,%r12,8), %rsi
movl $0xc8, %edx
callq 0x21b0
incl %ebp
incq %r12
cmpq %r12, %r15
jne 0x193ee
movl 0xc(%rsp), %r12d
cmpl %r12d, %r13d
jne 0x1935b
jmp 0x19435
movq 0x18(%rsp), %r14
movl 0x8(%rsp), %eax
cmpl %r12d, %eax
jne 0x1934b
testl %ebp, %ebp
jle 0x1946b
movl %ebp, %eax
imulq $0xc8, %rax, %rdx
movq 0x28(%rsp), %rdi
movq (%rsp), %r14
movq %r14, %rsi
callq 0x21b0
movq 0x10(%rsp), %rbx
jmp 0x19474
xorl %ebp, %ebp
jmp 0x19474
movq 0x10(%rsp), %rbx
movq (%rsp), %r14
movl %ebp, (%rbx)
movq %r14, %rdi
addq $0x2f18, %rsp           # imm = 0x2F18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
leaq 0x3dd99(%rip), %rdi     # 0x5722f
movl $0x3e8, %esi            # imm = 0x3E8
xorl %eax, %eax
callq 0x20f0
leaq 0x3dda8(%rip), %rdi     # 0x57251
movl %ebx, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280