// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movq %r8, %r14
movq %rsi, %r13
movq 0x8f8(%rsp), %rax
movl $0x0, 0x1c(%rsp)
movq 0x70(%rax), %rbx
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8a0(%rdi), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x8a8(%rdi), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rdi, 0x70(%rsp)
movslq 0x898(%rdi), %r12
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %r15
movq %r15, %rdi
callq 0x8460
testq %rax, %rax
je 0xe2bd2
movl %ebp, 0x18(%rsp)
movq %r12, 0x28(%rsp)
movq %rax, 0x48(%rsp)
movslq 0x104(%r14), %rbp
movq %rbp, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8460
testq %rax, %rax
je 0xe2c17
movq %rax, %r12
movq %r15, %rdi
callq 0x8460
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0xe2c5d
testl %ebp, %ebp
jle 0xe2b59
movq %r13, 0x20(%rsp)
movq 0x8e8(%rsp), %rsi
movl 0x8e0(%rsp), %r13d
movslq 0x18(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x192(%r14), %rax
movq %rax, 0x50(%rsp)
movslq %r13d, %rax
movq %rax, 0x60(%rsp)
xorl %r15d, %r15d
movl 0x50(%r14), %ecx
xorl $0x1, %ecx
movzwl 0x52(%r14), %eax
movl %eax, %edx
xorl $0x1, %edx
orw %cx, %dx
jne 0xe2b2c
cmpl %r13d, 0x54(%r14)
jne 0xe2b2c
movl 0xc(%r14), %ecx
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0xe2b2c
movq %rsi, %rbp
movq 0x148(%r14), %rax
movq 0x68(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x5c726
cmpl $0x1, %eax
je 0xe2ee6
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
movsd 0x58(%rsp), %xmm1
movsd 0xb875(%rip), %xmm0     # 0xee260
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1c(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x88(%rsp), %r9
callq 0x19e56
cmpl $0x1, %eax
je 0xe2f37
movslq 0x1c(%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 0xcbb7(%rip), %xmm5     # 0xef670
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 0x58(%rsp), %xmm1
addsd 0xb773(%rip), %xmm1     # 0xee260
divsd %xmm1, %xmm5
leaq 0x78(%rsp), %rdi
callq 0xe2fd8
movsd 0x78(%rsp), %xmm0
callq 0x82c0
addsd %xmm0, %xmm0
movq %rbp, %rsi
movq 0x60(%rsp), %rax
movq (%rbp,%rax,8), %rax
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%r12,%r15,8)
movl 0x104(%r14), %ebp
jmp 0xe2b4a
xorl %ecx, %ecx
cmpw $0x1, %ax
sete %cl
movslq 0x54(%r14,%rcx,4), %rax
movq (%rsi,%rax,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%r12,%r15,8)
incq %r15
movslq %ebp, %rax
cmpq %rax, %r15
jl 0xe2977
movq 0x80(%r14), %rdi
leaq 0x192(%r14), %rbx
movq %rbx, (%rsp)
movl $0x1, %r13d
movl %ebp, %esi
movq %r12, %rdx
movl $0x1, %ecx
movq 0x30(%rsp), %r8
movl $0x1, %r9d
callq 0x1577e
cmpl $0x1, %eax
jne 0xe2cc6
leaq 0xb855(%rip), %rsi      # 0xee3f0
leaq 0x4a6ed(%rip), %rdx     # 0x12d28f
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xb476(%rip), %rsi      # 0xee034
leaq 0x4a61c(%rip), %rdx     # 0x12d1e1
movq %rbx, %rdi
movl $0x4fe, %ecx            # imm = 0x4FE
jmp 0xe2e37
leaq 0xb42b(%rip), %rsi      # 0xee004
leaq 0x4a5f8(%rip), %rdx     # 0x12d1d8
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x192, %r14            # imm = 0x192
leaq 0xb431(%rip), %rsi      # 0xee034
leaq 0x4a5d7(%rip), %rdx     # 0x12d1e1
movq %r14, %rdi
movl $0x4c5, %ecx            # imm = 0x4C5
jmp 0xe2ca1
leal (,%rbp,8), %ecx
leaq 0xb3df(%rip), %rsi      # 0xee004
leaq 0x4a5ca(%rip), %rdx     # 0x12d1f6
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x192, %r14            # imm = 0x192
leaq 0xb3e8(%rip), %rsi      # 0xee034
leaq 0x4a58e(%rip), %rdx     # 0x12d1e1
movq %r14, %rdi
movl $0x4c6, %ecx            # imm = 0x4C6
jmp 0xe2ca1
leal (,%rbp,8), %ecx
leaq 0xb399(%rip), %rsi      # 0xee004
leaq 0x4a582(%rip), %rdx     # 0x12d1f4
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x192, %r14            # imm = 0x192
leaq 0xb3a2(%rip), %rsi      # 0xee034
leaq 0x4a548(%rip), %rdx     # 0x12d1e1
movq %r14, %rdi
movl $0x4c7, %ecx            # imm = 0x4C7
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %r13d
movl %r13d, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x28(%rsp)
jle 0xe2dc0
movsd 0x40(%rsp), %xmm0
movsd 0x10(%rsp), %xmm2
divsd %xmm2, %xmm0
movsd 0x38(%rsp), %xmm1
divsd %xmm2, %xmm1
movq 0x28(%rsp), %rax
decl %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd %xmm2, 0x20(%rsp)
movsd %xmm0, 0x40(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movq 0x48(%rsp), %rax
leaq 0x8(%rax), %r13
xorl %ebp, %ebp
leaq 0x98(%rsp), %r15
movsd 0x40(%rsp), %xmm0
callq 0x82c0
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x82c0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
callq 0x8670
movl 0x104(%r14), %ecx
movq 0x70(%rsp), %rax
movsd 0x830(%rax), %xmm1
movq %r14, %rdi
movsd %xmm0, 0x10(%rsp)
movq %r12, %rsi
movq 0x30(%rsp), %rdx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x9f650
cmpl $0x1, %eax
je 0xe2eab
movsd 0x10(%rsp), %xmm0
movsd %xmm0, -0x8(%r13)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, (%r13)
incq %rbp
addq $0x18, %r13
cmpq %rbp, 0x28(%rsp)
jne 0xe2d22
movq %rbx, 0x8(%rsp)
movl $0x1, (%rsp)
movl $0x1, %r13d
movq 0x48(%rsp), %r15
movq %r15, %rdi
movl $0x3, %esi
movq 0x28(%rsp), %rbp
movl %ebp, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x1381e
cmpl $0x1, %eax
jne 0xe2e46
leaq 0xb5eb(%rip), %rsi      # 0xee3f0
leaq 0x4a543(%rip), %rdx     # 0x12d34f
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xb20c(%rip), %rsi      # 0xee034
leaq 0x4a3b2(%rip), %rdx     # 0x12d1e1
movq %rbx, %rdi
movl $0x51b, %ecx            # imm = 0x51B
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
jmp 0xe2cb1
movl 0x140(%r14), %eax
decl %eax
cmpl 0x18(%rsp), %eax
jne 0xe2f7a
testl %ebp, %ebp
jle 0xe2fb6
movq 0x8f8(%rsp), %rdx
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movq %r15, %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, %rbp
jne 0xe2e7d
jmp 0xe2fb6
leaq 0xb53e(%rip), %rsi      # 0xee3f0
leaq 0x4a436(%rip), %rdx     # 0x12d2ef
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xb15f(%rip), %rsi      # 0xee034
leaq 0x4a305(%rip), %rdx     # 0x12d1e1
movq %rbx, %rdi
movl $0x50c, %ecx            # imm = 0x50C
jmp 0xe2f2f
movq 0x20(%rsp), %rcx
addq $0xd1c, %rcx            # imm = 0xD1C
leaq 0xb4f7(%rip), %rsi      # 0xee3f0
leaq 0x4a2fa(%rip), %rdx     # 0x12d1fa
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x100, %rbx            # imm = 0x100
leaq 0xb114(%rip), %rsi      # 0xee034
leaq 0x4a2ba(%rip), %rdx     # 0x12d1e1
movq %rbx, %rdi
movl $0x4cf, %ecx            # imm = 0x4CF
movq %r14, %r8
jmp 0xe2ca4
leaq 0xb4b2(%rip), %rsi      # 0xee3f0
leaq 0x4a2e5(%rip), %rdx     # 0x12d22a
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x50(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xb0ce(%rip), %rsi      # 0xee034
leaq 0x4a274(%rip), %rdx     # 0x12d1e1
movq %r14, %rdi
movl $0x4da, %ecx            # imm = 0x4DA
jmp 0xe2ca1
testl %ebp, %ebp
jle 0xe2fb6
movq 0x8f8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %r15, %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, %rbp
jne 0xe2f97
movq %r12, %rdi
callq 0x8410
movq 0x30(%rsp), %rdi
callq 0x8410
movq %r15, %rdi
callq 0x8410
xorl %r13d, %r13d
jmp 0xe2cb1