// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/kinetic_tnm.c
// Function: Kinetic_energy_Jac
int Kinetic_energy_Jac(struct Jacobian J, struct Reference Ref, int N_axes)
{
  // Compute kinetic energy tensor T=T_sqrt T_sqrt^T (only internal dof)
  // Lower tridiagonal matrix T[i][j] with j<=i
  int k, l, j, diff=0;
  for(l=0; l<N_axes; l++){
    float *Jl=J.Jacobian_ar[l];
    for(k=0; k<=l; k++){
      float *Jk=J.Jacobian_ar[k]; double sum=0;
      for(j=0; j<Ref.N_Cart; j++)sum+=Jk[j]*Jl[j]*Ref.mass_coord[j];
      if(fabs(sum-J.T[l][k])>0.0001*fabs(J.T[l][l])){
	printf("%d %d %.6f %.6f\n", l, k, sum, J.T[l][k]);
	diff++;
      }
      J.T[l][k]=sum;
      if(l!=k)J.T[k][l]=J.T[l][k];
    }
  }
  if(diff){
    printf("ERROR, %d components of the kinetic energy are different\n",
	   diff); exit(8);
  }else{
    printf("All components of the kinetic energy are equal\n"); exit(8);
  }
  if(DEBUG){
    int ini=N_axes-20;
    printf("###  Kinetic energy matrix (calc):\n");
    for(k=ini; k<ini+20; k++){
      for(l=ini; l<=k; l++)printf(" %.4g", J.T[k][l]);
      printf("\n");
    }
  }
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0x58(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl %edi, -0x4(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x30789
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x30779
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x40(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x3067f
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
movq -0x20(%rbp), %rcx
movslq -0x10(%rbp), %rdx
mulss (%rcx,%rdx,4), %xmm0
movq 0x18(%rax), %rax
movslq -0x10(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x3062f
movq -0x38(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movq 0x20(%rax), %rcx
movslq -0xc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x8(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm0
movaps 0x4bdec(%rip), %xmm1    # 0x7c490
pand %xmm1, %xmm0
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movaps 0x4bdcc(%rip), %xmm1    # 0x7c490
pand %xmm1, %xmm2
movsd 0x4a548(%rip), %xmm1    # 0x7ac18
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x30715
movq -0x38(%rbp), %rax
movl -0xc(%rbp), %esi
movl -0x8(%rbp), %edx
movsd -0x30(%rbp), %xmm0
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
leaq 0x4d17e(%rip), %rdi     # 0x7d883
movb $0x2, %al
callq 0x10d0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
cmpl -0x8(%rbp), %eax
je 0x30769
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movslq -0xc(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x8(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x20(%rax), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3076b
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x30600
jmp 0x3077b
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x305d9
cmpl $0x0, -0x14(%rbp)
je 0x307aa
movl -0x14(%rbp), %esi
leaq 0x4d0fb(%rip), %rdi     # 0x7d894
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
leaq 0x4d11d(%rip), %rdi     # 0x7d8ce
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
nopw %cs:(%rax,%rax)