// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Tors_step
int Tors_step(struct Tors *Diff, double **T_Lambda, float **Jacobian_ar,
	      float *mass_coord, int naxes, int N_Cart)
{
  double d_phi[naxes]; int fail=0;
  // Delta_phi=(T+Lambda I)^(-1)(M J^t Delta R)
  double Y[naxes]; int i, a;
  for(a=0; a<naxes; a++){
    Y[a]=0;
    for(i=0; i<N_Cart; i++)
      Y[a]+=mass_coord[i]*Jacobian_ar[a][i]*Diff->Cart[i];
    //Y[a]/=sqrt(T_Lambda[a][a]);
  }
  //(T+Lambda I)= LL^t Lower tridiagonal matrix L[i][j] with j<=i
  double **L=Allocate_mat2_d(naxes, naxes), X[naxes];
  if(choldc(L, T_Lambda, naxes)==0){
    //Solve L L^t d_phi = Y as: LX=Y (forward), L^t d_phi=X (backward)
    Forward_substitution(X, L, Y, naxes);
    Backward_substitution(d_phi, L, X, naxes);
    // The mean error is of order 1e-11
  }else{
    printf("Cholc decomposition failed\n");
    fail=1; for(a=0; a<naxes; a++)Diff->Tors[a]=0;
  }
  Empty_matrix_d(L, naxes);
  if(fail)return(1);
  /*double Yphi=0, phi2=0;
  for(a=0; a<naxes; a++){Yphi+=Y[a]*d_phi[a]; phi2+=d_phi[a]*d_phi[a];}
  float scale=Yphi/phi2;
  printf("Fast torsional step, scale= %.2g Yphi=%.2g phi2=%.2g\n",
	 scale, Yphi, phi2);
	 for(a=0; a<naxes; a++)Diff->Tors[a]=scale*d_phi[a];*/
  printf("Fast torsional step\n");
  for(a=0; a<naxes; a++)Diff->Tors[a]=d_phi[a];

  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r12d
movq %rsi, -0x40(%rbp)
movq %rdi, %rbx
movl %r8d, %eax
movq %rsp, %r14
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %rsp, %r13
movq %rax, -0x30(%rbp)
subq %rax, %r13
movq %r13, %rsp
xorl %eax, %eax
testl %r9d, %r9d
cmovlel %eax, %r9d
testl %r8d, %r8d
movl $0x0, %r15d
cmovgl %r8d, %r15d
cmpq %r15, %rax
je 0x32a0d
andq $0x0, (%r13,%rax,8)
xorpd %xmm0, %xmm0
xorl %esi, %esi
cmpq %rsi, %r9
je 0x32a08
movss (%rcx,%rsi,4), %xmm1
movq (%rdx,%rax,8), %rdi
mulss (%rdi,%rsi,4), %xmm1
movq 0x8(%rbx), %rdi
mulss (%rdi,%rsi,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rsi
jmp 0x329d8
incq %rax
jmp 0x329c7
movl %r12d, %edi
movl %r12d, %esi
callq 0x43878
movl %r12d, %edx
movq %rsp, %r12
subq -0x30(%rbp), %r12
movq %r12, %rsp
movq %rax, -0x30(%rbp)
movq %rax, %rdi
movq -0x40(%rbp), %rsi
movl %edx, -0x34(%rbp)
callq 0x438e8
movl %eax, -0x40(%rbp)
testl %eax, %eax
je 0x32a66
leaq 0x23244(%rip), %rdi     # 0x55c8a
callq 0x2090
xorl %eax, %eax
movl -0x34(%rbp), %esi
movq -0x30(%rbp), %rdi
cmpq %rax, %r15
je 0x32a95
movq 0x18(%rbx), %rcx
andl $0x0, (%rcx,%rax,4)
incq %rax
jmp 0x32a54
movq %r12, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
movl -0x34(%rbp), %r13d
movl %r13d, %ecx
callq 0x43a6b
movq %r14, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x43abd
movl %r13d, %esi
movq -0x30(%rbp), %rdi
callq 0x4372a
cmpl $0x0, -0x40(%rbp)
je 0x32ab2
pushq $0x1
popq %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x231ec(%rip), %rdi     # 0x55ca5
callq 0x2090
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x32aa3
cvtsd2ss (%r14,%rcx,8), %xmm0
movq 0x18(%rbx), %rdx
movss %xmm0, (%rdx,%rcx,4)
incq %rcx
jmp 0x32ac2