// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/dof_tnm.c
// Function: Set_dof
int Set_dof(struct axe **axe, int *num_dof,
	    char type, struct bond *bond, int first_atom,
	    int *ndof, int *oldref, int *refatom, int natoms,
	    int last_atom, int last_ref)
{
  /* Before updating the reference atom, maximum 3 degrees of freedom
     can be accepted   */
  int iref=Find_ref(first_atom, natoms, refatom);
  if((iref<0)||(last_ref<0)||(last_ref<iref)){
    atom *atom1=bond->previous->atom, *atom2=bond->atom;
    printf("\nWARNING, axe %s/%c%d/%d %s/%c%d/%d type %c ",
	   atom1->name, atom1->aa, atom1->res, atom1->chain,
	   atom2->name, atom2->aa, atom2->res, atom2->chain, type);
    printf("doesn't move any atom\n");
    printf("First: %d Last: %d first_ref: %d last_ref: %d\n",
	   first_atom, last_atom, iref, last_ref);
    printf("Refatom[first]= %d Refatom[last]= %d\n",
	   refatom[first_atom], refatom[last_atom]); 
    atom2=(bond+1)->atom;
    printf("Next bond: %s%d%c\n", atom2->name, atom2->res, atom2->aa);
    return(0);
  }

  if((*ndof >= 2)&&(iref <= *oldref)){
    printf("=(%d-%d)",iref, *oldref); return(0);
  }
  if(iref > *oldref){
    *oldref=iref; *ndof=0;
  }else{
    (*ndof)++;
  }

  //printf("%c%s-%s", type, bond->previous->atom->name, bond->atom->name);
  (*axe)->type=type; //l,a,t=(p,f,o)(1,2,3,4,5,6)(s)
  (*axe)->bond=bond;
  // rotation axe associated to dof
  /*if((type=='l')||(type=='a')){(*axe)->bond=bond;}
    else{(*axe)->bond=bond->previous;} // Torsion */

  (*axe)->first_atom=first_atom;
  (*axe)->first_kin=iref;
  (*axe)->last_atom=last_atom;
  (*axe)->last_kin=last_ref;
  (*axe)->first_side=-1;
  (*axe)->rigid=0;
  (*axe)++;
  (*num_dof)++;
  return(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %r14
movl %r8d, %ebp
movq %rcx, %rbx
movl %edx, %r13d
movq %rsi, (%rsp)
movq %rdi, %r15
movl 0x60(%rsp), %r12d
movq 0x48(%rsp), %rdx
movl 0x50(%rsp), %esi
movl %r8d, %edi
callq 0x13217
movl %r12d, %r9d
movl %eax, %r12d
orl %r9d, %eax
setns %al
cmpl %r9d, %r12d
setle %cl
testb %al, %cl
jne 0x12b44
movq (%rbx), %rax
movq 0x28(%rbx), %rcx
movq (%rcx), %rdi
leaq 0x18(%rdi), %rsi
movsbl 0x68(%rdi), %edx
movl 0x64(%rdi), %ecx
movl 0x6c(%rdi), %r8d
leaq 0x18(%rax), %r9
movsbl 0x68(%rax), %r10d
movl 0x64(%rax), %r11d
movl 0x6c(%rax), %r14d
movsbl %r13b, %r15d
leaq 0x3dc54(%rip), %rdi     # 0x50712
xorl %r13d, %r13d
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x20f0
addq $0x20, %rsp
leaq 0x3dd63(%rip), %rdi     # 0x5083e
callq 0x2090
leaq 0x3dc58(%rip), %rdi     # 0x5073f
movl %ebp, %esi
movl 0x58(%rsp), %r14d
movl %r14d, %edx
movl %r12d, %ecx
movl 0x60(%rsp), %r8d
xorl %eax, %eax
callq 0x20f0
movslq %ebp, %rax
movq 0x48(%rsp), %rcx
movl (%rcx,%rax,4), %esi
movslq %r14d, %rax
movl (%rcx,%rax,4), %edx
leaq 0x3dc56(%rip), %rdi     # 0x5076e
xorl %eax, %eax
callq 0x20f0
movq 0xc0(%rbx), %rax
leaq 0x18(%rax), %rsi
movl 0x64(%rax), %edx
movsbl 0x68(%rax), %ecx
leaq 0x3dc5c(%rip), %rdi     # 0x50794
xorl %eax, %eax
callq 0x20f0
jmp 0x12bc4
movl 0x58(%rsp), %r8d
movq 0x40(%rsp), %rcx
movl (%r14), %eax
cmpl $0x2, %eax
setl %sil
movl (%rcx), %edx
cmpl %edx, %r12d
setg %dil
orb %sil, %dil
je 0x12b72
cmpl %edx, %r12d
jle 0x12b88
movl %r12d, (%rcx)
xorl %eax, %eax
jmp 0x12b8a
leaq 0x3dc2e(%rip), %rdi     # 0x507a7
xorl %r13d, %r13d
movl %r12d, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x12bc4
incl %eax
movl %eax, (%r14)
movq (%r15), %rax
movb %r13b, (%rax)
movq %rbx, 0x8(%rax)
movq (%r15), %rax
movl %ebp, 0x10(%rax)
movl %r12d, 0x18(%rax)
movl %r8d, 0x14(%rax)
movl %r9d, 0x1c(%rax)
orl $-0x1, 0x28(%rax)
andl $0x0, 0x4(%rax)
addq $0x158, %rax            # imm = 0x158
movq %rax, (%r15)
movq (%rsp), %rax
incl (%rax)
pushq $0x1
popq %r13
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq