// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdi, %r14
leaq 0x55100(%rip), %r9      # 0x64060
movl (%r9), %edx
testl %edx, %edx
je 0xef7e
xorl %eax, %eax
cmpq $0x3, %rax
je 0xef7e
orl $-0x1, 0x3c(%rsp,%rax,4)
orl $-0x1, 0x30(%rsp,%rax,4)
incq %rax
jmp 0xef69
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %r8d
movl %esi, 0x2c(%rsp)
cmovgl %esi, %r8d
leaq 0x1a(%r14), %rsi
pushq $-0x1
popq %rcx
movl %ecx, %r10d
movl %ecx, 0xc(%rsp)
movl %ecx, %ebx
movl %ecx, %r12d
xorl %edi, %edi
xorl %r11d, %r11d
cmpl %r11d, %r8d
je 0xf052
movzbl -0x2(%rsi), %ebp
cmpl $0x43, %ebp
je 0xf00f
cmpl $0x48, %ebp
je 0xefd4
cmpl $0x4f, %ebp
je 0xf004
cmpl $0x4e, %ebp
jne 0xf046
cmpb $0x20, -0x1(%rsi)
jne 0xf046
movl %r11d, %ecx
jmp 0xf046
movb -0x1(%rsi), %bpl
movzbl %bpl, %r15d
leal -0x31(%r15), %r13d
cmpl $0x3, %r13d
jb 0xeff2
cmpl $0x41, %r15d
je 0xf03c
cmpl $0x20, %r15d
jne 0xf046
movb %bpl, (%rsi)
movb $0x4e, -0x1(%rsi)
cltq
movl %r11d, 0x3c(%rsp,%rax,4)
incl %eax
jmp 0xf046
cmpb $0x20, -0x1(%rsi)
jne 0xf01a
movl %r11d, %ebx
jmp 0xf046
cmpb $0x41, -0x1(%rsi)
jne 0xf025
movl %r11d, %r10d
jmp 0xf046
cmpb $0x54, -0x1(%rsi)
jne 0xf032
movl %r11d, %r12d
jmp 0xf046
cmpb $0x20, -0x1(%rsi)
jne 0xf046
movl %r11d, 0xc(%rsp)
jmp 0xf046
cmpb $0x58, -0x1(%rsi)
cmovel %r11d, %r12d
jmp 0xf046
movslq %edi, %rdi
movl %r11d, 0x30(%rsp,%rdi,4)
incl %edi
incl %r11d
addq $0x70, %rsi
jmp 0xefa8
leaq 0x57757(%rip), %rax     # 0x667b0
movq %rax, 0x10(%rsp)
testl %ecx, %ecx
js 0xf08a
pushq $0x1
popq %r11
movl %ecx, %eax
imulq $0x70, %rax, %rsi
addq %r14, %rsi
leaq 0x5773a(%rip), %rdi     # 0x667b0
pushq $0xe
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x5779d(%rip), %rax     # 0x66820
movq %rax, 0x10(%rsp)
jmp 0xf08d
xorl %r11d, %r11d
testl %edx, %edx
je 0xf0d1
xorl %r15d, %r15d
pushq $0xe
popq %rdx
pushq $0x1
popq %rbp
cmpq $0x3, %r15
je 0xf0cc
movslq 0x3c(%rsp,%r15,4), %rcx
testq %rcx, %rcx
js 0xf0c2
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movq %rdx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl %ebp, %ecx
jmp 0xf0c4
xorl %ecx, %ecx
addl %ecx, %r11d
incq %r15
jmp 0xf09a
movq %rax, 0x10(%rsp)
testl %r10d, %r10d
js 0xf0f8
movl %r10d, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
pushq $0xe
popq %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r15
jmp 0xf0fb
xorl %r15d, %r15d
addl %r11d, %r15d
cmpl $0x0, (%r9)
je 0xf14d
xorl %r9d, %r9d
pushq $0xe
popq %rdx
pushq $0x1
popq %r10
movl 0xc(%rsp), %r11d
cmpq $0x3, %r9
je 0xf146
movslq 0x30(%rsp,%r9,4), %rcx
testq %rcx, %rcx
js 0xf13c
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
movq %rdx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movl %r10d, %ecx
jmp 0xf13e
xorl %ecx, %ecx
addl %ecx, %r15d
incq %r9
jmp 0xf113
movq %rax, 0x10(%rsp)
jmp 0xf152
movl 0xc(%rsp), %r11d
movl %r11d, %eax
notl %eax
sarl $0x1f, %eax
movl 0x2c(%rsp), %r10d
addl %r10d, %eax
movl %ebx, %r13d
notl %r13d
sarl $0x1f, %r13d
addl %eax, %r13d
movl %r8d, %r8d
cmpl %r13d, %r15d
jne 0xf17f
movl %r15d, %r13d
jmp 0xf22f
movq %r8, 0x20(%rsp)
movl %ebx, 0x1c(%rsp)
leaq 0x10(%rsp), %rdi
pushq $0x42
popq %rsi
movq %r14, %rdx
movl %r10d, %ecx
movl %r10d, %ebx
callq 0xf41a
movl %eax, %ebp
addl %r15d, %ebp
cmpl %r13d, %ebp
je 0xf21e
leaq 0x10(%rsp), %rdi
pushq $0x47
popq %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xf41a
movl %eax, %r15d
addl %ebp, %r15d
cmpl %r13d, %r15d
je 0xf21e
leaq 0x10(%rsp), %rdi
pushq $0x44
popq %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xf41a
movl %eax, %ebp
addl %r15d, %ebp
cmpl %r13d, %ebp
je 0xf21e
leaq 0x10(%rsp), %rdi
pushq $0x45
popq %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xf41a
movl %eax, %r15d
addl %ebp, %r15d
cmpl %r13d, %r15d
je 0xf21e
leaq 0x10(%rsp), %rdi
pushq $0x5a
popq %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xf41a
movl %eax, %ebp
addl %r15d, %ebp
cmpl %r13d, %ebp
jne 0xf2f3
movl %ebx, %r10d
movl 0x1c(%rsp), %ebx
movl 0xc(%rsp), %r11d
movq 0x20(%rsp), %r8
xorl %edx, %edx
movl $0x0, %ebp
testl %r11d, %r11d
js 0xf25f
movq 0x10(%rsp), %rax
movl %r11d, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
pushq $0xe
popq %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rbp
addl %r13d, %ebp
testl %ebx, %ebx
js 0xf289
movq 0x10(%rsp), %rax
movl %ebx, %ecx
imulq $0x70, %rcx, %rsi
addq %r14, %rsi
pushq $0xe
popq %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rdx
addl %edx, %ebp
testl %r12d, %r12d
js 0xf2aa
movq 0x10(%rsp), %rdi
movl %r12d, %eax
imulq $0x70, %rax, %rsi
addq %r14, %rsi
pushq $0xe
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
pushq $0x1
popq %rax
jmp 0xf2ac
xorl %eax, %eax
addl %eax, %ebp
cmpl %r10d, %ebp
jne 0xf3be
imulq $0x70, %r8, %rdx
xorl %r8d, %r8d
leaq 0x574eb(%rip), %r9      # 0x667b0
pushq $0xe
popq %rax
cmpq %r8, %rdx
je 0xf2e1
leaq (%r14,%r8), %rdi
leaq (%r9,%r8), %rsi
movq %rax, %rcx
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r8
jmp 0xf2c8
movl %r10d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
pushq $0x48
popq %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xf41a
addl %ebp, %eax
cmpl %r13d, %eax
movl %ebx, %r10d
movl 0x1c(%rsp), %ebx
movl 0xc(%rsp), %r11d
movq 0x20(%rsp), %r8
je 0xf22f
movq 0x10(%rsp), %rdx
imulq $0x70, %r8, %r9
leaq 0x19(%r14), %r10
xorl %r11d, %r11d
pushq $0xe
popq %r8
movl $0x20020db, %ebp        # imm = 0x20020DB
cmpq %r11, %r9
je 0xf3ac
movzbl -0x1(%r10,%r11), %ecx
cmpl $0x43, %ecx
je 0xf36d
cmpl $0x4f, %ecx
je 0xf356
cmpl $0x4e, %ecx
je 0xf374
jmp 0xf37b
cmpb $0x20, (%r10,%r11)
je 0xf38d
cmpb $0x54, (%r10,%r11)
je 0xf38d
cmpb $0x58, (%r10,%r11)
jne 0xf37b
jmp 0xf38d
cmpb $0x41, (%r10,%r11)
je 0xf38d
cmpb $0x20, (%r10,%r11)
je 0xf38d
movzbl (%r10,%r11), %ecx
addl $-0x41, %ecx
cmpl $0x19, %ecx
ja 0xf393
btl %ecx, %ebp
jae 0xf393
addq $0x70, %r11
jmp 0xf33a
leaq (%r10,%r11), %rsi
addq $-0x19, %rsi
movq %r8, %rcx
movq %rdx, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rdx
incl %eax
jmp 0xf38d
movq %rdx, 0x10(%rsp)
movl %eax, %r13d
movl 0x2c(%rsp), %r10d
jmp 0xf225
leaq 0x40b69(%rip), %rdi     # 0x4ff2e
movl %r10d, %ebx
callq 0x2090
movsbl 0x68(%r14), %edx
movl 0x64(%r14), %esi
movl 0x6c(%r14), %ecx
leaq 0x40a7c(%rip), %rdi     # 0x4fe5d
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270