// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %rdx, 0x8(%rsp)
xorl %ebx, %ebx
testl %esi, %esi
cmovlel %ebx, %esi
movq %rsi, 0x38(%rsp)
leaq 0x30(%rdi), %rbp
leaq 0x78(%rdi), %r13
movq %rdi, 0x30(%rsp)
leaq 0x60(%rdi), %r15
xorpd %xmm3, %xmm3
cmpq 0x38(%rsp), %rbx
je 0x1f2a1
imulq $0x158, %rbx, %rax      # imm = 0x158
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %r14
movq 0x8(%rcx,%rax), %rax
movq 0x28(%rax), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x70, %rcx, %r12
movq 0x8(%rsp), %rcx
addq %rcx, %r12
movslq 0x20(%rax), %rax
imulq $0x70, %rax, %rax
addq %rcx, %rax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
cmpq $0x18, %rcx
je 0x1f0b8
movsd (%r12,%rcx), %xmm1
movsd %xmm1, (%rbp,%rcx)
movsd %xmm1, 0x60(%rsp,%rcx)
movsd (%rax,%rcx), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x80(%rsp,%rcx)
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
addq $0x8, %rcx
jmp 0x1f080
ucomisd %xmm3, %xmm0
jb 0x1f0c4
sqrtsd %xmm0, %xmm0
jmp 0x1f0c9
callq 0x2290
movsd 0x2bf77(%rip), %xmm1    # 0x4b048
divsd %xmm0, %xmm1
leaq 0x78(%r14), %rsi
xorl %eax, %eax
cmpq $0x3, %rax
je 0x1f0fa
movsd 0x80(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
jmp 0x1f0db
movzbl (%r14), %eax
cmpl $0x61, %eax
je 0x1f132
cmpl $0x6c, %eax
jne 0x1f175
pushq $-0x18
popq %rax
xorpd %xmm3, %xmm3
testq %rax, %rax
je 0x1f28b
movsd 0x18(%r13,%rax), %xmm0
movsd %xmm0, (%r13,%rax)
andq $0x0, -0x18(%r13,%rax)
addq $0x8, %rax
jmp 0x1f10f
movq 0x8(%r14), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x1f2c5
movslq 0x20(%rax), %rax
imulq $0x70, %rax, %rax
addq 0x8(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x1f1c0
movsd (%r12,%rcx,8), %xmm0
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xa0(%rsp,%rcx,8)
incq %rcx
jmp 0x1f156
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xf8f7
xorl %eax, %eax
xorpd %xmm3, %xmm3
movapd 0x2bf2e(%rip), %xmm1    # 0x4b0c0
cmpq $0x3, %rax
je 0x1f28b
movsd 0x40(%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
jmp 0x1f192
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0xf8f7
xorpd %xmm0, %xmm0
xorl %eax, %eax
xorpd %xmm2, %xmm2
cmpq $0x3, %rax
je 0x1f1fd
movsd 0x10(%rsp,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
jmp 0x1f1e4
ucomisd %xmm0, %xmm2
jae 0x1f2b3
ucomisd %xmm2, %xmm0
jb 0x1f213
sqrtsd %xmm0, %xmm0
jmp 0x1f218
callq 0x2290
movsd 0x2be28(%rip), %xmm1    # 0x4b048
divsd %xmm0, %xmm1
xorl %eax, %eax
cmpq $0x3, %rax
je 0x1f241
movsd 0x10(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp,%rax,8)
incq %rax
jmp 0x1f226
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0xf8f7
xorl %eax, %eax
xorpd %xmm3, %xmm3
movapd 0x2be5d(%rip), %xmm1    # 0x4b0c0
cmpq $0x3, %rax
je 0x1f28b
movsd 0x40(%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
jmp 0x1f263
incq %rbx
movl $0x158, %eax            # imm = 0x158
addq %rax, %rbp
addq %rax, %r13
addq %rax, %r15
jmp 0x1f03b
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x333a7(%rip), %rdi     # 0x52661
movl %ebx, %esi
movb $0x1, %al
callq 0x20f0
jmp 0x1f2d5
leaq 0x3337d(%rip), %rdi     # 0x52649
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270