// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2f40, %rsp           # imm = 0x2F40
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2f20(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x2f28(%rbp)
movq -0x8(%rbp), %rax
movslq (%rax), %rax
imulq $0xc8, %rax, %rdi
callq 0x1180
movq %rax, -0x2f30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x22a11
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x22a01
movl $0x0, -0x2f34(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x2f38(%rbp)
movq -0x2f20(%rbp), %rax
movq %rax, -0x2f18(%rbp)
movq -0x2f18(%rbp), %rax
cmpq -0x2f28(%rbp), %rax
jae 0x22945
movq -0x2f18(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x2286f
jmp 0x22945
movq -0x2f18(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2292a
movq -0x2f18(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x228f5
movq -0x2f18(%rbp), %rcx
movslq -0x2f34(%rbp), %rax
movq %rcx, -0x2f10(%rbp,%rax,8)
movl -0x2f34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f34(%rbp)
cmpl $0x3e8, -0x2f34(%rbp)   # imm = 0x3E8
jl 0x228f3
leaq 0x59ad8(%rip), %rdi     # 0x7c3a1
movl $0x3e8, %esi            # imm = 0x3E8
movb $0x0, %al
callq 0x10d0
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
leaq 0x59ae1(%rip), %rdi     # 0x7c3c3
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x22928
movq -0x2f18(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x2f38(%rbp), %eax
jge 0x22926
movq -0x2f18(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x20(%rbp), %eax
jle 0x22926
movq -0x2f18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2f38(%rbp)
jmp 0x22928
jmp 0x2292a
jmp 0x2292c
movq -0x2f18(%rbp), %rax
addq $0xc8, %rax
movq %rax, -0x2f18(%rbp)
jmp 0x22847
cmpl $0x0, -0x2f34(%rbp)
je 0x229ca
leaq -0xfd0(%rbp), %rdi
leaq -0x2f10(%rbp), %rsi
movl -0x2f34(%rbp), %edx
callq 0x22a80
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2f34(%rbp), %eax
jge 0x229c8
movslq -0x24(%rbp), %rax
cmpl $0x1, -0xfd0(%rbp,%rax,4)
jne 0x229bb
movq -0x2f30(%rbp), %rdi
movslq -0x18(%rbp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %rdi
movslq -0x24(%rbp), %rax
movq -0x2f10(%rbp,%rax,8), %rsi
movl $0xc8, %edx
callq 0x1160
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x229bd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2296e
jmp 0x229ca
movl -0x2f38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x229e5
movq -0x2f18(%rbp), %rax
movq %rax, -0x2f20(%rbp)
jmp 0x22a01
movl -0x2f38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x229f3
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2281a
jmp 0x22a03
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x22805
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x22a5c
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %rdi
movq -0x2f30(%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 0x22a18
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x2f30(%rbp), %rdi
callq 0x1040
addq $0x2f40, %rsp           # imm = 0x2F40
popq %rbp
retq
nopw (%rax,%rax)