// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/HMcode/hmcode.c
// Function: hmcode_fill_sigtab
int hmcode_fill_sigtab(
                       struct precision *ppr,
                       struct background *pba,
                       struct perturbations *ppt,
                       struct primordial *ppm,
                       struct fourier *pfo,
                       int index_tau,
                       int index_pk,
                       double **lnpk_l,
                       double **ddlnpk_l,
                       struct hmcode_workspace *phw
                       ) {

  double r;
  double rmin, rmax;
  double sig;
  double *sigtab;
  double *lpk, *ddlpk;
  int i, index_r, index_sig, index_ddsig, index_n, nsig;
  double cbcorr, z, growth;
  int last_index = 0;
  double a,b,h;
  double *head;
  double cbnu_ratio;
  int index_k;
  int index_pk_default;

  struct hmcode_growth *phg;

  phg = phw->phg;

  rmin = ppr->rmin_for_sigtab/pba->h;
  rmax = ppr->rmax_for_sigtab/pba->h;
  nsig = ppr->n_hmcode_tables;

  i=0;
  index_r=i;
  i++;
  index_sig=i;
  i++;
  index_ddsig=i;
  i++;
  index_n=i;

  class_alloc((sigtab),(nsig*index_n*sizeof(double)),pfo->error_message);
  class_alloc(lpk, pfo->k_size_extra*sizeof(double), pfo->error_message);
  class_alloc(ddlpk, pfo->k_size_extra*sizeof(double), pfo->error_message);
  for (index_k=0; index_k<pfo->k_size_extra; index_k++){
    cbcorr = 0.;
    if ((pfo->has_pk_m == _TRUE_ && pfo->has_pk_cb == _TRUE_ && index_pk == pfo->index_pk_m)
        && (pfo->hm_version == hmcode_version_2020 || pfo->hm_version == hmcode_version_2020_baryonic)){

      class_call(background_z_of_tau(pba,pfo->tau[index_tau],&z),
                 pba->error_message,
                 phg->error_message);

      class_call(array_spline_hunt(phg->a_table,
                                   phg->a_size,
                                   1./(z+1.),
                                   &last_index,
                                   &h,
                                   &a,
                                   &b,
                                   pfo->error_message),
                 pfo->error_message,
                 pfo->error_message);

      head = phg->growth_table+last_index*phg->gt_size;
      growth = array_spline_eval(head+phg->index_gt_g,head+phg->index_gt_ddg,0,phg->gt_size,h,a,b);
      // growth = g(a)/a = 1 in the EdS case, otherwise it is found in the growth table (without radiation, though)
      class_call(hmcode_cbnu_ratio(pfo->k[index_k],
                                   z,
                                   phg->fnu,
                                   phg->om_m,
                                   phg->Tcmb,
                                   growth/(1.+z),
                                   &cbnu_ratio),
                 pfo->error_message,
                 pfo->error_message);

      cbcorr = 2. * log(cbnu_ratio);
      lpk[index_k] = lnpk_l[index_pk][index_k]+cbcorr;
    }
    else{
      if (pfo->has_pk_cb == _TRUE_)
        index_pk_default = pfo->index_pk_cb;
      else
        index_pk_default = pfo->index_pk_m;
      lpk[index_k] = lnpk_l[index_pk_default][index_k];//Always take the P(k)_cb if we are a) in the cb case or b) not in HMcode 2020
    }
  }

  class_call(array_spline_table_columns(
                                        pfo->ln_k,
                                        pfo->k_size_extra,
                                        lpk,
                                        1,
                                        ddlpk,
                                        _SPLINE_EST_DERIV_,
                                        pfo->error_message),
             pfo->error_message,
             pfo->error_message);

  for (i=0;i<nsig;i++){
    r=exp(log(rmin)+log(rmax/rmin)*i/(nsig-1));

    class_call(fourier_sigmas(pfo,
                              r,
                              lpk,
                              ddlpk,
                              pfo->k_size_extra,
                              ppr->sigma_k_per_decade,
                              out_sigma,
                              &sig),
               pfo->error_message,
               pfo->error_message);

    sigtab[i*index_n+index_r]=r;
    sigtab[i*index_n+index_sig]=sig;
  }

  class_call(array_spline(sigtab,
						  index_n,
						  nsig,
						  index_r,
						  index_sig,
						  index_ddsig,
						  _SPLINE_EST_DERIV_,
						  pfo->error_message),
             pfo->error_message,
             pfo->error_message);

  if (index_tau == pfo->tau_size-1){
    for (i=0;i<nsig;i++){
      phw->rtab[i] = sigtab[i*index_n+index_r];
      phw->stab[i] = sigtab[i*index_n+index_sig];
      phw->ddstab[i] = sigtab[i*index_n+index_ddsig];
    }
  }
  else{
    for (i=0;i<nsig;i++){
      phw->stab[i] = sigtab[i*index_n+index_sig];
      phw->ddstab[i] = sigtab[i*index_n+index_ddsig];
    }
  }

  free(lpk);
  free(ddlpk);
  free(sigtab);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8a8, %rsp            # imm = 0x8A8
movl %r9d, %r13d
movq %r8, %r14
movq %rdi, %rbp
movq 0x8f8(%rsp), %rax
movl $0x0, 0x24(%rsp)
movq 0x70(%rax), %rbx
movq %rsi, 0x18(%rsp)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8a0(%rdi), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x8a8(%rdi), %xmm0
movsd %xmm0, 0x48(%rsp)
movslq 0x898(%rdi), %r15
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x8460
testq %rax, %rax
je 0xe60ff
movl %r13d, 0x20(%rsp)
movq %r15, 0x30(%rsp)
movq %rax, 0x60(%rsp)
movslq 0x104(%r14), %r15
movq %r15, %r13
shlq $0x3, %r13
movq %r13, %rdi
callq 0x8460
testq %rax, %rax
je 0xe6144
movq %rax, %r12
movq %r13, %rdi
callq 0x8460
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0xe618b
movl 0x104(%r14), %esi
testl %esi, %esi
jle 0xe6088
movq 0x8e8(%rsp), %r13
movl 0x8e0(%rsp), %ecx
movslq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x192(%r14), %rax
movq %rax, 0x58(%rsp)
movslq %ecx, %rax
movq %rax, 0x70(%rsp)
xorl %r15d, %r15d
cmpw $0x1, 0x50(%r14)
jne 0xe6054
cmpw $0x1, 0x52(%r14)
jne 0xe6054
cmpl %ecx, 0x54(%r14)
jne 0xe6054
movl 0xc(%r14), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0xe6054
movq 0x148(%r14), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x5ee3a
cmpl $0x1, %eax
je 0xe6482
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
movsd 0x68(%rsp), %xmm1
movsd 0xb344(%rip), %xmm0     # 0xf1260
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
leaq 0x24(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x88(%rsp), %r9
callq 0x19cfd
cmpl $0x1, %eax
je 0xe64d3
movslq 0x24(%rsp), %rcx
movslq 0x30(%rbx), %rax
imulq %rax, %rcx
shlq $0x3, %rcx
addq 0x10(%rbx), %rcx
movsd 0x90(%rsp), %xmm1
movslq 0x34(%rbx), %rdx
leaq (%rcx,%rdx,8), %rdx
movsd 0x88(%rsp), %xmm2
movsd (%rdx,%rax,8), %xmm3
mulsd %xmm2, %xmm3
movsd (%rdx), %xmm0
mulsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movapd %xmm1, %xmm5
mulsd %xmm1, %xmm5
mulsd %xmm1, %xmm5
subsd %xmm1, %xmm5
movslq 0x38(%rbx), %rdx
leaq (%rcx,%rdx,8), %rcx
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
subsd %xmm2, %xmm1
mulsd (%rcx,%rax,8), %xmm1
mulsd (%rcx), %xmm5
addsd %xmm1, %xmm5
movsd 0x80(%rsp), %xmm1
mulsd %xmm1, %xmm5
mulsd %xmm1, %xmm5
divsd 0xc686(%rip), %xmm5     # 0xf2670
addsd %xmm0, %xmm5
movq 0x78(%r14), %rax
movsd (%rax,%r15,8), %xmm0
movsd 0xa8(%rbx), %xmm2
movsd 0x98(%rbx), %xmm4
movsd 0xa0(%rbx), %xmm3
movsd 0x68(%rsp), %xmm1
addsd 0xb242(%rip), %xmm1     # 0xf1260
divsd %xmm1, %xmm5
leaq 0x78(%rsp), %rdi
callq 0xe6516
movsd 0x78(%rsp), %xmm0
callq 0x82c0
addsd %xmm0, %xmm0
movq 0x70(%rsp), %rax
movq (%r13,%rax,8), %rax
addsd (%rax,%r15,8), %xmm0
movl 0x8e0(%rsp), %ecx
jmp 0xe606f
xorl %eax, %eax
cmpw $0x1, 0x52(%r14)
sete %al
movslq 0x54(%r14,%rax,4), %rax
movq (%r13,%rax,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%r12,%r15,8)
incq %r15
movslq 0x104(%r14), %rsi
cmpq %rsi, %r15
jl 0xe5ead
movq 0x80(%r14), %rdi
leaq 0x192(%r14), %rbx
movq %rbx, (%rsp)
movl $0x1, %r13d
movq %r12, %rdx
movl $0x1, %ecx
movq 0x40(%rsp), %r8
movl $0x1, %r9d
callq 0x15654
cmpl $0x1, %eax
jne 0xe61f5
leaq 0xb328(%rip), %rsi      # 0xf13f0
leaq 0x4a190(%rip), %rdx     # 0x13025f
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xaf49(%rip), %rsi      # 0xf1034
leaq 0x4a0bf(%rip), %rdx     # 0x1301b1
movq %rbx, %rdi
movl $0x4fe, %ecx            # imm = 0x4FE
jmp 0xe636b
leaq 0xaefe(%rip), %rsi      # 0xf1004
leaq 0x4a09b(%rip), %rdx     # 0x1301a8
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r14            # imm = 0x192
leaq 0xaf04(%rip), %rsi      # 0xf1034
leaq 0x4a07a(%rip), %rdx     # 0x1301b1
movq %r14, %rdi
movl $0x4c5, %ecx            # imm = 0x4C5
jmp 0xe61d0
leal (,%r15,8), %ecx
leaq 0xaeb1(%rip), %rsi      # 0xf1004
leaq 0x4a06c(%rip), %rdx     # 0x1301c6
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r14            # imm = 0x192
leaq 0xaeba(%rip), %rsi      # 0xf1034
leaq 0x4a030(%rip), %rdx     # 0x1301b1
movq %r14, %rdi
movl $0x4c6, %ecx            # imm = 0x4C6
jmp 0xe61d0
leal (,%r15,8), %ecx
leaq 0xae6a(%rip), %rsi      # 0xf1004
leaq 0x4a023(%rip), %rdx     # 0x1301c4
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r14            # imm = 0x192
leaq 0xae73(%rip), %rsi      # 0xf1034
leaq 0x49fe9(%rip), %rdx     # 0x1301b1
movq %r14, %rdi
movl $0x4c7, %ecx            # imm = 0x4C7
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %r13d
movl %r13d, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x28(%rsp)
cmpl $0x0, 0x30(%rsp)
jle 0xe62ee
movsd 0x50(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
divsd %xmm2, %xmm0
movsd 0x48(%rsp), %xmm1
divsd %xmm2, %xmm1
movq 0x30(%rsp), %rax
decl %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd %xmm2, 0x38(%rsp)
movsd %xmm0, 0x50(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movq 0x60(%rsp), %rax
leaq 0x8(%rax), %r15
xorl %ebx, %ebx
leaq 0x98(%rsp), %r13
movsd 0x50(%rsp), %xmm0
callq 0x82c0
movsd %xmm0, 0x18(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x82c0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm1, %xmm0
divsd 0x38(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
callq 0x8670
movl 0x104(%r14), %ecx
movsd 0x830(%rbp), %xmm1
movq %r14, %rdi
movsd %xmm0, 0x18(%rsp)
movq %r12, %rsi
movq 0x40(%rsp), %rdx
xorl %r8d, %r8d
movq %r13, %r9
callq 0xa2522
cmpl $0x1, %eax
je 0xe63e0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, -0x8(%r15)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, (%r15)
incq %rbx
addq $0x18, %r15
cmpq %rbx, 0x30(%rsp)
jne 0xe6256
movq 0x28(%rsp), %rbp
movq %rbp, 0x8(%rsp)
movl $0x1, (%rsp)
movl $0x1, %r13d
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
movq 0x30(%rsp), %r15
movl %r15d, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x136a5
cmpl $0x1, %eax
jne 0xe637a
leaq 0xb0b7(%rip), %rsi      # 0xf13f0
leaq 0x49fdf(%rip), %rdx     # 0x13031f
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xacd8(%rip), %rsi      # 0xf1034
leaq 0x49e4e(%rip), %rdx     # 0x1301b1
movq %rbp, %rdi
movl $0x51b, %ecx            # imm = 0x51B
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
jmp 0xe61e0
movl 0x140(%r14), %eax
decl %eax
cmpl 0x20(%rsp), %eax
jne 0xe6423
testl %r15d, %r15d
movq 0x8f8(%rsp), %rdx
jle 0xe6460
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movq %rbx, %rsi
addq $0x10, %rsi
xorl %edi, %edi
movsd -0x10(%rsi), %xmm0
movsd %xmm0, (%rax,%rdi,8)
movsd -0x8(%rsi), %xmm0
movsd %xmm0, (%rcx,%rdi,8)
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx,%rdi,8)
incq %rdi
addq $0x18, %rsi
cmpq %rdi, %r15
jne 0xe63b2
jmp 0xe6460
leaq 0xb009(%rip), %rsi      # 0xf13f0
leaq 0x49ed1(%rip), %rdx     # 0x1302bf
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xac25(%rip), %rsi      # 0xf1034
leaq 0x49d9b(%rip), %rdx     # 0x1301b1
movq %rbx, %rdi
movl $0x50c, %ecx            # imm = 0x50C
jmp 0xe64cb
testl %r15d, %r15d
movq 0x8f8(%rsp), %rcx
jle 0xe6460
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %rbx, %rdx
addq $0x10, %rdx
xorl %esi, %esi
movsd -0x8(%rdx), %xmm0
movsd %xmm0, (%rax,%rsi,8)
movsd (%rdx), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
addq $0x18, %rdx
cmpq %rsi, %r15
jne 0xe6441
movq %r12, %rdi
callq 0x8410
movq 0x40(%rsp), %rdi
callq 0x8410
movq %rbx, %rdi
callq 0x8410
xorl %r13d, %r13d
jmp 0xe61e0
movq 0x18(%rsp), %rcx
addq $0xd1c, %rcx            # imm = 0xD1C
leaq 0xaf5b(%rip), %rsi      # 0xf13f0
leaq 0x49d2e(%rip), %rdx     # 0x1301ca
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x100, %rbx            # imm = 0x100
leaq 0xab78(%rip), %rsi      # 0xf1034
leaq 0x49cee(%rip), %rdx     # 0x1301b1
movq %rbx, %rdi
movl $0x4cf, %ecx            # imm = 0x4CF
movq %r14, %r8
jmp 0xe61d3
leaq 0xaf16(%rip), %rsi      # 0xf13f0
leaq 0x49d19(%rip), %rdx     # 0x1301fa
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xab32(%rip), %rsi      # 0xf1034
leaq 0x49ca8(%rip), %rdx     # 0x1301b1
movq %r14, %rdi
movl $0x4da, %ecx            # imm = 0x4DA
jmp 0xe61d0