// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/read.c
// Function: Order_atoms_aa
int Order_atoms_aa(atom *res_atom, int n_atom)
{
  int i_N=-1, i_CA=-1, i_C=-1, i_O=-1, i_OT=-1;
  int i_HN[3], i_HA[3], n_HN=0, n_HA=0, i, j;
  if(HYD)for(j=0; j<3; j++){i_HN[j]=-1; i_HA[j]=-1;}
  atom *atom1=res_atom;
  for(i=0; i<n_atom; i++){
    if(strncmp(atom1->name, "N ", 2)==0){i_N=i;}
    else if(strncmp(atom1->name, "CA", 2)==0){i_CA=i;}
    else if(strncmp(atom1->name, "C ", 2)==0){i_C=i;}
    else if(strncmp(atom1->name, "O ", 2)==0){i_O=i;}
    else if((strncmp(atom1->name, "OT", 2)==0)||
	    (strncmp(atom1->name, "OX", 2)==0)){i_OT=i;}
    else if(atom1->name[0]=='H'){
      if((atom1->name[1]==' ')||(atom1->name[1]=='1')||
	 (atom1->name[1]=='2')||(atom1->name[1]=='3')){
	atom1->name[2]=atom1->name[1]; atom1->name[1]='N';
	i_HN[n_HN]=i; n_HN++;
      }else if(atom1->name[1]=='A'){
	i_HA[n_HA]=i; n_HA++;
      }
    }
    atom1++;
  }
  
  // Store main chain in the order N (HN) CA (HA)
  atom *atom2=atom_tmp;
  int N_atom_res=0;
  N_atom_res+=Copy_atom(&atom2, res_atom, i_N);
  if(HYD){
    for(j=0; j<3; j++)
      N_atom_res+=Copy_atom(&atom2, res_atom, i_HN[j]);
  }
  N_atom_res+=Copy_atom(&atom2, res_atom, i_CA);
  if(HYD){
    for(j=0; j<3; j++)
      N_atom_res+=Copy_atom(&atom2, res_atom, i_HA[j]);
  }
  
  // Store side chain before C-O
  int N_side=n_atom;
  if(i_C>=0)N_side--;
  if(i_O>=0)N_side--; 
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'B', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'G', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'D', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'E', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'Z', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  N_atom_res+=Store_branch(&atom2, 'H', res_atom, n_atom);
  if(N_atom_res==N_side)goto CO;
  
  // Store other side chain atoms before C-O
  atom1=res_atom;
  for(i=0; i<n_atom; i++){
    if((strncmp(atom1->name, "N ", 2)!=0)&&
       (strncmp(atom1->name, "CA", 2)!=0)&&
       (strncmp(atom1->name, "C ", 2)!=0)&&
       (strncmp(atom1->name, "O ", 2)!=0)&&
       (strncmp(atom1->name, "OT", 2)!=0)&&
       (strncmp(atom1->name, "OX", 2)!=0)&&
       (atom1->name[1]!='N')&&
       (atom1->name[1]!='A')&&
       (atom1->name[1]!='B')&&
       (atom1->name[1]!='G')&&
       (atom1->name[1]!='D')&&
       (atom1->name[1]!='E')&&
       (atom1->name[1]!='Z')&&
       (atom1->name[1]!='H')){
      N_atom_res+=Copy_atom(&atom2, res_atom, i);
    }
    atom1++;
  }
  
  // Store CO
 CO:
  N_atom_res+=Copy_atom(&atom2, res_atom, i_C);
  N_atom_res+=Copy_atom(&atom2, res_atom, i_O);
  N_atom_res+=Copy_atom(&atom2, res_atom, i_OT);

  if(N_atom_res!=n_atom){
    printf("ERROR changing the order of protein atoms\n");
    printf("residue %d %c cain %d has %d residues but %d stored\n",
	   res_atom->res, res_atom->aa, res_atom->chain, n_atom, N_atom_res);
    exit(8);
  }

  for(i=0; i<n_atom; i++){
    res_atom[i]=atom_tmp[i];
  }
  return(N_atom_res);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x596fc(%rip), %r11     # 0x69060
movl (%r11), %ebp
testl %ebp, %ebp
je 0xf989
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x20(%rsp)
movq $-0x1, %rcx
movq %rcx, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movl %eax, 0x10(%rsp)
leaq 0x5be20(%rip), %rax     # 0x6b7b0
testl %ebx, %ebx
jle 0xfa9f
leaq 0x1a(%r14), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %esi, %esi
xorl %edi, %edi
xorl %r15d, %r15d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movzbl -0x2(%rcx), %r13d
cmpl $0x4d, %r13d
jg 0xfa0f
cmpl $0x43, %r13d
je 0xfa26
cmpl $0x48, %r13d
jne 0xfa64
movb -0x1(%rcx), %r13b
movzbl %r13b, %r11d
leal -0x31(%r11), %r9d
cmpl $0x3, %r9d
jb 0xf9fb
cmpl $0x41, %r11d
je 0xfa5b
cmpl $0x20, %r11d
jne 0xfa64
movb %r13b, (%rcx)
movb $0x4e, -0x1(%rcx)
movslq %r15d, %r15
movl %esi, 0x18(%rsp,%r15,4)
incl %r15d
jmp 0xfa64
cmpl $0x4f, %r13d
je 0xfa31
cmpl $0x4e, %r13d
jne 0xfa64
cmpb $0x20, -0x1(%rcx)
jne 0xfa64
movl %esi, %r12d
jmp 0xfa64
cmpb $0x41, -0x1(%rcx)
jne 0xfa3c
movl %esi, %r10d
jmp 0xfa64
cmpb $0x20, -0x1(%rcx)
jne 0xfa48
movl %esi, %r8d
jmp 0xfa64
cmpb $0x20, -0x1(%rcx)
jne 0xfa64
movl %esi, 0x4(%rsp)
jmp 0xfa64
cmpb $0x54, -0x1(%rcx)
jne 0xfa52
movl %esi, %edx
jmp 0xfa64
cmpb $0x58, -0x1(%rcx)
cmovel %esi, %edx
jmp 0xfa64
movslq %edi, %rdi
movl %esi, 0x8(%rsp,%rdi,4)
incl %edi
incl %esi
addq $0x70, %rcx
cmpl %esi, %ebx
jne 0xf9c2
testl %r12d, %r12d
js 0xfabd
movl %r12d, %eax
imulq $0x70, %rax, %rsi
addq %r14, %rsi
leaq 0x5bd28(%rip), %rdi     # 0x6b7b0
movl $0xe, %ecx
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %r15d
leaq 0x5bd83(%rip), %rax     # 0x6b820
jmp 0xfac0
xorl %r15d, %r15d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
jmp 0xfac7
xorl %r15d, %r15d
leaq 0x59599(%rip), %r11     # 0x69060
testl %ebp, %ebp
je 0xfb0a
xorl %r12d, %r12d
movl 0x4(%rsp), %r9d
movslq 0x18(%rsp,%r12,4), %rcx
testq %rcx, %rcx
js 0xfafa
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl $0x1, %ecx
jmp 0xfafc
xorl %ecx, %ecx
addl %ecx, %r15d
incq %r12
cmpq $0x3, %r12
jne 0xfad3
jmp 0xfb0f
movl 0x4(%rsp), %r9d
testl %r10d, %r10d
js 0xfb35
movl %r10d, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl $0x1, %r10d
jmp 0xfb38
xorl %r10d, %r10d
addl %r15d, %r10d
cmpl $0x0, (%r11)
je 0xfb79
xorl %r11d, %r11d
movslq 0x8(%rsp,%r11,4), %rcx
testq %rcx, %rcx
js 0xfb6b
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl $0x1, %ecx
jmp 0xfb6d
xorl %ecx, %ecx
addl %ecx, %r10d
incq %r11
cmpq $0x3, %r11
jne 0xfb44
movl %r9d, %ecx
notl %ecx
sarl $0x1f, %ecx
addl %ebx, %ecx
movl %r8d, %r11d
notl %r11d
sarl $0x1f, %r11d
addl %ecx, %r11d
cmpl %r11d, %r10d
je 0xfcdb
testl %ebx, %ebx
jle 0xfc84
movl %ebx, %r15d
imulq $0x70, %r15, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpb $0x42, 0x19(%r14,%r13)
jne 0xfbca
leaq (%r14,%r13), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %ebp
addq $0x70, %r13
cmpq %r13, %r12
jne 0xfbad
addl %r10d, %ebp
cmpl %r11d, %ebp
je 0xfcd8
xorl %r13d, %r13d
xorl %r10d, %r10d
cmpb $0x47, 0x19(%r14,%r13)
jne 0xfc03
leaq (%r14,%r13), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %r10d
addq $0x70, %r13
cmpq %r13, %r12
jne 0xfbe5
addl %ebp, %r10d
cmpl %r11d, %r10d
je 0xfcd8
testl %ebx, %ebx
jle 0xfc84
imulq $0x70, %r15, %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpb $0x44, 0x19(%r14,%r12)
jne 0xfc42
leaq (%r14,%r12), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %ebp
addq $0x70, %r12
cmpq %r12, %r15
jne 0xfc25
addl %ebp, %r10d
cmpl %r11d, %r10d
je 0xfcd8
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpb $0x45, 0x19(%r14,%r12)
jne 0xfc79
leaq (%r14,%r12), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %ebp
addq $0x70, %r12
cmpq %r12, %r15
jne 0xfc5c
jmp 0xfc86
xorl %ebp, %ebp
testl %ebx, %ebx
setle %cl
addl %ebp, %r10d
cmpl %r11d, %r10d
sete %sil
orb %cl, %sil
jne 0xfcdb
movl %ebx, %r15d
imulq $0x70, %r15, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpb $0x5a, 0x19(%r14,%r13)
jne 0xfcc3
leaq (%r14,%r13), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %ebp
addq $0x70, %r13
cmpq %r13, %r12
jne 0xfca6
addl %r10d, %ebp
cmpl %r11d, %ebp
jne 0xfd99
movl %r11d, %r10d
xorl %r11d, %r11d
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
js 0xfd05
movl %ecx, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl $0x1, %ebp
jmp 0xfd07
xorl %ebp, %ebp
addl %r10d, %ebp
testl %r8d, %r8d
js 0xfd2e
movl %r8d, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl $0x1, %r11d
addl %r11d, %ebp
testl %edx, %edx
js 0xfd50
movl %edx, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %eax
jmp 0xfd52
xorl %eax, %eax
addl %eax, %ebp
cmpl %ebx, %ebp
jne 0xfe66
testl %ebx, %ebx
jle 0xfd88
movl %ebx, %eax
imulq $0x70, %rax, %rax
xorl %edx, %edx
leaq 0x5ba41(%rip), %r8      # 0x6b7b0
leaq (%r14,%rdx), %rdi
leaq (%r8,%rdx), %rsi
movl $0xe, %ecx
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rdx
cmpq %rdx, %rax
jne 0xfd6f
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
xorl %r10d, %r10d
cmpb $0x48, 0x19(%r14,%r13)
jne 0xfdbd
leaq (%r14,%r13), %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %r10d
addq $0x70, %r13
cmpq %r13, %r12
jne 0xfd9f
testl %ebx, %ebx
setle %cl
addl %ebp, %r10d
cmpl %r11d, %r10d
sete %sil
orb %cl, %sil
jne 0xfcdb
leaq 0x19(%r14), %r11
imulq $0x70, %r15, %r15
xorl %r12d, %r12d
movl $0x20020db, %ebp        # imm = 0x20020DB
movzbl -0x1(%r11,%r12), %ecx
cmpl $0x43, %ecx
je 0xfe1c
cmpl $0x4f, %ecx
je 0xfe05
cmpl $0x4e, %ecx
je 0xfe23
jmp 0xfe2a
cmpb $0x20, (%r11,%r12)
je 0xfe3c
cmpb $0x54, (%r11,%r12)
je 0xfe3c
cmpb $0x58, (%r11,%r12)
jne 0xfe2a
jmp 0xfe3c
cmpb $0x41, (%r11,%r12)
je 0xfe3c
cmpb $0x20, (%r11,%r12)
je 0xfe3c
movzbl (%r11,%r12), %ecx
addl $-0x41, %ecx
cmpl $0x19, %ecx
ja 0xfe4a
btl %ecx, %ebp
jae 0xfe4a
addq $0x70, %r12
cmpq %r12, %r15
jne 0xfdee
jmp 0xfcdb
leaq (%r11,%r12), %rsi
addq $-0x19, %rsi
movl $0xe, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
incl %r10d
jmp 0xfe3c
leaq 0x46171(%rip), %rdi     # 0x55fde
callq 0x2090
movsbl 0x68(%r14), %edx
movl 0x64(%r14), %esi
movl 0x6c(%r14), %ecx
leaq 0x46087(%rip), %rdi     # 0x55f0d
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280