// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rsi, %rbx
movq %rdi, 0x30(%rsp)
movslq (%rdi), %rax
imulq $0xc8, %rax, %rdi
leaq (%rsi,%rdi), %r14
callq 0x21d0
movq %r14, %rdx
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movl %eax, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movl %ebp, 0x1c(%rsp)
movq %r14, 0x38(%rsp)
cmpl 0x18(%rsp), %r12d
je 0x17d54
leal 0x1(%r12), %r13d
movl %r13d, 0xc(%rsp)
cmpl %ebp, %r13d
jge 0x17d48
xorl %r14d, %r14d
movq 0x20(%rsp), %r15
cmpq %rdx, %r15
jae 0x17ccf
cmpl %r12d, 0x8(%r15)
jg 0x17ccf
jne 0x17cc6
movl 0xc(%r15), %eax
cmpl %r13d, %eax
jne 0x17cb9
movslq %r14d, %rax
movq %r15, 0xfe0(%rsp,%rax,8)
cmpl $0x3e7, %r14d           # imm = 0x3E7
jge 0x17db4
incl %r14d
jmp 0x17cc6
cmpl %ebp, %eax
movl %ebp, %ecx
cmovll %eax, %ecx
cmpl %r13d, %eax
cmovgl %ecx, %ebp
addq $0xc8, %r15
jmp 0x17c86
testl %r14d, %r14d
je 0x17d32
leaq 0x40(%rsp), %rdi
leaq 0xfe0(%rsp), %rsi
movl %r14d, %edx
callq 0x17de3
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x17d2d
cmpl $0x1, 0x40(%rsp,%r13,4)
jne 0x17d28
movslq %ebx, %rbx
imulq $0xc8, %rbx, %rdi
addq 0x10(%rsp), %rdi
movq 0xfe0(%rsp,%r13,8), %rsi
movl $0xc8, %edx
callq 0x21a0
incl %ebx
incq %r13
jmp 0x17cf8
movq 0x38(%rsp), %rdx
movl %ebp, %r13d
movl 0x1c(%rsp), %eax
cmpl %eax, %ebp
movl %eax, %ebp
jne 0x17c75
movq %r15, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r12d
jmp 0x17c60
xorl %r14d, %r14d
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
imulq $0xc8, %rax, %r15
movq 0x28(%rsp), %r12
cmpq %r14, %r15
je 0x17d92
leaq (%r12,%r14), %rdi
movq 0x10(%rsp), %rax
leaq (%rax,%r14), %rsi
movl $0xc8, %edx
callq 0x21a0
addq $0xc8, %r14
jmp 0x17d6d
movq 0x30(%rsp), %rax
movl %ebx, (%rax)
movq 0x10(%rsp), %rdi
addq $0x2f28, %rsp           # imm = 0x2F28
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
leaq 0x393c4(%rip), %rdi     # 0x5117f
movl $0x3e8, %esi            # imm = 0x3E8
xorl %eax, %eax
callq 0x20f0
leaq 0x393d3(%rip), %rdi     # 0x511a1
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270