// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/screened_interactions.c
// Function: Protect_interactions
int **Protect_interactions(struct ranked *rank, atom *atoms,
			   int N_atoms, int nres)
{
  int **protect=malloc(N_atoms*sizeof(int *));
  int N_protect=0, i1=0, i;
  int *ii2=malloc(N_atoms*sizeof(int));
  int *i1start=malloc(nres*sizeof(int));
  for(i=0; i<nres; i++)i1start[i]=N_atoms;
  for(i1=0; i1<N_atoms; i1++){
    int n=rank[i1].num;
    protect[i1]=malloc(n*sizeof(int));
    for(i=0; i<n; i++)protect[i1][i]=0;
    if(i1<i1start[atoms[i1].res])i1start[atoms[i1].res]=i1;
    ii2[i1]=0;
  }

  float dmin=100;
  int i1min=-1, imin=-1, res1, res2;
  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 res2next=nres; i1min=-1;
      for(i1=i1start[res1]; i1<N_atoms; i1++){
	if(atoms[i1].res > res1)break;
	if(atoms[i1].res == res1){
	  struct store *store=rank[i1].first; i=0;
	  while(store!=NULL){
	    int res2atom=atoms[store->i].res;
	    if(res2atom == res2){
	      if(NOCOV && Covalent(res1, res2, atoms+i1, atoms+store->i))
		goto next;
	      if((i1min<0)|| (store->x< dmin)){
		i1min=i1; dmin=store->x; imin=i;
	      }
	    }else if(res2atom > res2){
	      if(res2atom  < res2next)res2next=res2atom;
	      //ii2[i1]=i; break;
	    }
	  next:
	    store=store->next; i++;
	  }
	}
      } // end pair
      if(i1min >=0){protect[i1min][imin]=1; N_protect++;}

      // Prepare next value
      if(res2next<nres)res2=res2next-1;
    }
  }
  printf("%d contacts protected from screening (MIN)\n", N_protect);
  free(ii2); free(i1start);
  return(protect);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movslq -0x14(%rbp), %rdi
shlq $0x3, %rdi
callq 0x1180
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movslq -0x14(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x38(%rbp)
movslq -0x18(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2cdbf
movl -0x14(%rbp), %edx
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2cd9e
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2ce8c
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movslq -0x44(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x2ce33
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2ce09
movl -0x28(%rbp), %eax
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x28(%rbp), %rsi
imulq $0x70, %rsi, %rsi
addq %rsi, %rdx
movslq 0x64(%rdx), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x2ce6f
movl -0x28(%rbp), %edx
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rsi
imulq $0x70, %rsi, %rsi
addq %rsi, %rcx
movslq 0x64(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2cdc6
movss 0x4921c(%rip), %xmm0    # 0x760b0
movss %xmm0, -0x48(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2d089
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2d079
movl -0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2d032
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x54(%rbp), %eax
jle 0x2cf12
jmp 0x2d032
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x2d022
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x2d020
movq -0x10(%rbp), %rax
movq -0x68(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jne 0x2cfea
leaq 0x5e643(%rip), %rax     # 0x8b5c0
cmpl $0x0, (%rax)
je 0x2cfb5
movl -0x54(%rbp), %edi
movl -0x58(%rbp), %esi
movq -0x10(%rbp), %rdx
movslq -0x28(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdx
movq -0x10(%rbp), %rcx
movq -0x68(%rbp), %rax
movslq (%rax), %rax
imulq $0x70, %rax, %rax
addq %rax, %rcx
callq 0x215f0
cmpl $0x0, %eax
je 0x2cfb5
jmp 0x2d006
cmpl $0x0, -0x4c(%rbp)
jl 0x2cfce
movq -0x68(%rbp), %rax
movss 0x4(%rax), %xmm1
movss -0x48(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2cfe8
movl -0x28(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x68(%rbp), %rax
movss 0x4(%rax), %xmm0
movss %xmm0, -0x48(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x2d004
movl -0x6c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jle 0x2d002
movl -0x6c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x2d000
movl -0x6c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x2d002
jmp 0x2d004
jmp 0x2d006
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2cf4b
jmp 0x2d022
jmp 0x2d024
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2ceea
cmpl $0x0, -0x4c(%rbp)
jl 0x2d058
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x50(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2d069
movl -0x5c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2d06b
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2cec3
jmp 0x2d07b
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2ceae
movl -0x24(%rbp), %esi
leaq 0x506ec(%rip), %rdi     # 0x7d77f
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rdi
callq 0x1040
movq -0x40(%rbp), %rdi
callq 0x1040
movq -0x20(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)