// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/buildup.c
// Function: Internal_coordinates
void Internal_coordinates(double *int_coord, int N_axes,
			  struct bond *bonds, int N_atoms)
{
  struct bond *bond; int i, k=0;
  for(i=0; i<N_axes; i++)int_coord[i]=0;
  for(i=1; i<N_atoms; i++){
    bond=bonds+i;
    if(bond->i_atom<0)break;
    if(bond->len >= 0){
      if(bond->len>=N_axes)goto error;
      int_coord[bond->len]=bond->l; k++;
      if(isnan(int_coord[bond->len]))goto error;
    }
    if(bond->angle >= 0){
      if(bond->angle>=N_axes)goto error;
      double c=bond->r_cos_theta/bond->l;
      if(c>1){c=1;}else if(c<-1){c=-1;}
      int_coord[bond->angle]=acos(c); k++;
      if(isnan(int_coord[bond->angle]))goto error;
    }
    if((bond->torsion >= 0)&&(bond->atom->main)){
      if(bond->torsion>=N_axes)goto error;
      double c=bond->phi;
      while(c > TWOPI){c-=TWOPI;}
      while(c <-TWOPI){c+=TWOPI;}
      int_coord[bond->torsion]=c; k++;
      if(isnan(int_coord[bond->torsion]))goto error;
    }
  }
  if(0)printf("%d internal coordinates over %d stored\n", k, N_axes);
  return;
 error:
  printf("ERROR in internal_coordinates, bond %d atom %s %c%d chain %d\n",
	 i, bond->atom->name, bond->atom->aa,
	 bond->atom->res, bond->atom->chain);
  printf("len: %d angle: %d torsion: %d Total_dofs= %d\n",
	 bond->len, bond->angle, bond->torsion, N_axes);
  if(bond->len>=0)printf("Len: %.2f\n", int_coord[bond->len]);
  if(bond->angle>=0)printf("Angle: %.2f\n", int_coord[bond->angle]);
  if(bond->torsion>=0)printf("Torsion: %.2f\n", int_coord[bond->torsion]);
  printf("r= %.2f r_cos_theta %.4f phi= %.4f\n",
	  bond->l, bond->r_cos_theta, bond->phi);
  exit(8);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
testl %esi, %esi
jle 0x16e31
movl %ebp, %edx
shlq $0x3, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
cmpl $0x2, %r15d
jl 0x16f47
movl %r15d, %r13d
movl $0x1, %r15d
leaq (%r15,%r15,2), %r12
shlq $0x6, %r12
cmpl $0x0, 0x20(%r14,%r12)
js 0x16f47
addq %r14, %r12
movslq 0x34(%r12), %rax
testq %rax, %rax
js 0x16e83
cmpl %ebp, %eax
jge 0x16f56
movsd 0x58(%r12), %xmm0
movsd %xmm0, (%rbx,%rax,8)
ucomisd %xmm0, %xmm0
jp 0x16f56
movl 0x38(%r12), %eax
testl %eax, %eax
js 0x16edf
cmpl %ebp, %eax
jge 0x16f56
movsd 0x60(%r12), %xmm1
divsd 0x58(%r12), %xmm1
movsd 0x3a196(%rip), %xmm0    # 0x51040
ucomisd %xmm0, %xmm1
ja 0x16eca
movsd 0x3f238(%rip), %xmm0    # 0x560f0
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
jbe 0x16eca
movsd 0x3f226(%rip), %xmm0    # 0x560f0
callq 0x2150
movslq 0x38(%r12), %rax
movsd %xmm0, (%rbx,%rax,8)
ucomisd %xmm0, %xmm0
jp 0x16f56
movslq 0x3c(%r12), %rax
testq %rax, %rax
js 0x16f3b
movq (%r12), %rcx
cmpl $0x0, 0x48(%rcx)
je 0x16f3b
cmpl %ebp, %eax
jge 0x16f56
movsd 0x68(%r12), %xmm0
movss 0x5192a(%rip), %xmm2    # 0x68830
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
jmp 0x16f13
subsd %xmm1, %xmm0
ucomisd %xmm1, %xmm0
ja 0x16f0f
xorps 0x3fa10(%rip), %xmm2    # 0x56930
cvtss2sd %xmm2, %xmm2
jmp 0x16f2a
addsd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
ja 0x16f26
movsd %xmm0, (%rbx,%rax,8)
ucomisd %xmm0, %xmm0
jp 0x16f56
incq %r15
cmpq %r13, %r15
jne 0x16e44
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rax
leaq 0x18(%rax), %rdx
movsbl 0x68(%rax), %ecx
movl 0x64(%rax), %r8d
movl 0x6c(%rax), %r9d
leaq 0x3fc59(%rip), %rdi     # 0x56bca
movl %r15d, %esi
xorl %eax, %eax
callq 0x20f0
movl 0x34(%r12), %esi
movl 0x38(%r12), %edx
movl 0x3c(%r12), %ecx
leaq 0x3fc77(%rip), %rdi     # 0x56c08
movl %ebp, %r8d
xorl %eax, %eax
callq 0x20f0
movslq 0x34(%r12), %rax
testq %rax, %rax
js 0x16fb8
movsd (%rbx,%rax,8), %xmm0
leaq 0x3fc85(%rip), %rdi     # 0x56c36
movb $0x1, %al
callq 0x20f0
movslq 0x38(%r12), %rax
testq %rax, %rax
js 0x16fd5
movsd (%rbx,%rax,8), %xmm0
leaq 0x3fc73(%rip), %rdi     # 0x56c41
movb $0x1, %al
callq 0x20f0
movslq 0x3c(%r12), %rax
testq %rax, %rax
js 0x16ff2
movsd (%rbx,%rax,8), %xmm0
leaq 0x3fc63(%rip), %rdi     # 0x56c4e
movb $0x1, %al
callq 0x20f0
movsd 0x58(%r12), %xmm0
movsd 0x60(%r12), %xmm1
movsd 0x68(%r12), %xmm2
leaq 0x3fc4f(%rip), %rdi     # 0x56c5d
movb $0x3, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270
nop