// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movb %dl, %al
movl 0x30(%rbp), %edx
movl 0x28(%rbp), %edx
movl 0x20(%rbp), %edx
movq 0x18(%rbp), %rdx
movq 0x10(%rbp), %rdx
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq %rcx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movq %r9, -0x40(%rbp)
movl -0x34(%rbp), %edi
movl 0x20(%rbp), %esi
movq 0x18(%rbp), %rdx
callq 0x1b320
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x1a43d
cmpl $0x0, 0x30(%rbp)
jl 0x1a43d
movl 0x30(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x1a546
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rsi
addq $0x18, %rsi
movq -0x50(%rbp), %rax
movsbl 0x68(%rax), %edx
movq -0x50(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x50(%rbp), %rax
movl 0x6c(%rax), %r8d
movq -0x58(%rbp), %r9
addq $0x18, %r9
movq -0x58(%rbp), %rax
movsbl 0x68(%rax), %ebx
movq -0x58(%rbp), %rax
movl 0x64(%rax), %r11d
movq -0x58(%rbp), %rax
movl 0x6c(%rax), %r10d
movsbl -0x21(%rbp), %eax
leaq 0x61470(%rip), %rdi     # 0x7b911
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x10d0
leaq 0x6147e(%rip), %rdi     # 0x7b93e
movb $0x0, %al
callq 0x10d0
movl -0x34(%rbp), %esi
movl 0x28(%rbp), %edx
movl -0x44(%rbp), %ecx
movl 0x30(%rbp), %r8d
leaq 0x6147a(%rip), %rdi     # 0x7b955
movb $0x0, %al
callq 0x10d0
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq 0x18(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x61485(%rip), %rdi     # 0x7b984
movb $0x0, %al
callq 0x10d0
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
addq $0x18, %rsi
movq -0x58(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x58(%rbp), %rax
movsbl 0x68(%rax), %ecx
leaq 0x61477(%rip), %rdi     # 0x7b9aa
movb $0x0, %al
callq 0x10d0
movl $0x0, -0xc(%rbp)
jmp 0x1a636
movq -0x40(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x1a57d
movl -0x44(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x1a57d
movl -0x44(%rbp), %esi
movq 0x10(%rbp), %rax
movl (%rax), %edx
leaq 0x61453(%rip), %rdi     # 0x7b9bd
movb $0x0, %al
callq 0x10d0
movl $0x0, -0xc(%rbp)
jmp 0x1a636
movl -0x44(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x1a59d
movl -0x44(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl $0x0, (%rax)
jmp 0x1a5a8
movq -0x40(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movb -0x21(%rbp), %cl
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x10(%rax)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x18(%rax)
movl 0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x14(%rax)
movl 0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x1c(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x158, %rcx            # imm = 0x158
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x1, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x78, %rsp
popq %rbx
popq %rbp
retq