// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/nma.c
// Function: Convert_cart2torsion1
int Convert_cart2torsion1(float *Tors_dev,
			  float *Masswtd_Tors_dev,
			  float *Cart_dev,
			  struct Reference Ref,
			  struct Jacobian *J)
{
  // Formula: (LL^t)Delta_theta = JM Delta_r  with:
  // L=T_sqrt (lower diagonal matrix if obtained from Cholevsky decomposition)
  // T=JMJ^t = LL^t
  // J is the jacobian matrix dr_int_i/d_theta_a
  // M_i is the diagonal mass matrix.
  // ==> L^t Delta_theta = L^{-1} J M Delta_r = Jtilde M Delta_r
  // To solve the equation:
  // Compute x=Jtilde MDelta_r =Masswtd_Tors
  // solve x=L^t Delta_theta (by backward substitution if T_sqrt lower diagonal)
  // Return the torsional fraction,
  // sum_i m_i (J d_theta)^2/sum_i m_i Dr_i^2

  if(J->Jtilde_ar==NULL)Compute_Jtilde(J);

  double sum=0; int i, j, a;

  // Compute Masswtd_Tors_dev = Jtilde M Delta_r
  for(a=0; a<J->N_axes; a++){
    float *Jt=J->Jtilde_ar[a]; sum=0;
    float *r=Cart_dev, *m=Ref.mass_coord;
    for(j=0; j<J->N_Cart; j++)sum+=m[j]*r[j]*Jt[j];
    Masswtd_Tors_dev[a]=sum;
  }
  if(J->T_sqrt_inv){
    // T_sqrt is not lower diagonal!
    for(a=0; a<J->N_axes; a++){
      sum=0;
      for(i=0; i<J->N_axes; i++)sum+=J->T_sqrt_inv[i][a]*Masswtd_Tors_dev[i];
      Tors_dev[a]=sum;
    }
  }else{
    // Exploit that T_sqrt is lower diagonal
    // Backward_substitution
    // theta_i =(x_i - sum_j>i L_ji x_j)/L_ii
    for(i=J->N_axes-1; i>=0; i--){
      Tors_dev[i]=Masswtd_Tors_dev[i];
      for(j=i+1; j<J->N_axes; j++)Tors_dev[i]-=Tors_dev[j]*J->T_sqrt[j][i];
      Tors_dev[i]/=J->T_sqrt[i][i];
    }
  }
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x35d44
movq -0x20(%rbp), %rdi
callq 0x30980
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35e09
movq -0x58(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x35de5
movq -0x50(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x48(%rbp), %rax
movslq -0x30(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x40(%rbp), %rax
movslq -0x30(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x35d99
movsd -0x28(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x35d53
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x35eac
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35ea7
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35e83
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x35e39
movsd -0x28(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x35e1f
jmp 0x35fa5
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x35fa3
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35f5e
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x35ee5
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x35eb8
jmp 0x35fa5
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)