// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/anharmonic_tnm.c
// Function: Compute_corr_inv
double **Compute_corr_inv(int npara, int nsam)
{
  //C_ab= sum_i=1^4 i^a*i^b = sum_i=1^4 i^(a+b)
  double **Corr=Allocate_mat2_d(npara, npara); int a,b,k;
  for(a=0; a<npara; a++){
    for(b=0; b<=a; b++){
      double C=0;
      for(k=1; k<nsam; k++)C+=pow(k,a+b);
      Corr[a][b]=C; Corr[b][a]=C;
    }
  }
  Corr[0][0]=nsam+1;
  double **Corr_inv=Allocate_mat2_d(npara, npara);
  if(choldc(Corr, Corr, npara)==0){ //
    printf("Inverting correlation through Cholevsky decomposition\n");
    double **L_inv=Cholevsky_inversion(Corr, npara);
    for(k=0; k<npara; k++){
      double *v=L_inv[k];
      for(a=0; a<npara; a++)for(b=0; b<=a; b++)Corr_inv[a][b]+=v[a]*v[b];
    }
    Empty_matrix_d(L_inv, npara);
  }else{
    printf("Inverting correlation through diagonalization\n");
    float **eigen_vector=Allocate_mat2_f(npara, npara), eigen_value[npara];
    d_Diagonalize(npara, Corr, eigen_value, eigen_vector, 1);
    int num=0;
    for(k=0; k<npara; k++){
      if(eigen_value[k]<=0){num++; continue;}
      double t=1./eigen_value[k];
      float *v=eigen_vector[k];
      for(a=0; a<npara; a++){
	for(b=0; b<=a; b++)Corr_inv[a][b]+=t*v[a]*v[b];
      }
    }
    if(num)printf("WARNING, correlation has %d null modes\n", num);
    Empty_matrix_f(eigen_vector, npara);
  }
  for(a=0; a<npara; a++)for(b=0; b<a; b++)Corr_inv[b][a]=Corr_inv[a][b];
  Empty_matrix_d(Corr, npara);
  return(Corr_inv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %r15d
movl %edi, %ebx
movl %edi, %esi
callq 0x43878
xorl %r12d, %r12d
testl %ebx, %ebx
movl $0x0, %ecx
movl %ebx, -0x2c(%rbp)
cmovgl %ebx, %ecx
movq %rcx, -0x38(%rbp)
movq %rax, %r14
pushq $0x1
popq %rax
movq %rax, -0x48(%rbp)
cmpq -0x38(%rbp), %r12
je 0x199cf
xorl %ebx, %ebx
cmpq -0x48(%rbp), %rbx
je 0x199c3
movq %r14, %r13
leal (%rbx,%r12), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
movsd 0x316df(%rip), %xmm0    # 0x4b048
pushq $0x1
popq %r14
cmpl %r15d, %r14d
jge 0x199a6
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x58(%rbp)
movsd -0x50(%rbp), %xmm1
callq 0x20a0
movsd -0x58(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
addsd 0x316a7(%rip), %xmm0    # 0x4b048
incl %r14d
jmp 0x1996d
movq %r13, %r14
movq (%r13,%r12,8), %rax
movsd %xmm1, (%rax,%rbx,8)
movq (%r13,%rbx,8), %rax
movsd %xmm1, (%rax,%r12,8)
incq %rbx
jmp 0x19947
incq %r12
incq -0x48(%rbp)
jmp 0x1993b
incl %r15d
cvtsi2sd %r15d, %xmm0
movq (%r14), %rax
movsd %xmm0, (%rax)
movl -0x2c(%rbp), %ebx
movl %ebx, %edi
movl %ebx, %esi
callq 0x43878
movq %rax, %r15
movq %r14, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x438e8
movl %ebx, %r12d
testl %eax, %eax
je 0x19aed
leaq 0x38721(%rip), %rdi     # 0x5212d
callq 0x2090
movl %ebx, %edi
movl %ebx, %esi
callq 0x4379e
movq %rsp, -0x40(%rbp)
movl %ebx, %edi
movq %rax, %rbx
movq %rsp, %r13
leaq 0xf(,%r12,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
pushq $0x1
popq %r8
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x444de
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd 0x315f0(%rip), %xmm1    # 0x4b048
pushq $0x1
popq %rcx
xorl %esi, %esi
cmpq -0x38(%rbp), %rax
je 0x19ac8
movss (%r13,%rax,4), %xmm2
ucomiss %xmm2, %xmm0
jae 0x19ac1
cvtss2sd %xmm2, %xmm3
movapd %xmm1, %xmm2
divsd %xmm3, %xmm2
movq (%rbx,%rax,8), %rdx
xorl %edi, %edi
movq %rcx, %r8
cmpq %r12, %rdi
je 0x19ac3
cvtss2sd (%rdx,%rdi,4), %xmm3
mulsd %xmm2, %xmm3
movq (%r15,%rdi,8), %r9
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x19ab9
cvtss2sd (%rdx,%r10,4), %xmm4
mulsd %xmm3, %xmm4
addsd (%r9,%r10,8), %xmm4
movsd %xmm4, (%r9,%r10,8)
incq %r10
jmp 0x19a99
incq %rdi
incq %r8
jmp 0x19a84
incl %esi
incq %rax
jmp 0x19a5d
testl %esi, %esi
je 0x19ada
leaq 0x38632(%rip), %rdi     # 0x52105
xorl %eax, %eax
callq 0x20f0
movq %rbx, %rdi
movl -0x2c(%rbp), %ebx
movl %ebx, %esi
callq 0x436f0
movq -0x40(%rbp), %rsp
jmp 0x19b5b
leaq 0x38667(%rip), %rdi     # 0x5215b
callq 0x2090
movq %r14, %rdi
movl %ebx, %esi
callq 0x43bdb
xorl %ecx, %ecx
pushq $0x1
popq %rdx
cmpq -0x38(%rbp), %rcx
je 0x19b51
movq (%rax,%rcx,8), %rsi
xorl %edi, %edi
movq %rdx, %r8
cmpq %r12, %rdi
je 0x19b4c
movq (%r15,%rdi,8), %r9
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x19b44
movsd (%rsi,%rdi,8), %xmm0
mulsd (%rsi,%r10,8), %xmm0
addsd (%r9,%r10,8), %xmm0
movsd %xmm0, (%r9,%r10,8)
incq %r10
jmp 0x19b23
incq %rdi
incq %r8
jmp 0x19b17
incq %rcx
jmp 0x19b08
movq %rax, %rdi
movl %ebx, %esi
callq 0x4372a
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
je 0x19b86
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x19b81
movq (%r15,%rax,8), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r15,%rcx,8), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %rcx
jmp 0x19b65
incq %rax
jmp 0x19b5d
movq %r14, %rdi
movl %ebx, %esi
callq 0x4372a
movq %r15, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq