// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/align_tnm.c
// Function: Purge_not_aligned
void Purge_not_aligned(struct chain *chains1, atom *atoms1, int *natoms1,
		       struct chain *chains2, atom *atoms2, int *natoms2)
{
  // Not aligned atoms are purged, except side chain atoms in aligned residues
  int k1=0, k2=0, j_old=0, i, j, ichain=-1;
  int notali=0, notalimax=1000; atom notali_atom[notalimax];
  printf("Not aligned atoms: ");
  struct chain *ch1=NULL, *ch2=NULL;
  for(i=0; i<*natoms1; i++){
    atom *a1=atoms1+i;
    if(a1->chain!=ichain){
      ichain=a1->chain;
      ch1=chains1+ichain; ch1->ini_atom=-1;
      ch2=chains2+ch1->match; ch2->ini_atom=-1;
      printf("Chain %d ",ichain);
    }
    j=a1->ali;
    if(j>=0){
      // if((j>=0)||
      //  ((ch1->alignres[ch1->inires+a1->res]>=0)&&(a1->main==0))){ //
      // aligned atom or side chain atom in aligned residue
      if(ch1->ini_atom<0)ch1->ini_atom=k1;
      if(i!=k1)atoms1[k1]=*a1;
      // if(j>=0){
      if(ch2->ini_atom<0)ch2->ini_atom=k2;
      if(j!=k2){
	for(int k=j_old+1; k<j; k++){
	  if(notali>=notalimax)break;
	  notali_atom[notali]=atoms2[k]; notali++;
	}
	atoms2[k2]=atoms2[j];
      }
      atoms1[k1].ali=k2; j_old=j; k2++;
      // }else{printf("Saved: %s/%c%d", a1->name, a1->aa, a1->res);}
      k1++;
    }else{
      // not aligned
      printf(" %s/%c%d", a1->name, a1->aa, a1->res);
      ch1->natoms--;
    }
  }
  printf("\nn1= %d n2= %d\n", k1, k2);
  if(k1 != *natoms1){
    printf("WARNING, eliminating %d not aligned atoms of prot 1 (%d)\n",
	   *natoms1-k1, *natoms1); *natoms1=k1;
  }
  if(k2 != *natoms2){
    printf("WARNING, eliminating %d not aligned atoms of prot 2 (%d)\n",
	   *natoms2-k2, *natoms2); *natoms2=k2;
    atom *a1=notali_atom;
    for(int k=0; k<notali; k++){
      printf(" %s/%c%d/%d", a1->name, a1->aa, a1->res, a1->chain); a1++;
    }
    printf("\n");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b5d8, %rsp          # imm = 0x1B5D8
movq %r9, 0x30(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, %rbp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x40(%rsp)
leaq 0x43e89(%rip), %rdi     # 0x562d1
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x20f0
cmpl $0x0, (%rbp)
movl $0x0, %r8d
movl $0x0, %edx
jle 0x1267f
xorl %r15d, %r15d
xorl %edx, %edx
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %r12d, %r12d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %rbp, 0x28(%rsp)
imulq $0x70, %r15, %r13
movq 0x10(%rsp), %rax
movl 0x6c(%rax,%r13), %r14d
cmpl %r9d, %r14d
je 0x1250d
movslq %r14d, %rax
imulq $0x70, %rax, %rax
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax), %rsi
movq %rsi, 0x8(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, (%rcx,%rax)
movslq 0x40(%rcx,%rax), %rax
imulq $0x70, %rax, %rax
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax), %rdi
movq %rdi, 0x18(%rsp)
movl %esi, (%rcx,%rax)
leaq 0x43e02(%rip), %rdi     # 0x562e5
movl %r14d, %esi
xorl %eax, %eax
movq %r15, (%rsp)
movl %r8d, %ebp
movl %edx, %ebx
movq %r10, %r15
callq 0x20f0
movq %r15, %r10
movl %ebx, %edx
movl %ebp, %r8d
movq 0x28(%rsp), %rbp
movq (%rsp), %r15
movl %r14d, %r9d
addq 0x10(%rsp), %r13
movslq 0x54(%r13), %r14
testq %r14, %r14
js 0x12628
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jns 0x12530
movq 0x8(%rsp), %rax
movl %edx, (%rax)
movl %edx, %eax
movslq %edx, %r11
cmpq %rax, %r15
je 0x1254e
imulq $0x70, %r11, %rdi
addq 0x10(%rsp), %rdi
movl $0xe, %ecx
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
jns 0x12560
movq 0x18(%rsp), %rax
movl %r8d, (%rax)
cmpl %r8d, %r14d
je 0x12613
leal 0x1(%r10), %eax
cmpl %r14d, %eax
jge 0x125f0
cmpl $0x3e7, %r12d           # imm = 0x3E7
jg 0x125f0
movslq %r12d, %r13
imulq $0x70, %r13, %rcx
leaq (%rsp,%rcx), %rdi
addq $0x50, %rdi
movslq %eax, %rbp
imulq $0x70, %rbp, %rsi
addq 0x20(%rsp), %rsi
movl %r14d, %eax
subl %r10d, %eax
addl $-0x2, %eax
movl $0x3e7, %ecx            # imm = 0x3E7
subl %r12d, %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movl %edx, (%rsp)
imulq $0x70, %rcx, %rdx
addq $0x70, %rdx
movl %r8d, %ebx
movl %r9d, %r12d
movq %r11, 0x38(%rsp)
callq 0x21a0
movq 0x38(%rsp), %r11
movl %r12d, %r9d
movl (%rsp), %edx
movl %ebx, %r8d
incq %rbp
leaq 0x1(%r13), %r12
cmpq %r14, %rbp
jge 0x125f0
incq %rbp
cmpq $0x3e7, %r13            # imm = 0x3E7
movq %r12, %r13
jl 0x125d8
movslq %r8d, %rax
imulq $0x70, %rax, %rdi
movq 0x20(%rsp), %rax
addq %rax, %rdi
imulq $0x70, %r14, %rsi
addq %rax, %rsi
movl $0xe, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq 0x28(%rsp), %rbp
imulq $0x70, %r11, %rax
movq 0x10(%rsp), %rcx
movl %r8d, 0x54(%rcx,%rax)
incl %r8d
incl %edx
jmp 0x1266c
leaq 0x18(%r13), %rsi
movl %edx, (%rsp)
movsbl 0x68(%r13), %edx
movl 0x64(%r13), %ecx
leaq 0x43cb0(%rip), %rdi     # 0x562ef
xorl %eax, %eax
movq %r15, %r13
movq %rbp, %r15
movl %r8d, %ebp
movl %r9d, %ebx
movq %r10, %r14
callq 0x20f0
movl %ebx, %r9d
movl (%rsp), %edx
movl %ebp, %r8d
movq %r15, %rbp
movq %r13, %r15
movq 0x8(%rsp), %rax
decl 0x4(%rax)
incq %r15
movslq (%rbp), %rax
movl %r14d, %r10d
cmpq %rax, %r15
jl 0x12492
leaq 0x43c72(%rip), %rdi     # 0x562f8
movl %edx, %esi
movl %r8d, %r14d
movl %edx, %ebx
movl %r8d, %edx
xorl %eax, %eax
callq 0x20f0
movl (%rbp), %edx
movl %edx, %esi
subl %ebx, %esi
je 0x126b1
leaq 0x43c61(%rip), %rdi     # 0x56308
xorl %eax, %eax
callq 0x20f0
movl %ebx, (%rbp)
movq 0x30(%rsp), %rbx
movl (%rbx), %edx
movl %edx, %esi
subl %r14d, %esi
je 0x12711
leaq 0x43c7c(%rip), %rdi     # 0x56342
xorl %eax, %eax
callq 0x20f0
movl %r14d, (%rbx)
testl %r12d, %r12d
jle 0x12707
leaq 0xbc(%rsp), %r14
leaq 0x43c98(%rip), %rbx     # 0x5637c
leaq -0x54(%r14), %rsi
movsbl -0x4(%r14), %edx
movl -0x8(%r14), %ecx
movl (%r14), %r8d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20f0
addq $0x70, %r14
decl %r12d
jne 0x126e4
movl $0xa, %edi
callq 0x2060
addq $0x1b5d8, %rsp          # imm = 0x1B5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq