// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/nma.c
// Function: Convert_torsion2cart_old
void Convert_torsion2cart_old(float *Cart_mode, atom *atoms, float *u_a,
			  struct axe *axes, int N_axes, int *atom_ref,
			  int N_ref, struct Jacobian *J)
{
  // Computing derivative:
  // dr_ia ~ (sum_k u_a,k*rot_ik) X r_i + (sum_k u_a,k*shift_ik)

  int  i, j, k, jj;

  double dr_daxe_rot[J->N_Cart], dr_daxe_shift[J->N_Cart];
  for(j=0; j<J->N_Cart; j++){
    dr_daxe_rot[j]=0; dr_daxe_shift[j]=0;
  }
  float *u_ak=u_a;
  struct axe *axe=axes;
  for(k=0; k<N_axes; k++){
    jj=0;
    for(i=0; i<N_ref; i++){
      if((i>=axe->first_kin)&&(i<=axe->last_kin)){
	for(j=0; j<3; j++){
	  dr_daxe_rot[jj]  +=(*u_ak)*axe->local_rot[j];
	  dr_daxe_shift[jj]+=(*u_ak)*axe->local_shift[j];
	  jj++;
	}
      }else{
	for(j=0; j<3; j++){
	  dr_daxe_rot[jj]  +=(*u_ak)*axe->global_rot[j];
	  dr_daxe_shift[jj]+=(*u_ak)*axe->global_shift[j];
	  jj++;
	}
      }
    }
    u_ak++; axe++;
  }
  
  double r[3], dd[3]; jj=0;
  for(i=0; i<N_ref; i++){
    atom *atom=atoms+atom_ref[i];
    for(j=0; j<3; j++)r[j]= atom->r[j];
    Vector_product_d(dd, dr_daxe_rot+jj, r);
    for(j=0; j<3; j++){
      Cart_mode[jj]=dr_daxe_shift[jj]+dd[j]; jj++;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, -0x48(%rbp)
movl %r8d, %r14d
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq 0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq %rsp, %r12
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
testl %ecx, %ecx
jle 0x25f10
shlq $0x3, %rcx
movq %r12, %rdi
xorl %esi, %esi
movq %rcx, %rdx
movq %rcx, -0x30(%rbp)
callq 0x2110
movq %r13, %rdi
xorl %esi, %esi
movq -0x30(%rbp), %rdx
callq 0x2110
movl 0x10(%rbp), %eax
testl %r14d, %r14d
jle 0x26010
xorl %ecx, %ecx
testl %eax, %eax
jle 0x25ffa
movl 0x18(%r15), %edx
xorl %esi, %esi
xorl %edi, %edi
movslq %edi, %rdi
cmpl %edx, %esi
jge 0x25f3b
movss (%rbx), %xmm0
jmp 0x25f45
movss (%rbx), %xmm0
cmpl 0x1c(%r15), %esi
jle 0x25f9a
cvtss2sd %xmm0, %xmm0
leaq (%r12,%rdi,8), %r8
leaq (,%rdi,8), %r10
addq %r13, %r10
xorl %r9d, %r9d
movsd 0xa8(%r15,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r8,%r9,8), %xmm1
movsd %xmm1, (%r8,%r9,8)
movsd 0x90(%r15,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r10,%r9,8), %xmm1
movsd %xmm1, (%r10,%r9,8)
incq %r9
cmpq $0x3, %r9
jne 0x25f5b
jmp 0x25fed
cvtss2sd %xmm0, %xmm0
leaq (%r12,%rdi,8), %r8
leaq (,%rdi,8), %r10
addq %r13, %r10
xorl %r9d, %r9d
movsd 0xd8(%r15,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r8,%r9,8), %xmm1
movsd %xmm1, (%r8,%r9,8)
movsd 0xc0(%r15,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r10,%r9,8), %xmm1
movsd %xmm1, (%r10,%r9,8)
incq %r9
cmpq $0x3, %r9
jne 0x25fb0
addq %r9, %rdi
incl %esi
cmpl %eax, %esi
jne 0x25f2e
addq $0x4, %rbx
addq $0x158, %r15            # imm = 0x158
incl %ecx
cmpl %r14d, %ecx
jne 0x25f1e
testl %eax, %eax
jle 0x2608e
movl %eax, %ebx
xorl %r15d, %r15d
xorl %r14d, %r14d
movq -0x48(%rbp), %rax
movslq (%rax,%r15,4), %rax
imulq $0x70, %rax, %rax
movq -0x40(%rbp), %rdx
movq 0x10(%rdx,%rax), %rcx
movq %rcx, -0x50(%rbp)
movups (%rdx,%rax), %xmm0
movaps %xmm0, -0x60(%rbp)
movslq %r14d, %r14
leaq (%r12,%r14,8), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x103bb
leaq (,%r14,8), %rcx
addq %r13, %rcx
movq -0x38(%rbp), %rax
leaq (%rax,%r14,4), %rdx
xorl %eax, %eax
movsd (%rcx,%rax,8), %xmm0
addsd -0x80(%rbp,%rax,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rdx,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x26066
incq %r15
addq %rax, %r14
cmpq %rbx, %r15
jne 0x2601c
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq