// File: /workspace/github_c_makefile_star2_O3/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
movl %r8d, %r14d
movq %rcx, %r11
movl 0x60(%rsp), %r13d
movl 0x58(%rsp), %ebx
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rcx
movslq 0x50(%rsp), %rax
movslq %r8d, %r15
leaq 0x1(%r15), %r8
movl -0x4(%rbp,%r8,4), %r12d
testl %r12d, %r12d
jns 0x13cba
leaq 0x1(%r8), %r10
cmpq %rax, %r8
movq %r10, %r8
jl 0x13ca4
movl %r12d, %eax
orl %r13d, %eax
setns %al
cmpl %r13d, %r12d
setle %r8b
testb %al, %r8b
jne 0x13d90
movq (%r11), %rdi
movq 0x28(%r11), %rax
movq (%rax), %r8
leaq 0x18(%r8), %rsi
movsbl 0x68(%r8), %eax
movl 0x64(%r8), %ecx
movl 0x6c(%r8), %r8d
leaq 0x18(%rdi), %r9
movsbl 0x68(%rdi), %r10d
movq %r11, (%rsp)
movl 0x64(%rdi), %r11d
movl 0x6c(%rdi), %ebx
movsbl %dl, %r13d
leaq 0x42acd(%rip), %rdi     # 0x567da
movl %eax, %edx
xorl %eax, %eax
pushq %r13
pushq %rbx
xorl %ebx, %ebx
pushq %r11
pushq %r10
callq 0x20f0
addq $0x20, %rsp
leaq 0x42bdc(%rip), %rdi     # 0x56906
callq 0x2090
leaq 0x42ad1(%rip), %rdi     # 0x56807
movl %r14d, %esi
movl 0x58(%rsp), %r14d
movl %r14d, %edx
movl %r12d, %ecx
movl 0x60(%rsp), %r8d
xorl %eax, %eax
callq 0x20f0
movl (%rbp,%r15,4), %esi
movslq %r14d, %rax
movl (%rbp,%rax,4), %edx
leaq 0x42ad3(%rip), %rdi     # 0x56836
xorl %eax, %eax
callq 0x20f0
movq (%rsp), %rax
movq 0xc0(%rax), %rax
leaq 0x18(%rax), %rsi
movl 0x64(%rax), %edx
movsbl 0x68(%rax), %ecx
leaq 0x42ad5(%rip), %rdi     # 0x5685c
xorl %eax, %eax
callq 0x20f0
jmp 0x13e03
movl (%r9), %r8d
movl (%rcx), %eax
cmpl $0x2, %r8d
jl 0x13db7
cmpl %eax, %r12d
jg 0x13db7
leaq 0x42ac8(%rip), %rdi     # 0x5686f
xorl %ebx, %ebx
movl %r12d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20f0
jmp 0x13e03
cmpl %eax, %r12d
jle 0x13dc4
movl %r12d, (%rcx)
xorl %r8d, %r8d
jmp 0x13dc7
incl %r8d
movl %r8d, (%r9)
movq (%rdi), %rax
movb %dl, (%rax)
movq %r11, 0x8(%rax)
movq (%rdi), %rax
movl %r14d, 0x10(%rax)
movl %r12d, 0x18(%rax)
movl %ebx, 0x14(%rax)
movl %r13d, 0x1c(%rax)
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
movl $0x0, 0x4(%rax)
addq $0x158, %rax            # imm = 0x158
movq %rax, (%rdi)
incl (%rsi)
movl $0x1, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq