// File: /workspace/github_c_makefile_star2_O2/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, -0x40(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdi, -0x30(%rbp)
movl 0x10(%rbp), %eax
movq 0x18(%rbp), %rsi
movl 0x4(%rsi), %r9d
movq %rsp, %rbx
leaq 0xf(,%r9,8), %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, %rsp
movq %rsp, %r14
subq %rsi, %r14
movq %r14, %rsp
xorl %esi, %esi
testl %r9d, %r9d
movl $0x0, %edi
cmovgl %r9d, %edi
cmpq %rsi, %rdi
je 0x23874
andq $0x0, (%rbx,%rsi,8)
andq $0x0, (%r14,%rsi,8)
incq %rsi
jmp 0x23860
xorl %esi, %esi
testl %eax, %eax
cmovlel %esi, %eax
testl %r8d, %r8d
cmovlel %esi, %r8d
cmpl %r8d, %esi
je 0x2396f
xorl %edi, %edi
xorl %r9d, %r9d
cmpl %eax, %r9d
je 0x2395d
movslq %edi, %rdi
cmpl 0x18(%rcx), %r9d
jge 0x238a8
movss (%rdx), %xmm0
jmp 0x238b2
movss (%rdx), %xmm0
cmpl 0x1c(%rcx), %r9d
jle 0x23904
cvtss2sd %xmm0, %xmm0
leaq (%rbx,%rdi,8), %r10
leaq (%r14,%rdi,8), %r15
xorl %r11d, %r11d
cmpq $0x3, %r11
je 0x23952
movsd 0xa8(%rcx,%r11,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r10,%r11,8), %xmm1
movsd %xmm1, (%r10,%r11,8)
movsd 0x90(%rcx,%r11,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r15,%r11,8), %xmm1
movsd %xmm1, (%r15,%r11,8)
incq %r11
jmp 0x238c1
cvtss2sd %xmm0, %xmm0
leaq (%rbx,%rdi,8), %r10
leaq (%r14,%rdi,8), %r15
xorl %r11d, %r11d
cmpq $0x3, %r11
je 0x23952
movsd 0xd8(%rcx,%r11,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r10,%r11,8), %xmm1
movsd %xmm1, (%r10,%r11,8)
movsd 0xc0(%rcx,%r11,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r15,%r11,8), %xmm1
movsd %xmm1, (%r15,%r11,8)
incq %r11
jmp 0x23913
addq %r11, %rdi
incl %r9d
jmp 0x23890
addq $0x4, %rdx
addq $0x158, %rcx            # imm = 0x158
incl %esi
jmp 0x23882
movl %eax, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq %r15, %r12
je 0x239ee
movq -0x40(%rbp), %rax
movslq (%rax,%r12,4), %rax
imulq $0x70, %rax, %rax
addq -0x38(%rbp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x239a5
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x80(%rbp,%rcx,8)
incq %rcx
jmp 0x2398f
movslq %r13d, %r13
leaq (%rbx,%r13,8), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0xf8f7
leaq (%r14,%r13,8), %rcx
movq -0x30(%rbp), %rax
leaq (%rax,%r13,4), %rdx
xorl %eax, %eax
cmpq $0x3, %rax
je 0x239e6
movsd (%rcx,%rax,8), %xmm0
addsd -0x60(%rbp,%rax,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rdx,%rax,4)
incq %rax
jmp 0x239c7
incq %r12
addq %rax, %r13
jmp 0x23978
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq