// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2e7a9
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x28(%rcx), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e427
movq -0x90(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x30(%rax,%rcx,8)
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd 0x30(%rax,%rcx,8), %xmm0
movslq -0x24(%rbp), %rax
movsd %xmm0, -0x60(%rbp,%rax,8)
movq -0x98(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x90(%rbp), %rax
movslq -0x24(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movslq -0x24(%rbp), %rax
movsd %xmm0, -0x40(%rbp,%rax,8)
movslq -0x24(%rbp), %rax
movsd -0x40(%rbp,%rax,8), %xmm0
movslq -0x24(%rbp), %rax
movsd -0x40(%rbp,%rax,8), %xmm2
movsd -0xa0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e37d
movsd -0xa0(%rbp), %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x47c09(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e486
movslq -0x24(%rbp), %rax
movsd -0x40(%rbp,%rax,8), %xmm0
mulsd -0xa0(%rbp), %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x78(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e452
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x6c, %eax
jne 0x2e4e8
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e4e3
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd 0x78(%rax,%rcx,8), %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x60(%rax,%rcx,8)
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e49c
jmp 0x2e799
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jne 0x2e711
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0x2e52c
movl -0x20(%rbp), %esi
leaq 0x4f470(%rip), %rdi     # 0x7d98b
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x28(%rcx), %rcx
movq 0x28(%rcx), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e59a
movq -0x90(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa8(%rbp), %rax
movslq -0x24(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movslq -0x24(%rbp), %rax
movsd %xmm0, -0xc0(%rbp,%rax,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e55c
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x14aa0
xorps %xmm0, %xmm0
movsd %xmm0, -0xe8(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e606
movslq -0x24(%rbp), %rax
movsd -0xe0(%rbp,%rax,8), %xmm0
movslq -0x24(%rbp), %rax
movsd -0xe0(%rbp,%rax,8), %xmm2
movsd -0xe8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e5c3
xorps %xmm0, %xmm0
ucomisd -0xe8(%rbp), %xmm0
jb 0x2e636
movl -0x20(%rbp), %esi
movsd -0xe8(%rbp), %xmm0
leaq 0x4f37e(%rip), %rdi     # 0x7d9a3
movb $0x1, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movsd -0xe8(%rbp), %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x479fa(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e690
movsd -0xe8(%rbp), %xmm0
movslq -0x24(%rbp), %rax
mulsd -0xe0(%rbp,%rax,8), %xmm0
movsd %xmm0, -0xe0(%rbp,%rax,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e661
leaq -0x80(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x14aa0
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e70c
movslq -0x24(%rbp), %rax
movsd -0x80(%rbp,%rax,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x60(%rax,%rcx,8)
movslq -0x24(%rbp), %rax
movsd -0xe0(%rbp,%rax,8), %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x48(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e6ab
jmp 0x2e797
leaq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x78, %rsi
leaq -0x60(%rbp), %rdx
callq 0x14aa0
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x2e795
movslq -0x24(%rbp), %rax
movsd -0x80(%rbp,%rax,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x60(%rax,%rcx,8)
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd 0x78(%rax,%rcx,8), %xmm0
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, 0x48(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e730
jmp 0x2e797
jmp 0x2e799
jmp 0x2e79b
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2e300
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)