// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/interactions_tnm.c
// Function: Purge_interactions_res_pair
void Purge_interactions_res_pair(int *N_int, struct interaction *Int_list,
				 int nres)
{
  // Maximum one interaction per residue pair
  int Nnew=0, res1, res2, k; 
  struct interaction *res12;
  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++){
      // Find strongest res1-res2 contact
      // Find the next value of res2
      int res2min=nres; res12=NULL;
      for(ptr=ini; ptr<end; ptr++){
	if(ptr->res1 > res1)break;
	if(ptr->res1 == res1){
	  if(ptr->res2 == res2){
	    if((res12==NULL)||(ptr->sec_der>res12->sec_der)||
	       ((ptr->sec_der==res12->sec_der)&&(ptr->r0 < res12->r0))){
	      res12=ptr;
	    }
	  }else if((ptr->res2 < res2min)&&(ptr->res2 > res2)){
	    res2min=ptr->res2;
	  }
	}
      } // End pair

      if(res12){tmp[Nnew]=*res12; Nnew++;} // store

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

    } // end res2
  } // end res1

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

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq (%rax), %rax
imulq $0xc8, %rax, %rdi
callq 0x1180
movq %rax, -0x50(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x20eb4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x20ea4
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x20e49
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x20d9f
jmp 0x20e49
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x20e34
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x20e0e
cmpq $0x0, -0x30(%rbp)
je 0x20e04
movq -0x38(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x30(%rbp), %rax
ucomisd 0x28(%rax), %xmm0
ja 0x20e04
movq -0x38(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x30(%rbp), %rax
ucomisd 0x28(%rax), %xmm0
jne 0x20e0c
jp 0x20e0c
movq -0x38(%rbp), %rax
movsd 0x20(%rax), %xmm1
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x20e0c
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x20e32
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x54(%rbp), %eax
jge 0x20e30
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x20(%rbp), %eax
jle 0x20e30
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0x20e32
jmp 0x20e34
jmp 0x20e36
movq -0x38(%rbp), %rax
addq $0xc8, %rax
movq %rax, -0x38(%rbp)
jmp 0x20d80
cmpq $0x0, -0x30(%rbp)
je 0x20e79
movq -0x50(%rbp), %rdi
movslq -0x18(%rbp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
movl $0xc8, %edx
callq 0x1160
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x20e8b
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x20ea4
movl -0x54(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x20e96
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x20d5e
jmp 0x20ea6
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20d49
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x20efc
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
movslq -0x24(%rbp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %rsi
movl $0xc8, %edx
callq 0x1160
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x20ebb
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rdi
callq 0x1040
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)