// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../source/fourier.c
// Function: fourier_get_source
int fourier_get_source(
                       struct background * pba,
                       struct perturbations * ppt,
                       struct fourier * pfo,
                       int index_k,
                       int index_ic,
                       int index_tp,
                       int index_tau,
                       double ** sources,
                       double * source
                       ) {

  double k,k_max,k_previous;
  double source_max,source_previous;
  double scaled_factor,log_scaled_factor;

  /** - use precomputed values */
  if (index_k < pfo->k_size) {
    *source = sources[index_ic * ppt->tp_size[pfo->index_md_scalars] + index_tp][index_tau * pfo->k_size + index_k];
  }
  /** - extrapolate **/
  else {

    k = pfo->k[index_k];

    /**
     * --> Get last source and k, which are used in (almost) all methods
     */
    k_max = pfo->k[pfo->k_size-1];
    source_max = sources[index_ic * ppt->tp_size[pfo->index_md_scalars] + index_tp][index_tau * pfo->k_size + pfo->k_size - 1];

    /**
     * --> Get previous source and k, which are used in best methods
     */
    k_previous = pfo->k[pfo->k_size-2];
    source_previous = sources[index_ic * ppt->tp_size[pfo->index_md_scalars] + index_tp][index_tau * pfo->k_size + pfo->k_size - 2];

    switch(pfo->extrapolation_method){
      /**
       * --> Extrapolate by assuming the source to vanish Has terrible
       * discontinuity
       */
    case extrap_zero:
      {
        *source=0.0;
        break;
      }
      /**
       * --> Extrapolate starting from the maximum value, assuming  growth ~ ln(k)
       * Has a terrible bend in log slope, discontinuity only in derivative
       */
    case extrap_only_max:
      {
        *source = source_max*(log(k)/log(k_max));
        break;
      }
      /**
       * --> Extrapolate starting from the maximum value, assuming
       * growth ~ ln(k) Here we use k in h/Mpc instead of 1/Mpc as it
       * is done in the CAMB implementation of HMcode Has a terrible
       * bend in log slope, discontinuity only in derivative
       */
    case extrap_only_max_units:
      {
        *source = source_max*(log(k/pba->h)/log(k_max/pba->h));
        break;
      }
      /**
       * --> Extrapolate assuming source ~ ln(a*k) where a is obtained
       * from the data at k_0 Mostly continuous derivative, quite good
       */
    case extrap_max_scaled:
      {
        log_scaled_factor = (source_previous*log(k_max)-source_max*log(k_previous))/(source_max-source_previous);
        *source = source_max*((log_scaled_factor+log(k))/(log_scaled_factor+log(k_max)));
        break;
      }
      /**
       * --> Extrapolate assuming source ~ ln(e+a*k) where a is
       * estimated like is done in original HMCode
       */
    case extrap_hmcode:
      {
        scaled_factor = 1.8/(13.41*pba->a_eq*pba->H_eq);
        *source = source_max*(log(_E_+scaled_factor*k)/log(_E_+scaled_factor*k_max));
        break;
      }
      /**
       * --> If the user has a complicated model and wants to
       * interpolate differently, they can define their interpolation
       * here and switch to using it instead
       */
    case extrap_user_defined:
      {
        class_stop(pfo->error_message,"Method of source extrapolation 'user_defined' was not yet defined.");
        break;
      }
    }
  }
  return _SUCCESS_;
}

