// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/kinetic_tnm.c
// Function: Kinetic_sqrt
int Kinetic_sqrt(struct Jacobian *J, int *N_kin,
		 int N, int CONTROL, float E_MIN)
{
  // 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;
  (*N_kin)=N;

  if(CONTROL==0){
    if(START)printf("Kinetic_sqrt with Cholevsky decomposition\n");
    if(choldc(J->T_sqrt, J->T, N)==0){
      //J->T_sqrt_inv=Cholevsky_inversion_d2f(J->T_sqrt, N);
      for(k=0; k<N; k++){
	double *Lk=J->T_sqrt[k]+k+1;
	for(l=k+1; l<N; l++){*Lk=0; Lk++;}
      }
      return(0);
    }
  }

  // New decomposition diagonalizing kinetic energy
  printf("Square root of kinetic energy through diagonalization\n");
  {
    float **eigen_vector=Allocate_mat2_f(N, N);
    float eigen_value[N], t, t_inv;
    int num=0, ik;
    if(J->T_sqrt_inv)Empty_matrix_f(J->T_sqrt_inv, N);
    J->T_sqrt_inv=Allocate_mat2_f(N, N);
    d_Diagonalize(N, J->T, eigen_value, eigen_vector, 1);
    for(k=0; k<N; k++){
      if(eigen_value[k]<E_MIN){t=0; num++; continue;}
      else{t=sqrt(eigen_value[k]); t_inv=1./t; ik=k-num;}
      for(l=0; l<N; l++){
	J->T_sqrt[l][ik]=t*eigen_vector[k][l];
	if(t)J->T_sqrt_inv[ik][l]=eigen_vector[k][l]*t_inv;
      }
    }
    if(num)printf("WARNING, kinetic energy has %d null modes\n", num);
    (*N_kin)-=num;
    Empty_matrix_f(eigen_vector, N);
  }

  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x2fb92
cmpl $0x0, 0x5c38b(%rip)     # 0x8be70
je 0x2faf5
leaq 0x4de10(%rip), %rdi     # 0x7d8fe
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x69540
cmpl $0x0, %eax
jne 0x2fb90
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2fb84
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2fb77
movq -0x38(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2fb4d
jmp 0x2fb79
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2fb19
movl $0x0, -0x4(%rbp)
jmp 0x2fd9d
jmp 0x2fb92
leaq 0x4dd90(%rip), %rdi     # 0x7d929
xorl %eax, %eax
callq 0x10d0
movl -0x1c(%rbp), %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x48(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x2fbf7
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0x69240
movl -0x1c(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x69360
movq -0x68(%rbp), %rdx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x1c(%rbp), %edi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rcx
movl $0x1, %r8d
callq 0x6ac30
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2fd5f
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x24(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2fc6b
xorps %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2fd51
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x463ad(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
movl -0x28(%rbp), %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2fd4f
movss -0x54(%rbp), %xmm0
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x60(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movss -0x54(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2fd0c
jp 0x2fd0c
jmp 0x2fd3f
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
mulss -0x58(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x2fd41
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2fcb8
jmp 0x2fd51
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2fc32
cmpl $0x0, -0x5c(%rbp)
je 0x2fd76
movl -0x5c(%rbp), %esi
leaq 0x4dbf1(%rip), %rdi     # 0x7d960
movb $0x0, %al
callq 0x10d0
movl -0x5c(%rbp), %edx
movq -0x18(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x69240
movq -0x48(%rbp), %rax
movq %rax, %rsp
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)