// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, -0x38(%rbp)
movl %edi, %ebx
movl %edi, %esi
callq 0x49798
movq %rax, %r14
movl %ebx, %eax
movq %rax, -0x30(%rbp)
movl %ebx, -0x44(%rbp)
testl %ebx, %ebx
jle 0x1b966
movq -0x38(%rbp), %rax
decl %eax
movl %eax, -0x48(%rbp)
movl $0x1, %r13d
xorl %ebx, %ebx
movsd 0x3576b(%rip), %xmm0    # 0x51040
xorl %r12d, %r12d
movq %r14, %r15
xorpd %xmm1, %xmm1
cmpl $0x2, -0x38(%rbp)
jl 0x1b938
leal (%r12,%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x50(%rbp)
xorpd %xmm1, %xmm1
movl -0x48(%rbp), %r14d
movapd %xmm0, %xmm2
movsd %xmm2, -0x58(%rbp)
movsd %xmm1, -0x40(%rbp)
movapd %xmm2, %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x20a0
movsd -0x58(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd 0x35711(%rip), %xmm0    # 0x51040
addsd %xmm0, %xmm2
decl %r14d
jne 0x1b901
movq %r15, %r14
movq (%r15,%rbx,8), %rax
movsd %xmm1, (%rax,%r12,8)
movq (%r15,%r12,8), %rax
movsd %xmm1, (%rax,%rbx,8)
incq %r12
cmpq %r13, %r12
jne 0x1b8d8
incq %rbx
incq %r13
cmpq -0x30(%rbp), %rbx
jne 0x1b8d5
movq -0x38(%rbp), %rax
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq (%r14), %rax
movsd %xmm0, (%rax)
movl -0x44(%rbp), %ebx
movl %ebx, %edi
movl %ebx, %esi
callq 0x49798
movq %rax, %r15
movq %r14, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x49810
testl %eax, %eax
je 0x1ba78
leaq 0x3c868(%rip), %rdi     # 0x5820d
callq 0x2090
movl %ebx, %edi
movl %ebx, %esi
callq 0x496ae
movq %rax, %r12
movq %rsp, -0x40(%rbp)
movq %rsp, %r13
movq -0x30(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movl %ebx, %edi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
movl $0x1, %r8d
callq 0x4a4d2
testl %ebx, %ebx
jle 0x1bae8
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd 0x35641(%rip), %xmm1    # 0x51040
xorl %esi, %esi
movq -0x30(%rbp), %r10
movss (%r13,%rax,4), %xmm2
ucomiss %xmm2, %xmm0
jae 0x1ba6c
xorps %xmm3, %xmm3
cvtss2sd %xmm2, %xmm3
movapd %xmm1, %xmm2
divsd %xmm3, %xmm2
movq (%r12,%rax,8), %rcx
movl $0x1, %edx
xorl %edi, %edi
xorps %xmm3, %xmm3
cvtss2sd (%rcx,%rdi,4), %xmm3
mulsd %xmm2, %xmm3
movq (%r15,%rdi,8), %r8
xorl %r9d, %r9d
xorps %xmm4, %xmm4
cvtss2sd (%rcx,%r9,4), %xmm4
mulsd %xmm3, %xmm4
addsd (%r8,%r9,8), %xmm4
movsd %xmm4, (%r8,%r9,8)
incq %r9
cmpq %r9, %rdx
jne 0x1ba3e
incq %rdi
incq %rdx
cmpq %r10, %rdi
jne 0x1ba2b
jmp 0x1ba6e
incl %esi
incq %rax
cmpq %r10, %rax
jne 0x1ba05
jmp 0x1baea
leaq 0x3c7bc(%rip), %rdi     # 0x5823b
callq 0x2090
movq %r14, %rdi
movl %ebx, %esi
callq 0x49b4c
testl %ebx, %ebx
movq -0x30(%rbp), %r10
jle 0x1badc
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movl $0x1, %esi
xorl %edi, %edi
movq (%r15,%rdi,8), %r8
xorl %r9d, %r9d
movsd (%rdx,%rdi,8), %xmm0
mulsd (%rdx,%r9,8), %xmm0
addsd (%r8,%r9,8), %xmm0
movsd %xmm0, (%r8,%r9,8)
incq %r9
cmpq %r9, %rsi
jne 0x1baaa
incq %rdi
incq %rsi
cmpq %r10, %rdi
jne 0x1baa3
incq %rcx
cmpq %r10, %rcx
jne 0x1ba98
movq %rax, %rdi
movl %ebx, %esi
callq 0x49642
jmp 0x1bb0a
xorl %esi, %esi
testl %esi, %esi
je 0x1bafc
leaq 0x3c6f0(%rip), %rdi     # 0x581e5
xorl %eax, %eax
callq 0x20f0
movq %r12, %rdi
movl %ebx, %esi
callq 0x4960c
movq -0x40(%rbp), %rsp
testl %ebx, %ebx
movq -0x30(%rbp), %rdi
jle 0x1bb3d
xorl %eax, %eax
testq %rax, %rax
je 0x1bb35
movq (%r15,%rax,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
movq (%r15,%rdx,8), %rsi
movsd %xmm0, (%rsi,%rax,8)
incq %rdx
cmpq %rdx, %rax
jne 0x1bb1f
incq %rax
cmpq %rdi, %rax
jne 0x1bb14
movq %r14, %rdi
movl %ebx, %esi
callq 0x49642
movq %r15, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq