// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/dof_tnm.c
// Function: Axe_prot_side
void Axe_prot_side(struct axe *axe_side, int *N_side, struct side_chain *sc,
		   struct bond *bond, int ibond,
		   atom *atoms, int natoms, int *refatom)
{
  if(bond->atom->res!=sc->res){
    // Residue start
    sc->res=bond->atom->res;
    sc->aa= bond->atom->aa;
    if((sc->aa=='G')||(sc->aa=='A')||(sc->aa=='P'))return;
    
    // Find first and last atom in side chain
    sc->first_atom=-1;
    sc->last_atom=-1;
    sc->first_ref=-1;
    sc->last_ref=-1;
    int i;
    for(i=bond->i_atom; i<natoms; i++){
      atom *atom_i=atoms+i;
      if((atom_i->res>sc->res)||
	 (strncmp(atom_i->name,"OT", 2)==0)||
	 (strncmp(atom_i->name,"OX", 2)==0))
	break;
      if((strncmp(atom_i->name,"N ", 2)==0)||
	 (strncmp(atom_i->name,"CA", 2)==0)||
	 (strncmp(atom_i->name,"CB", 2)==0))continue;
      if((strncmp(atom_i->name,"C ", 2)!=0)&&
	 (strncmp(atom_i->name,"O ", 2)!=0)){
	sc->last_atom=i;
	if(sc->first_atom<0)sc->first_atom=i;
	int iref=refatom[i];
	if(iref>=0){
	  sc->last_ref=iref; if(sc->first_ref<0)sc->first_ref=iref;
	}
      }
    }
    sc->ndof=0; sc->numdof=0; sc->oldref=0;
  }
  
  if((bond->terminal)||
     (strncmp(bond->atom->name,"N ", 2)==0)||
     (strncmp(bond->atom->name,"CA", 2)==0)||
     (strncmp(bond->atom->name,"C ", 2)==0)||
     (strncmp(bond->atom->name,"O ", 2)==0))
    return;
    
  if((sc->first_atom<0)||(sc->first_ref<0)||
     (sc->aa=='G')||(sc->aa=='A')||(sc->aa=='P'))return;
  
  if(((strncmp(bond->atom->name,"CB", 2)!=0)&&
      (strncmp(bond->atom->name,"CG", 2)==0))&&
     ((sc->aa=='F')||(sc->aa=='W')||(sc->aa=='Y')||(sc->aa=='H'))){
    return;  // if aromatic ring, exit
  }

  //sprintf(type, "%1d", sc->numdof);
  struct axe *axe=axe_side+*N_side;
  int first_atom=(Next_bond(bond, ibond, natoms))->i_atom;
  if(Set_dof(&axe, N_side, 's', bond, first_atom, &sc->ndof,
	     &sc->oldref, refatom, natoms, sc->last_atom, sc->last_ref)){
    sc->numdof++;
  }
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq 0x48(%rsp), %rbp
movl 0x40(%rsp), %r14d
movq (%rcx), %rax
movl 0x64(%rax), %ecx
cmpl 0x4(%rdx), %ecx
jne 0x12e82
cmpl $0x0, 0x30(%r15)
jne 0x12e9d
movzbl 0x18(%rax), %ecx
cmpl $0x43, %ecx
je 0x12f60
cmpl $0x4f, %ecx
je 0x12dc4
cmpl $0x4e, %ecx
jne 0x12dce
cmpb $0x20, 0x19(%rax)
je 0x12e9d
xorl %ecx, %ecx
cmpl $0x0, 0xc(%rbx)
js 0x12e9d
cmpl $0x0, 0x10(%rbx)
js 0x12e9d
movzbl (%rbx), %edx
leal -0x41(%rdx), %esi
cmpl $0xf, %esi
ja 0x12dff
movl $0x8041, %r9d           # imm = 0x8041
btl %esi, %r9d
jb 0x12e9d
testb %cl, %cl
je 0x12e21
cmpb $0x42, 0x19(%rax)
je 0x12e21
cmpb $0x47, 0x19(%rax)
jne 0x12e21
addl $-0x46, %edx
cmpl $0x13, %edx
ja 0x12e21
movl $0xa0005, %eax          # imm = 0xA0005
btl %edx, %eax
jb 0x12e9d
movslq (%r12), %rax
imulq $0x158, %rax, %rax      # imm = 0x158
addq %rax, %rdi
movq %rsp, %r13
movq %rdi, (%r13)
movq %r15, %rdi
movl %r8d, %esi
movl %r14d, %edx
callq 0x12fb0
movl 0x20(%rax), %r8d
leaq 0x1c(%rbx), %r9
leaq 0x20(%rbx), %rax
movl 0x14(%rbx), %r10d
movl 0x18(%rbx), %r11d
subq $0x8, %rsp
pushq $0x73
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rcx
pushq %r11
pushq %r10
pushq %r14
pushq %rbp
pushq %rax
callq 0x12a3b
addq $0x30, %rsp
testl %eax, %eax
je 0x12e9d
incl 0x24(%rbx)
jmp 0x12e9d
movl %ecx, 0x4(%rbx)
movzbl 0x68(%rax), %edx
movb %dl, (%rbx)
addl $-0x41, %edx
cmpl $0xf, %edx
ja 0x12eac
movl $0x8041, %esi           # imm = 0x8041
btl %edx, %esi
jae 0x12eac
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc(%rbx), %rdx
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xc(%rbx)
movslq 0x20(%r15), %rsi
movslq %r14d, %r10
imulq $0x70, %rsi, %r11
addq %r11, %r9
addq $0x18, %r9
pushq $-0x1
popq %r11
movl %r11d, %r14d
cmpq %r10, %rsi
jge 0x12f4d
cmpl %ecx, 0x4c(%r9)
jg 0x12f4d
movzbl (%r9), %r13d
cmpl $0x43, %r13d
je 0x12f03
cmpl $0x4e, %r13d
je 0x12f11
cmpl $0x4f, %r13d
jne 0x12f18
cmpb $0x54, 0x1(%r9)
je 0x12f4d
cmpb $0x58, 0x1(%r9)
jne 0x12f11
jmp 0x12f4d
cmpb $0x41, 0x1(%r9)
je 0x12f38
cmpb $0x42, 0x1(%r9)
je 0x12f38
cmpb $0x20, 0x1(%r9)
je 0x12f38
movl %esi, 0x14(%rbx)
testl %r14d, %r14d
jns 0x12f25
movl %esi, (%rdx)
movl %esi, %r14d
movl (%rbp,%rsi,4), %r13d
testl %r13d, %r13d
js 0x12f38
movl %r13d, 0x18(%rbx)
testl %r11d, %r11d
js 0x12f47
movl %r11d, %r13d
incq %rsi
addq $0x70, %r9
movl %r13d, %r11d
jmp 0x12ed2
movl %r13d, 0x10(%rbx)
jmp 0x12f3b
andq $0x0, 0x1c(%rbx)
andl $0x0, 0x24(%rbx)
movl 0x40(%rsp), %r14d
jmp 0x12da2
cmpb $0x41, 0x19(%rax)
je 0x12e9d
movb $0x1, %cl
cmpb $0x20, 0x19(%rax)
jne 0x12dd0
jmp 0x12e9d