// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x38(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x2c(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x4e637
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x4e627
movq -0x78(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x54(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
movq -0x20(%rbp), %rcx
movslq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x54(%rbp), %rdx
mulss (%rcx,%rdx,4), %xmm0
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x54(%rbp), %rdx
mulss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x58(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4e5cb
jmp 0x4e629
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4e5a8
movl -0x2c(%rbp), %esi
movl %esi, %edi
callq 0x694a0
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x69540
cmpl $0x0, %eax
jne 0x4e6ad
movq -0x88(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rsi
movl -0x2c(%rbp), %ecx
callq 0x697c0
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rdx
movq -0x60(%rbp), %rsi
movl -0x2c(%rbp), %ecx
callq 0x698c0
jmp 0x4e6f2
leaq 0x32a5e(%rip), %rdi     # 0x81112
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x44(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x4e6f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x58(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4e6c9
jmp 0x4e6f2
movq -0x60(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x692a0
cmpl $0x0, -0x44(%rbp)
je 0x4e714
movl $0x1, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x4e76c
leaq 0x32a13(%rip), %rdi     # 0x8112e
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x4e75e
movq -0x80(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x58(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4e729
movl $0x0, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x38(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)