// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/kinetic_tnm.c
// Function: Set_rot_shift
void  Set_rot_shift(struct axe *axes, int N_axes, atom *atoms, int N_atoms)
{
  int k, j;
  double v[3], offset[3], shift[3];
  // Axes vector and shift
  for(k=0; k<N_axes; k++){
    struct axe *axe=axes+k;
    double *r1=(atoms+axe->bond->previous->i_atom)->r;
    double *r2=(atoms+axe->bond->i_atom)->r;
    double v2=0;
    for(j=0; j<3; j++){
      axe->offset[j]=r1[j];               // Get offset as r1
      offset[j]=axe->offset[j];
      v[j]=r2[j]-r1[j]; v2+=v[j]*v[j];    // Get axe as (r1-r2)/|r1-r2|
    }
    v2=1./sqrt(v2);
    for(j=0; j<3; j++)axe->vers[j]=v[j]*v2;

    if(axe->type=='l'){ // bond length
      for(j=0; j<3; j++){
	// Bonds used as dof have a standard length LBOND=1
	axe->shift[j]=axe->vers[j];
	axe->rot[j]=0;
      }
    }else if(axe->type=='a'){ // bond angle
      if(axe->bond->previous->previous==NULL){
	printf("ERROR in bond angle %d\n", k); exit(8);
      }
      // Compute normal vector
      double *r0=(atoms+axe->bond->previous->previous->i_atom)->r;
      double v0[3], normal[3];
      for(j=0; j<3; j++)v0[j]=r1[j]-r0[j];
      Vector_product_d(normal, v, v0);
      // Normalize:
      double v2=0; for(j=0; j<3; j++)v2+=normal[j]*normal[j];
      if(v2<=0){
	printf("ERROR for bond angle %d, zero norm (%.6f)\n",k, v2);
	exit(8);
      }
      v2=1./sqrt(v2); for(j=0; j<3; j++)normal[j]*=v2;
      Vector_product_d(shift, normal, offset);
      for(j=0; j<3; j++){
	axe->shift[j]=-shift[j];
	axe->rot[j]=normal[j];
      }
    }else{   // torsion
      Vector_product_d(shift, axe->vers, offset);
      for(j=0; j<3; j++){
	axe->shift[j]=-shift[j]; axe->rot[j]=axe->vers[j];
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, 0x8(%rsp)
movq %rdi, (%rsp)
testl %esi, %esi
jle 0x21817
movl %esi, %eax
movq %rax, 0x28(%rsp)
movq (%rsp), %rax
leaq 0x30(%rax), %rbp
leaq 0x78(%rax), %r13
leaq 0x60(%rax), %r15
xorl %ebx, %ebx
xorpd %xmm2, %xmm2
imulq $0x158, %rbx, %rax      # imm = 0x158
movq (%rsp), %rcx
leaq (%rcx,%rax), %r12
movq 0x8(%rcx,%rax), %rax
movq 0x28(%rax), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x70, %rcx, %r14
movq 0x8(%rsp), %rcx
addq %rcx, %r14
movslq 0x20(%rax), %rax
imulq $0x70, %rax, %rax
addq %rcx, %rax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movsd (%r14,%rcx), %xmm1
movsd %xmm1, (%rbp,%rcx)
movsd %xmm1, 0x50(%rsp,%rcx)
movsd (%rax,%rcx), %xmm1
subsd (%r14,%rcx), %xmm1
movsd %xmm1, 0x70(%rsp,%rcx)
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
addq $0x8, %rcx
cmpq $0x18, %rcx
jne 0x215fc
ucomisd %xmm2, %xmm0
jb 0x2163d
sqrtsd %xmm0, %xmm0
jmp 0x21642
callq 0x2290
movsd 0x2f9f6(%rip), %xmm1    # 0x51040
divsd %xmm0, %xmm1
xorl %eax, %eax
movsd 0x70(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x21650
movzbl (%r12), %eax
cmpl $0x61, %eax
je 0x216a9
cmpl $0x6c, %eax
jne 0x21739
movq $-0x3, %rax
xorpd %xmm2, %xmm2
movsd 0x18(%r13,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
movq $0x0, -0x18(%r13,%rax,8)
incq %rax
jne 0x21688
jmp 0x217fb
movq 0x8(%r12), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x2183b
movslq 0x20(%rax), %rax
imulq $0x70, %rax, %rax
addq 0x8(%rsp), %rax
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x90(%rsp,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x216ce
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x1086b
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd 0x10(%rsp,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq $0x3, %rax
jne 0x21708
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jae 0x21829
ucomisd %xmm1, %xmm0
jb 0x21787
sqrtsd %xmm0, %xmm0
jmp 0x2178c
addq $0x78, %r12
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
leaq 0x50(%rsp), %rdx
callq 0x1086b
xorl %eax, %eax
xorpd %xmm2, %xmm2
movapd 0x2f933(%rip), %xmm1    # 0x51090
movsd 0x30(%rsp,%rax,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, -0x18(%r13,%rax,8)
movsd (%r13,%rax,8), %xmm0
movsd %xmm0, -0x30(%r13,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x2175d
jmp 0x217fb
callq 0x2290
movsd 0x2f8ac(%rip), %xmm1    # 0x51040
divsd %xmm0, %xmm1
xorl %eax, %eax
movsd 0x10(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x2179a
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1086b
xorl %eax, %eax
movapd 0x2f8bf(%rip), %xmm1    # 0x51090
movsd 0x30(%rsp,%rax,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%r15,%rax,8)
movsd 0x10(%rsp,%rax,8), %xmm0
movsd %xmm0, -0x18(%r15,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x217d1
xorpd %xmm2, %xmm2
incq %rbx
movl $0x158, %eax            # imm = 0x158
addq %rax, %rbp
addq %rax, %r13
addq %rax, %r15
cmpq 0x28(%rsp), %rbx
jne 0x215c3
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36efb(%rip), %rdi     # 0x5872b
movl %ebx, %esi
movb $0x1, %al
callq 0x20f0
jmp 0x2184b
leaq 0x36ed1(%rip), %rdi     # 0x58713
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270