// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/main_tnm.c
// Function: Apo_interactions
struct interaction *Apo_interactions(int *N_int_apo,
				     struct interaction **Int_list_inter,
				     int *N_int_inter,
				     struct interaction *Int_list, int N_int,
				     atom *atoms, int *apo_chain_num,
				     int n_apo, int Nchain)
{
  struct interaction *Int_list_apo=
    malloc(N_int*sizeof(struct interaction)), *tmp=Int_list;
  *N_int_apo=0; *N_int_inter=0;
  for(int k=0; k<N_int; k++){
    if(atoms[tmp->i1].chain!=atoms[tmp->i2].chain){
      int apo1=Belong_to_apo(atoms[tmp->i1].chain, apo_chain_num, n_apo);
      int apo2=Belong_to_apo(atoms[tmp->i2].chain, apo_chain_num, n_apo);
      if((apo1 && apo2==0) || (apo1==0 && apo2)){
	(*N_int_inter)++; goto next_int;
      }
    }
    Int_list_apo[*N_int_apo]=*tmp; (*N_int_apo)++; 
  next_int:
    tmp++;
  }
  printf("%d interactions belong to the interface "
	 "between %d chains and %d chains\n",
	 N_int-*N_int_apo, n_apo, Nchain-n_apo);

  *Int_list_inter=malloc(*N_int_inter*sizeof(struct interaction));
  int n=0; tmp=Int_list; struct interaction *store=*Int_list_inter;
  for(int k=0; k<N_int; k++){
    if(atoms[tmp->i1].chain!=atoms[tmp->i2].chain){
      int apo1=Belong_to_apo(atoms[tmp->i1].chain, apo_chain_num, n_apo);
      int apo2=Belong_to_apo(atoms[tmp->i2].chain, apo_chain_num, n_apo);
      if((apo1 && apo2==0) || (apo1==0 && apo2)){
	*store=*tmp; store++; n++; 
      }
    }
    tmp++;
  }
  if(n!=*N_int_inter){printf("ERROR of Interface interactions\n"); exit(8);}

  return(Int_list_apo);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x20(%rsp)
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, 0x28(%rsp)
movq %rdi, %r12
movslq %r8d, %r15
imulq $0xc8, %r15, %rdi
callq 0x21d0
movq %r12, 0x8(%rsp)
andl $0x0, (%r12)
movq %rbx, 0x10(%rsp)
andl $0x0, (%rbx)
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
testl %r15d, %r15d
movl %ebp, 0x4(%rsp)
cmovgl %ebp, %ebx
movl %ebx, %r13d
movq %r14, 0x30(%rsp)
movq %r14, %r15
subl $0x1, %r13d
jb 0x8a1b
movslq (%r15), %rax
imulq $0x70, %rax, %rax
movq 0x20(%rsp), %rcx
movl 0x6c(%rcx,%rax), %edi
movslq 0x4(%r15), %rax
imulq $0x70, %rax, %rax
movl 0x6c(%rcx,%rax), %ebp
cmpl %ebp, %edi
jne 0x89cb
movq 0x8(%rsp), %r14
movslq (%r14), %r12
imulq $0xc8, %r12, %rdi
addq 0x18(%rsp), %rdi
movl $0xc8, %edx
movq %r15, %rsi
callq 0x21a0
movq %r14, %rax
jmp 0x8a09
movq 0x70(%rsp), %rsi
movl 0x78(%rsp), %r14d
movl %r14d, %edx
callq 0x8ea9
movl %eax, %r12d
movl %ebp, %edi
movq 0x70(%rsp), %rsi
movl %r14d, %edx
callq 0x8ea9
testl %r12d, %r12d
je 0x89f8
testl %eax, %eax
je 0x8a01
testl %r12d, %r12d
jne 0x89a5
testl %eax, %eax
je 0x89a5
movq 0x10(%rsp), %rax
movl (%rax), %r12d
incl %r12d
movl %r12d, (%rax)
addq $0xc8, %r15
jmp 0x897b
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rax
subl (%rax), %esi
movl 0x78(%rsp), %edx
movl 0x80(%rsp), %ecx
subl %edx, %ecx
leaq 0x46373(%rip), %rdi     # 0x4edad
movl $0x0, 0x4(%rsp)
xorl %eax, %eax
callq 0x20f0
movq 0x10(%rsp), %rax
movslq (%rax), %rax
imulq $0xc8, %rax, %rdi
callq 0x21d0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq %rcx, (%rax)
movq 0x30(%rsp), %r13
subl $0x1, %ebx
jb 0x8b04
movslq (%r13), %rax
imulq $0x70, %rax, %rax
movq 0x20(%rsp), %rcx
movl 0x6c(%rcx,%rax), %edi
movslq 0x4(%r13), %rax
imulq $0x70, %rax, %rax
movl 0x6c(%rcx,%rax), %ebp
cmpl %ebp, %edi
je 0x8af8
movq 0x70(%rsp), %r12
movq %r12, %rsi
movl 0x78(%rsp), %r14d
movl %r14d, %edx
callq 0x8ea9
movl %eax, %r15d
movl %ebp, %edi
movq %r12, %rsi
movl %r14d, %edx
callq 0x8ea9
testl %r15d, %r15d
je 0x8aca
testl %eax, %eax
je 0x8ad3
testl %r15d, %r15d
jne 0x8af8
testl %eax, %eax
je 0x8af8
movl $0xc8, %edx
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x21a0
addq $0xc8, %r14
movq %r14, 0x8(%rsp)
incl 0x4(%rsp)
addq $0xc8, %r13
jmp 0x8a72
movq 0x10(%rsp), %rax
movl 0x4(%rsp), %ecx
cmpl (%rax), %ecx
jne 0x8b25
movq 0x18(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x46de8(%rip), %rdi     # 0x4f914
callq 0x2090
pushq $0x8
popq %rdi
callq 0x2270