// File: /workspace/github_c_makefile_star2_O1/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 $0x2f28, %rsp           # imm = 0x2F28
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, 0x30(%rsp)
movslq (%rdi), %rax
imulq $0xc8, %rax, %r14
movq %r14, %rdi
callq 0x21d0
movq %rax, 0x18(%rsp)
testl %r12d, %r12d
movq %rbx, 0x28(%rsp)
jle 0x19b76
addq %rbx, %r14
xorl %ebp, %ebp
xorl %eax, %eax
movl %r12d, 0x14(%rsp)
movq %r14, %rdx
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %r13d
movl %r13d, 0x10(%rsp)
cmpl %r12d, %r13d
jge 0x19b67
xorl %r14d, %r14d
movq %rbx, %r15
movl %r12d, 0xc(%rsp)
cmpq %rdx, %rbx
jae 0x19ada
xorl %r14d, %r14d
movl %r12d, 0xc(%rsp)
movq %rbx, %r15
movq 0x20(%rsp), %rax
cmpl %eax, 0x8(%r15)
jg 0x19ada
jne 0x19ace
movl 0xc(%r15), %eax
cmpl %r13d, %eax
jne 0x19ab9
movslq %r14d, %rax
movq %r15, 0xfe0(%rsp,%rax,8)
cmpl $0x3e7, %r14d           # imm = 0x3E7
jge 0x19bb7
incl %r14d
jmp 0x19ace
movl 0xc(%rsp), %esi
cmpl %esi, %eax
movl %esi, %ecx
cmovll %eax, %ecx
cmpl %r13d, %eax
cmovgl %ecx, %esi
movl %esi, 0xc(%rsp)
addq $0xc8, %r15
cmpq %rdx, %r15
jb 0x19a86
movq %rbx, 0x38(%rsp)
testl %r14d, %r14d
je 0x19b45
movq %rdx, %rbx
leaq 0x40(%rsp), %rdi
leaq 0xfe0(%rsp), %rsi
movl %r14d, %edx
callq 0x19bea
testl %r14d, %r14d
jle 0x19b42
movl %r14d, %r14d
xorl %r12d, %r12d
movq %rbx, %rdx
cmpl $0x1, 0x40(%rsp,%r12,4)
jne 0x19b38
movslq %ebp, %rbp
imulq $0xc8, %rbp, %rdi
addq 0x18(%rsp), %rdi
movq 0xfe0(%rsp,%r12,8), %rsi
movl $0xc8, %edx
callq 0x21a0
movq %rbx, %rdx
incl %ebp
incq %r12
cmpq %r12, %r14
jne 0x19b0a
jmp 0x19b45
movq %rbx, %rdx
incl %r13d
movl 0x14(%rsp), %r12d
movl 0xc(%rsp), %eax
cmpl %r12d, %eax
cmovnel %eax, %r13d
movq 0x38(%rsp), %rbx
cmoveq %r15, %rbx
jne 0x19a62
movl 0x10(%rsp), %eax
cmpl %r12d, %eax
jne 0x19a52
jmp 0x19b78
xorl %ebp, %ebp
testl %ebp, %ebp
movq 0x18(%rsp), %rbx
jle 0x19b97
movl %ebp, %eax
imulq $0xc8, %rax, %rdx
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x21a0
movq 0x30(%rsp), %rax
movl %ebp, (%rax)
movq %rbx, %rdi
addq $0x2f28, %rsp           # imm = 0x2F28
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
leaq 0x3d6b1(%rip), %rdi     # 0x5726f
movl $0x3e8, %esi            # imm = 0x3E8
xorl %eax, %eax
callq 0x20f0
leaq 0x3d6c0(%rip), %rdi     # 0x57291
movq 0x20(%rsp), %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270