// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/kinetic_tnm.c
// Function: Kinetic_energy
int Kinetic_energy(double ***T_mat, float *mass_coord,
		   struct axe *axe, int ini_axe, int N_axes,
		   atom *atoms, int *atom_num, int N_ref)
{
  // Compute kinetic energy tensor T=T_sqrt T_sqrt^T (only internal dof)
  // Lower tridiagonal matrix T_sqrt[i][j] with j<=i
  int k, l, i, j, ini_ref, N_Cart=3*N_ref;
  float **J_ar=Allocate_mat2_f(N_axes, N_Cart), *J, dr[3];
  *T_mat=Allocate_mat2_d(N_axes, N_axes);

  // Local Jacobian (only atoms upstream of k)
  for(l=0; l<N_axes; l++){
    struct axe *l_axe=axe+ini_axe+l;
    float offset[3], rot[3];
    for(j=0; j<3; j++){
      offset[j]=l_axe->offset[j]; rot[j]=l_axe->rot[j];
    }
    ini_ref=l_axe->first_kin;
    J=J_ar[l]+3*ini_ref;
    for(i=ini_ref; i<N_ref; i++){
      for(j=0; j<3; j++)dr[j]=atoms[atom_num[i]].r[j]-offset[j];
      Vector_product(J, rot, dr); J+=3;
    }
  }

  for(l=0; l<N_axes; l++){
    float *Jl=J_ar[l];
    //~ struct axe *l_axe=axe+ini_axe+l;
    int end_cart=3*(axe[ini_axe+l].first_kin);

    for(k=0; k<=l; k++){
      double sum=0; float *Jk=J_ar[k];
      int ini_cart=3*(axe[ini_axe+k].first_kin);
      for(j=ini_cart; j<end_cart; j++)sum+=Jk[j]*Jl[j]*mass_coord[j];
      (*T_mat)[k][l]=sum;
    }
  }
  for(l=0; l<N_axes; l++){
    for(k=l+1; k<N_axes; k++)(*T_mat)[k][l]=(*T_mat)[l][k];
  }
  if(DEBUG){
    for(l=0; l<10; l++){
      for(k=0; k<=l; k++){
	printf("%d %d %d %d\n", l, k,
	       axe[ini_axe+l].first_kin, axe[ini_axe+k].first_kin);
      }
    }
    printf("\n");
    for(l=0; l<20; l++){
      for(k=0; k<=l; k++)printf("%.2g ", (*T_mat)[l][k]);
      printf("\n");
    }
  }

  Empty_matrix_f(J_ar, N_axes);
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
imull $0x3, 0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x20(%rbp), %edi
movl -0x40(%rbp), %esi
callq 0x69360
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x694a0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x30078
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
movslq -0x30(%rbp), %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x2ffab
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd 0x30(%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq -0x38(%rbp), %rax
movss %xmm0, -0x74(%rbp,%rax,4)
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd 0x48(%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq -0x38(%rbp), %rax
movss %xmm0, -0x80(%rbp,%rax,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2ff62
movq -0x68(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
imull $0x3, -0x3c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x30068
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x3003d
movq -0x28(%rbp), %rax
movq 0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movslq -0x38(%rbp), %rax
movss -0x74(%rbp,%rax,4), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movslq -0x38(%rbp), %rax
movss %xmm0, -0x5c(%rbp,%rax,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2ffec
movq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x149c0
movq -0x50(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x50(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2ffd9
jmp 0x3006a
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2ff2b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x301af
movq -0x48(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
imull $0x3, 0x18(%rax), %eax
movl %eax, -0x8c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x3019f
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x48(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
imull $0x3, 0x18(%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jge 0x30171
movq -0xa0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x88(%rbp), %rax
movslq -0x38(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3011a
movsd -0x98(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x300c6
jmp 0x301a1
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3007f
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x30217
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3020a
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x301c7
jmp 0x3020c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x301b6
leaq 0x6c18e(%rip), %rax     # 0x9c3ac
cmpl $0x0, (%rax)
je 0x3031a
movl $0x0, -0x30(%rbp)
cmpl $0xa, -0x30(%rbp)
jge 0x302a4
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x30297
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x158, %rcx, %rcx      # imm = 0x158
addq %rcx, %rax
movl 0x18(%rax), %ecx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %edi
addl -0x2c(%rbp), %edi
movslq %edi, %rdi
imulq $0x158, %rdi, %rdi      # imm = 0x158
addq %rdi, %rax
movl 0x18(%rax), %r8d
leaq 0x4d5c7(%rip), %rdi     # 0x7d84c
movb $0x0, %al
callq 0x10d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3023b
jmp 0x30299
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3022e
leaq 0x4ddcd(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x30(%rbp)
cmpl $0x14, -0x30(%rbp)
jge 0x30318
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x302ff
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x4d56c(%rip), %rdi     # 0x7d859
movb $0x1, %al
callq 0x10d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x302c6
leaq 0x4dd72(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x302b9
jmp 0x3031a
movq -0x48(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x69240
xorl %eax, %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)