// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movl $0x3e8, -0x50(%rbp)     # imm = 0x3E8
movl -0x50(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
imulq $0x70, %rax, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
leaq 0x6350f(%rip), %rdi     # 0x7b435
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x18127
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl 0x6c(%rax), %eax
cmpl -0x48(%rbp), %eax
je 0x17fcb
movq -0x78(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq -0x48(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
movslq 0x40(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x48(%rbp), %esi
leaq 0x63485(%rip), %rdi     # 0x7b449
movb $0x0, %al
callq 0x10d0
movq -0x78(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x180e5
movq -0x68(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x17ff1
movl -0x34(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x18016
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
movq -0x78(%rbp), %rsi
movl $0x70, %edx
callq 0x1160
movq -0x70(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x18028
movl -0x38(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movl -0x44(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x180b6
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x1808e
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jl 0x1804f
jmp 0x1808e
movq -0x98(%rbp), %rdi
movslq -0x4c(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movslq -0x7c(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rsi
movl $0x70, %edx
callq 0x1160
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1803d
movq -0x28(%rbp), %rdi
movslq -0x38(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movslq -0x44(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rsi
movl $0x70, %edx
callq 0x1160
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x54(%rax)
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x18117
movq -0x78(%rbp), %rsi
addq $0x18, %rsi
movq -0x78(%rbp), %rax
movsbl 0x68(%rax), %edx
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
leaq 0x63350(%rip), %rdi     # 0x7b453
movb $0x0, %al
callq 0x10d0
movq -0x68(%rbp), %rax
movl 0x4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x18119
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x17f44
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
leaq 0x63328(%rip), %rdi     # 0x7b45c
movb $0x0, %al
callq 0x10d0
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x1816c
movq -0x18(%rbp), %rax
movl (%rax), %esi
subl -0x34(%rbp), %esi
movq -0x18(%rbp), %rax
movl (%rax), %edx
leaq 0x63310(%rip), %rdi     # 0x7b46c
movb $0x0, %al
callq 0x10d0
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
je 0x1822e
movq -0x30(%rbp), %rax
movl (%rax), %esi
subl -0x38(%rbp), %esi
movq -0x30(%rbp), %rax
movl (%rax), %edx
leaq 0x63315(%rip), %rdi     # 0x7b4a6
movb $0x0, %al
callq 0x10d0
movq -0x98(%rbp), %rax
movl -0x38(%rbp), %edx
movq -0x30(%rbp), %rcx
movl %edx, (%rcx)
movq %rax, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x18220
movq -0x88(%rbp), %rsi
addq $0x18, %rsi
movq -0x88(%rbp), %rax
movsbl 0x68(%rax), %edx
movq -0x88(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x88(%rbp), %rax
movl 0x6c(%rax), %r8d
leaq 0x632ea(%rip), %rdi     # 0x7b4e0
movb $0x0, %al
callq 0x10d0
movq -0x88(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x88(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x181b9
leaq 0x65e51(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movq -0x58(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)