// Assembly:
subq $0x10d8, %rsp           # imm = 0x10D8
movq 0x10f0(%rsp), %rax
movq 0x10e8(%rsp), %rax
movl 0x10e0(%rsp), %eax
movq %rdi, 0x10c8(%rsp)
movq %rsi, 0x10c0(%rsp)
movq %rdx, 0x10b8(%rsp)
movl %ecx, 0x10b4(%rsp)
movl %r8d, 0x10b0(%rsp)
movl %r9d, 0x10ac(%rsp)
movl 0x10b4(%rsp), %eax
movq 0x10b8(%rsp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x12f330
movq 0x10e8(%rsp), %rax
movl 0x10b0(%rsp), %ecx
movq 0x10c0(%rsp), %rdx
movq 0x998(%rdx), %rdx
movq 0x10b8(%rsp), %rsi
movslq 0x3c(%rsi), %rsi
imull (%rdx,%rsi,4), %ecx
addl 0x10ac(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl 0x10e0(%rsp), %ecx
movq 0x10b8(%rsp), %rdx
imull 0x6c(%rdx), %ecx
addl 0x10b4(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x10f0(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x12f7c8
movq 0x10b8(%rsp), %rax
movq 0x78(%rax), %rax
movslq 0x10b4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10a0(%rsp)
movq 0x10b8(%rsp), %rcx
movq 0x78(%rcx), %rax
movl 0x6c(%rcx), %ecx
decl %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1098(%rsp)
movq 0x10e8(%rsp), %rax
movl 0x10b0(%rsp), %edx
movq 0x10c0(%rsp), %rcx
movq 0x998(%rcx), %rsi
movq 0x10b8(%rsp), %rcx
movslq 0x3c(%rcx), %rdi
movl (%rsi,%rdi,4), %esi
imull %esi, %edx
movl 0x10ac(%rsp), %esi
addl %esi, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl 0x10e0(%rsp), %esi
movl 0x6c(%rcx), %ecx
imull %ecx, %esi
movl %ecx, %edx
movl %esi, %ecx
leal -0x1(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1088(%rsp)
movq 0x10b8(%rsp), %rcx
movq 0x78(%rcx), %rax
movl 0x6c(%rcx), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1090(%rsp)
movq 0x10e8(%rsp), %rax
movl 0x10b0(%rsp), %edx
movq 0x10c0(%rsp), %rcx
movq 0x998(%rcx), %rsi
movq 0x10b8(%rsp), %rcx
movslq 0x3c(%rcx), %rdi
movl (%rsi,%rdi,4), %esi
imull %esi, %edx
movl 0x10ac(%rsp), %esi
addl %esi, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl 0x10e0(%rsp), %esi
movl 0x6c(%rcx), %ecx
imull %ecx, %esi
movl %ecx, %edx
movl %esi, %ecx
leal -0x2(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1080(%rsp)
movq 0x10b8(%rsp), %rax
movl 0x4(%rax), %eax
movq %rax, 0x68(%rsp)
subq $0x5, %rax
ja 0x12f7c6
movq 0x68(%rsp), %rax
leaq 0xd01a7(%rip), %rcx     # 0x1ff630
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10f0(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x12f7c6
movsd 0x1088(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x10a0(%rsp), %xmm0
callq 0x82f0
movsd %xmm0, 0x58(%rsp)
movsd 0x1098(%rsp), %xmm0
callq 0x82f0
movsd 0x58(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x60(%rsp), %xmm0
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x10f0(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x12f7c6
movsd 0x1088(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x10a0(%rsp), %xmm0
movq 0x10c8(%rsp), %rax
divsd 0x8(%rax), %xmm0
callq 0x82f0
movsd %xmm0, 0x48(%rsp)
movsd 0x1098(%rsp), %xmm0
movq 0x10c8(%rsp), %rax
divsd 0x8(%rax), %xmm0
callq 0x82f0
movsd 0x48(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x10f0(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x12f7c6
movsd 0x1080(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x1098(%rsp), %xmm0
callq 0x82f0
movsd %xmm0, 0x18(%rsp)
movsd 0x1088(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x1090(%rsp), %xmm0
callq 0x82f0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movaps %xmm0, %xmm3
movsd 0x20(%rsp), %xmm0
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x1088(%rsp), %xmm1
subsd 0x1080(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x1070(%rsp)
movsd 0x1088(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x1070(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x10a0(%rsp), %xmm0
callq 0x82f0
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x1070(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x1098(%rsp), %xmm0
callq 0x82f0
movsd 0x30(%rsp), %xmm2
movsd 0x38(%rsp), %xmm1
movaps %xmm0, %xmm3
movsd 0x40(%rsp), %xmm0
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x10f0(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x12f7c6
movq 0x10c8(%rsp), %rax
movsd 0xcff71(%rip), %xmm1    # 0x1ff618
mulsd 0x360(%rax), %xmm1
movq 0x10c8(%rsp), %rax
mulsd 0x368(%rax), %xmm1
movsd 0xa58c9(%rip), %xmm0    # 0x1d4f90
divsd %xmm1, %xmm0
movsd %xmm0, 0x1078(%rsp)
movsd 0x1088(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x1078(%rsp), %xmm0
movsd 0x10a0(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xcff0f(%rip), %xmm1    # 0x1ff610
addsd %xmm1, %xmm0
callq 0x82f0
movsd %xmm0, (%rsp)
movsd 0x1078(%rsp), %xmm0
movsd 0x1098(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xcfee3(%rip), %xmm1    # 0x1ff610
addsd %xmm1, %xmm0
callq 0x82f0
movsd (%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x10f0(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x12f7c6
leaq 0x870(%rsp), %rdi
leaq 0xd28e6(%rip), %rsi     # 0x20204f
movb $0x0, %al
callq 0x5b9c0
leaq 0x70(%rsp), %rdi
leaq 0x870(%rsp), %rdx
leaq 0xa2de9(%rip), %rsi     # 0x1d256d
movb $0x0, %al
callq 0x5b9c0
movq 0x10b8(%rsp), %rdi
addq $0x192, %rdi            # imm = 0x192
leaq 0x70(%rsp), %r8
leaq 0xa288e(%rip), %rsi     # 0x1d2034
leaq 0xd28e5(%rip), %rdx     # 0x202092
movl $0x930, %ecx            # imm = 0x930
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x10d4(%rsp)
jmp 0x12f7d3
jmp 0x12f7c8
movl $0x0, 0x10d4(%rsp)
movl 0x10d4(%rsp), %eax
addq $0x10d8, %rsp           # imm = 0x10D8
retq
nopw %cs:(%rax,%rax)