// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movl %esi, %r10d
movq %rdi, %rbx
leaq 0x593b5(%rip), %rax     # 0x69060
movl (%rax), %eax
movl %eax, 0x24(%rsp)
testl %eax, %eax
je 0xfcd3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x50(%rsp)
movq $-0x1, %rcx
movq %rcx, 0x48(%rsp)
movq %rcx, 0x38(%rsp)
movl %eax, 0x40(%rsp)
testl %r10d, %r10d
jle 0xfe49
leaq 0x18(%rbx), %r14
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorl %r13d, %r13d
leaq 0x46231(%rip), %r15     # 0x55f23
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %r10d, %r12d
movl $0x2, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2070
testl %eax, %eax
je 0xfe00
movl $0x2, %edx
movq %r14, %rdi
leaq 0x4541f(%rip), %rsi     # 0x5516a
callq 0x2070
testl %eax, %eax
je 0xfe05
movl $0x2, %edx
movq %r14, %rdi
leaq 0x461bf(%rip), %rsi     # 0x55f26
callq 0x2070
testl %eax, %eax
je 0xfe0c
movl $0x2, %edx
movq %r14, %rdi
leaq 0x461a6(%rip), %rsi     # 0x55f29
callq 0x2070
testl %eax, %eax
je 0xfe1a
movl $0x2, %edx
movq %r14, %rdi
leaq 0x4618d(%rip), %rsi     # 0x55f2c
callq 0x2070
testl %eax, %eax
je 0xfe13
movl $0x2, %edx
movq %r14, %rdi
leaq 0x46178(%rip), %rsi     # 0x55f2f
callq 0x2070
testl %eax, %eax
je 0xfe13
cmpb $0x48, (%r14)
movl %r12d, %r10d
jne 0xfe22
movb 0x1(%r14), %al
movzbl %al, %ecx
leal -0x31(%rcx), %edx
cmpl $0x3, %edx
jb 0xfde2
cmpl $0x41, %ecx
je 0xfe34
cmpl $0x20, %ecx
jne 0xfe22
movb %al, 0x2(%r14)
movb $0x4e, 0x1(%r14)
movq 0x30(%rsp), %rax
cltq
movl %r13d, 0x48(%rsp,%rax,4)
incl %eax
movq %rax, 0x30(%rsp)
jmp 0xfe22
movl %r13d, %ebp
jmp 0xfe1f
movl %r13d, 0x18(%rsp)
jmp 0xfe1f
movl %r13d, 0x10(%rsp)
jmp 0xfe1f
movl %r13d, 0x14(%rsp)
jmp 0xfe1f
movl %r13d, 0xc(%rsp)
movl %r12d, %r10d
incl %r13d
addq $0x70, %r14
cmpl %r13d, %r10d
jne 0xfd21
jmp 0xfe6e
movq 0x28(%rsp), %rax
cltq
movl %r13d, 0x38(%rsp,%rax,4)
incl %eax
movq %rax, 0x28(%rsp)
jmp 0xfe22
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
testl %ebp, %ebp
js 0xfe98
movl %ebp, %eax
imulq $0x70, %rax, %rsi
addq %rbx, %rsi
leaq 0x5b92e(%rip), %rdi     # 0x6b7b0
movl $0xe, %ecx
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %eax
leaq 0x5b98a(%rip), %r14     # 0x6b820
jmp 0xfea1
xorl %eax, %eax
leaq 0x5b90f(%rip), %r14     # 0x6b7b0
movl 0xc(%rsp), %r11d
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r8d
cmpl $0x0, 0x24(%rsp)
je 0xfeec
xorl %edx, %edx
movslq 0x48(%rsp,%rdx,4), %rcx
testq %rcx, %rcx
js 0xfedf
imulq $0x70, %rcx, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
movl $0x1, %ecx
jmp 0xfee1
xorl %ecx, %ecx
addl %ecx, %eax
incq %rdx
cmpq $0x3, %rdx
jne 0xfeb8
testl %r8d, %r8d
js 0xff12
movl %r8d, %ecx
imulq $0x70, %rcx, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
movl $0x1, %r13d
jmp 0xff15
xorl %r13d, %r13d
addl %eax, %r13d
leaq 0x59141(%rip), %rax     # 0x69060
cmpl $0x0, (%rax)
je 0xff5b
xorl %eax, %eax
movslq 0x38(%rsp,%rax,4), %rcx
testq %rcx, %rcx
js 0xff4d
imulq $0x70, %rcx, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
movl $0x1, %ecx
jmp 0xff4f
xorl %ecx, %ecx
addl %ecx, %r13d
incq %rax
cmpq $0x3, %rax
jne 0xff26
movl %ebp, %ecx
notl %ecx
sarl $0x1f, %ecx
addl %r10d, %ecx
movl %r11d, %eax
notl %eax
sarl $0x1f, %eax
addl %ecx, %eax
movl %r10d, %r15d
cmpl %eax, %r13d
movq %r15, 0x18(%rsp)
je 0x10218
testl %r10d, %r10d
jle 0xffb6
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %edx, %edx
cmpb $0x42, 0x19(%rbx,%r9)
jne 0xffab
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %edx
addq $0x70, %r9
cmpq %r9, %r8
jne 0xff8e
jmp 0xffb8
xorl %edx, %edx
addl %edx, %r13d
cmpl %eax, %r13d
je 0x10218
testl %r10d, %r10d
jle 0xfffa
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %edx, %edx
cmpb $0x47, 0x19(%rbx,%r9)
jne 0xffef
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %edx
addq $0x70, %r9
cmpq %r9, %r8
jne 0xffd2
jmp 0xfffc
xorl %edx, %edx
addl %edx, %r13d
cmpl %eax, %r13d
je 0x10218
testl %r10d, %r10d
jle 0x1003e
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %edx, %edx
cmpb $0x44, 0x19(%rbx,%r9)
jne 0x10033
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %edx
addq $0x70, %r9
cmpq %r9, %r8
jne 0x10016
jmp 0x10040
xorl %edx, %edx
addl %edx, %r13d
cmpl %eax, %r13d
je 0x10218
testl %r10d, %r10d
jle 0x10082
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %edx, %edx
cmpb $0x45, 0x19(%rbx,%r9)
jne 0x10077
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %edx
addq $0x70, %r9
cmpq %r9, %r8
jne 0x1005a
jmp 0x10084
xorl %edx, %edx
addl %edx, %r13d
cmpl %eax, %r13d
je 0x10218
testl %r10d, %r10d
jle 0x100c6
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %edx, %edx
cmpb $0x5a, 0x19(%rbx,%r9)
jne 0x100bb
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %edx
addq $0x70, %r9
cmpq %r9, %r8
jne 0x1009e
jmp 0x100c8
xorl %edx, %edx
addl %r13d, %edx
cmpl %eax, %edx
jne 0x100d7
movl %edx, %r13d
jmp 0x10218
testl %r10d, %r10d
jle 0x1010f
imulq $0x70, %r15, %r8
xorl %r9d, %r9d
xorl %r13d, %r13d
cmpb $0x48, 0x19(%rbx,%r9)
jne 0x10104
leaq (%rbx,%r9), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %r13d
addq $0x70, %r9
cmpq %r9, %r8
jne 0x100e6
jmp 0x10112
xorl %r13d, %r13d
addl %edx, %r13d
cmpl %eax, %r13d
sete %al
testl %r10d, %r10d
setle %cl
orb %al, %cl
jne 0x10218
leaq 0x18(%rbx), %r15
movq 0x18(%rsp), %r12
movl %r10d, %ebp
movl $0x2, %edx
movq %r15, %rdi
leaq 0x45ddf(%rip), %rsi     # 0x55f23
callq 0x2070
testl %eax, %eax
je 0x101ff
movl $0x2, %edx
movq %r15, %rdi
leaq 0x4500a(%rip), %rsi     # 0x5516a
callq 0x2070
testl %eax, %eax
je 0x101ff
movl $0x2, %edx
movq %r15, %rdi
leaq 0x45daa(%rip), %rsi     # 0x55f26
callq 0x2070
testl %eax, %eax
je 0x101ff
movl $0x2, %edx
movq %r15, %rdi
leaq 0x45d95(%rip), %rsi     # 0x55f29
callq 0x2070
testl %eax, %eax
je 0x101ff
movl $0x2, %edx
movq %r15, %rdi
leaq 0x45d80(%rip), %rsi     # 0x55f2c
callq 0x2070
testl %eax, %eax
je 0x101ff
movl $0x2, %edx
movq %r15, %rdi
leaq 0x45d6b(%rip), %rsi     # 0x55f2f
callq 0x2070
testl %eax, %eax
je 0x101ff
movzbl 0x1(%r15), %eax
addl $-0x41, %eax
cmpl $0x19, %eax
movl %ebp, %r10d
ja 0x101e7
movl $0x20020db, %ecx        # imm = 0x20020DB
btl %eax, %ecx
jb 0x10202
leaq -0x18(%r15), %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
incl %r13d
jmp 0x10202
movl %ebp, %r10d
movl 0xc(%rsp), %r11d
movl 0x10(%rsp), %ebp
addq $0x70, %r15
decq %r12
jne 0x10132
xorl %eax, %eax
testl %ebp, %ebp
js 0x1023e
movl %ebp, %ecx
imulq $0x70, %rcx, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
movl $0x1, %r15d
jmp 0x10241
xorl %r15d, %r15d
addl %r13d, %r15d
testl %r11d, %r11d
js 0x10267
movl %r11d, %eax
imulq $0x70, %rax, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %r14
movl $0x1, %eax
movl 0x14(%rsp), %ecx
addl %eax, %r15d
testl %ecx, %ecx
js 0x1028d
movl %ecx, %eax
imulq $0x70, %rax, %rsi
addq %rbx, %rsi
movl $0xe, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %eax
jmp 0x1028f
xorl %eax, %eax
addl %eax, %r15d
cmpl %r10d, %r15d
jne 0x102d6
testl %r10d, %r10d
jle 0x102c4
imulq $0x70, 0x18(%rsp), %rax
xorl %edx, %edx
leaq 0x5b505(%rip), %r8      # 0x6b7b0
leaq (%rbx,%rdx), %rdi
leaq (%r8,%rdx), %rsi
movl $0xe, %ecx
rep  movsq (%rsi), %es:(%rdi)
addq $0x70, %rdx
cmpq %rdx, %rax
jne 0x102ab
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45d26(%rip), %rdi     # 0x56003
movl %r10d, %ebp
callq 0x2090
movsbl 0x68(%rbx), %edx
movl 0x64(%rbx), %esi
movl 0x6c(%rbx), %ecx
leaq 0x45c3c(%rip), %rdi     # 0x55f32
movl %ebp, %r8d
movl %r15d, %r9d
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270