// File: /workspace/github_c_makefile_star2_O2/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, %rbx
andl $0x0, 0x3c(%rsp)
movq %rdi, %r13
movq 0x8f8(%rsp), %rax
movq 0x70(%rax), %r14
movq %rsi, 0x18(%rsp)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x8a0(%rdi), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x8a8(%rdi), %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x898(%rdi), %r12
imulq $0x18, %r12, %r15
movq %r15, %rdi
callq 0x8490
testq %rax, %rax
je 0xda7f7
movq %r12, 0x50(%rsp)
movl %ebp, 0x38(%rsp)
movq %rax, 0x58(%rsp)
movslq 0x104(%rbx), %r12
movq %r12, %rbp
shlq $0x3, %rbp
movq %rbp, %rdi
callq 0x8490
testq %rax, %rax
je 0xda83c
movq %rax, %r15
movq %rbp, %rdi
callq 0x8490
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0xda8fc
movq %r13, 0x68(%rsp)
movq 0x8e8(%rsp), %rsi
movl 0x8e0(%rsp), %r13d
movsd 0x40(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x192(%rbx), %rax
movq %rax, 0x20(%rsp)
movslq %r13d, %rax
movq %rax, 0x70(%rsp)
xorl %ebp, %ebp
movslq %r12d, %rax
cmpq %rax, %rbp
jge 0xda886
movl 0x50(%rbx), %ecx
xorl $0x1, %ecx
movzwl 0x52(%rbx), %eax
movl %eax, %edx
xorl $0x1, %edx
orw %cx, %dx
jne 0xda7d2
cmpl %r13d, 0x54(%rbx)
jne 0xda7d2
movl 0xc(%rbx), %ecx
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0xda7d2
movq %rsi, %r12
movq 0x148(%rbx), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x58962
cmpl $0x1, %eax
je 0xdab09
movq (%r14), %rdi
movl 0x8(%r14), %esi
movsd 0x60(%rsp), %xmm1
movsd 0xabcf(%rip), %xmm0     # 0xe5260
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
leaq 0x3c(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x88(%rsp), %r9
callq 0x17d10
cmpl $0x1, %eax
je 0xdab54
movslq 0x3c(%rsp), %rcx
movslq 0x30(%r14), %rax
imulq %rax, %rcx
shlq $0x3, %rcx
addq 0x10(%r14), %rcx
movsd 0x90(%rsp), %xmm1
movslq 0x34(%r14), %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(%r14), %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 0xbef1(%rip), %xmm5     # 0xe6650
addsd %xmm0, %xmm5
movq 0x78(%rbx), %rax
movsd (%rax,%rbp,8), %xmm0
movsd 0xa8(%r14), %xmm2
movsd 0x98(%r14), %xmm4
movsd 0xa0(%r14), %xmm3
movsd 0x60(%rsp), %xmm1
addsd 0xaacb(%rip), %xmm1     # 0xe5260
divsd %xmm1, %xmm5
leaq 0x78(%rsp), %rdi
callq 0xdac4a
movsd 0x78(%rsp), %xmm0
callq 0x82e0
addsd %xmm0, %xmm0
movq %r12, %rsi
movq 0x70(%rsp), %rax
movq (%r12,%rax,8), %rax
addsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%r15,%rbp,8)
movl 0x104(%rbx), %r12d
jmp 0xda7ef
xorl %ecx, %ecx
cmpw $0x1, %ax
sete %cl
movslq 0x54(%rbx,%rcx,4), %rax
movq (%rsi,%rax,8), %rax
movsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0xda613
leaq 0xa806(%rip), %rsi      # 0xe5004
leaq 0x49843(%rip), %rdx     # 0x124048
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0xa80c(%rip), %rsi      # 0xe5034
leaq 0x49822(%rip), %rdx     # 0x124051
movq %rbx, %rdi
movl $0x4c5, %ecx            # imm = 0x4C5
jmp 0xda941
leal (,%r12,8), %ecx
leaq 0xa7b9(%rip), %rsi      # 0xe5004
leaq 0x49814(%rip), %rdx     # 0x124066
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0xa7c2(%rip), %rsi      # 0xe5034
leaq 0x497d8(%rip), %rdx     # 0x124051
movq %rbx, %rdi
movl $0x4c6, %ecx            # imm = 0x4C6
jmp 0xda941
movq 0x80(%rbx), %rdi
movq 0x20(%rsp), %r14
movq %r14, (%rsp)
pushq $0x1
popq %rbp
movl %r12d, %esi
movq %r15, %rdx
movl %ebp, %ecx
movq 0x48(%rsp), %r8
movl %ebp, %r9d
callq 0x139d8
cmpl $0x1, %eax
jne 0xda962
leaq 0xab32(%rip), %rsi      # 0xe53f0
leaq 0x4983a(%rip), %rdx     # 0x1240ff
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xa753(%rip), %rsi      # 0xe5034
leaq 0x49769(%rip), %rdx     # 0x124051
movq %r14, %rdi
movl $0x4fe, %ecx            # imm = 0x4FE
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
jmp 0xda94e
leal (,%r12,8), %ecx
leaq 0xa6f9(%rip), %rsi      # 0xe5004
leaq 0x49752(%rip), %rdx     # 0x124064
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0xa702(%rip), %rsi      # 0xe5034
leaq 0x49718(%rip), %rdx     # 0x124051
movq %rbx, %rdi
movl $0x4c7, %ecx            # imm = 0x4C7
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rcx
leal -0x1(%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r12d, %r12d
testl %ecx, %ecx
movl $0x0, %ebp
cmovgl %ecx, %ebp
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %r14
movq 0x68(%rsp), %r13
cmpq %r12, %rbp
je 0xdaa3f
movsd 0x40(%rsp), %xmm0
callq 0x82e0
movsd %xmm0, 0x18(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x82e0
cvtsi2sd %r12d, %xmm1
mulsd %xmm1, %xmm0
divsd 0x28(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
callq 0x86a0
movl 0x104(%rbx), %ecx
movsd 0x830(%r13), %xmm1
movq %rbx, %rdi
movsd %xmm0, 0x18(%rsp)
movq %r15, %rsi
movq 0x48(%rsp), %rdx
xorl %r8d, %r8d
leaq 0x98(%rsp), %r9
callq 0x9a68f
cmpl $0x1, %eax
je 0xdaac6
movsd 0x18(%rsp), %xmm0
movsd %xmm0, -0x8(%r14)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, (%r14)
incq %r12
addq $0x18, %r14
jmp 0xda9a1
movq 0x20(%rsp), %r12
movq %r12, 0x8(%rsp)
movl $0x1, (%rsp)
pushq $0x3
popq %rsi
pushq $0x1
popq %r8
pushq $0x2
popq %r9
movq 0x58(%rsp), %r14
movq %r14, %rdi
movq 0x50(%rsp), %rdx
xorl %ecx, %ecx
movl %r8d, %r13d
callq 0x11b09
cmpl $0x1, %eax
jne 0xdab9a
leaq 0xa96e(%rip), %rsi      # 0xe53f0
leaq 0x49736(%rip), %rdx     # 0x1241bf
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xa58f(%rip), %rsi      # 0xe5034
leaq 0x495a5(%rip), %rdx     # 0x124051
movq %r12, %rdi
movl $0x51b, %ecx            # imm = 0x51B
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
movl %r13d, %ebp
jmp 0xda94e
leaq 0xa923(%rip), %rsi      # 0xe53f0
leaq 0x4968b(%rip), %rdx     # 0x12415f
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xa53f(%rip), %rsi      # 0xe5034
leaq 0x49555(%rip), %rdx     # 0x124051
movq %r14, %rdi
movl $0x50c, %ecx            # imm = 0x50C
jmp 0xdab92
movq 0x18(%rsp), %rcx
addq $0xd1c, %rcx            # imm = 0xD1C
leaq 0xa8d4(%rip), %rsi      # 0xe53f0
leaq 0x49547(%rip), %rdx     # 0x12406a
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x100, %r14            # imm = 0x100
leaq 0xa4f1(%rip), %rsi      # 0xe5034
leaq 0x49507(%rip), %rdx     # 0x124051
movq %r14, %rdi
movl $0x4cf, %ecx            # imm = 0x4CF
jmp 0xdab92
leaq 0xa895(%rip), %rsi      # 0xe53f0
leaq 0x49538(%rip), %rdx     # 0x12409a
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xa4b1(%rip), %rsi      # 0xe5034
leaq 0x494c7(%rip), %rdx     # 0x124051
movq %r14, %rdi
movl $0x4da, %ecx            # imm = 0x4DA
movq %rbx, %r8
jmp 0xda944
movl 0x140(%rbx), %eax
decl %eax
cmpl 0x38(%rsp), %eax
jne 0xdabef
movq %r14, %rax
addq $0x10, %rax
xorl %ecx, %ecx
movq 0x8f8(%rsp), %rsi
cmpq %rcx, %rbp
je 0xdac29
movsd -0x10(%rax), %xmm0
movq (%rsi), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movsd -0x8(%rax), %xmm0
movq 0x8(%rsi), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movsd (%rax), %xmm0
movq 0x10(%rsi), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
addq $0x18, %rax
jmp 0xdabb9
movq %r14, %rax
addq $0x10, %rax
xorl %ecx, %ecx
movq 0x8f8(%rsp), %rsi
cmpq %rcx, %rbp
je 0xdac29
movsd -0x8(%rax), %xmm0
movq 0x8(%rsi), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movsd (%rax), %xmm0
movq 0x10(%rsi), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
addq $0x18, %rax
jmp 0xdac00
movq %r15, %rdi
callq 0x8430
movq 0x48(%rsp), %rdi
callq 0x8430
movq %r14, %rdi
callq 0x8430
xorl %ebp, %ebp
jmp 0xda94e