// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/fourier.c
// Function: fourier_pks_at_kvec_and_zvec
int fourier_pks_at_kvec_and_zvec(
                                 struct background * pba,
                                 struct fourier * pfo,
                                 enum pk_outputs pk_output,
                                 double * kvec, // kvec[index_kvec]
                                 int kvec_size,
                                 double * zvec, // zvec[index_zvec]
                                 int zvec_size,
                                 double * out_pk,   // output_pk[index_zvec*kvec_size+index_kvec],
                                                    // already allocated
                                                    //(or NULL if user knows there is no _m output)
                                 double * out_pk_cb // output_pk[index_zvec*kvec_size+index_kvec],
                                                    //already allocated
                                                    //(or NULL if user knows there is no _cb output)
                                 ) {

  /** Summary: */

  /** - define local variables */

  int index_k, index_kvec, index_zvec;
  double * ln_kvec;
  double * ln_pk_table = NULL;
  double * ddln_pk_table = NULL;
  double * ln_pk_cb_table = NULL;
  double * ddln_pk_cb_table = NULL;
  double h, a, b;

  /** - Allocate arrays */

  class_alloc(ln_kvec, sizeof(double)*kvec_size,
              pfo->error_message);

  if (pfo->has_pk_m == _TRUE_) {
    class_alloc(ln_pk_table, sizeof(double)*pfo->k_size*zvec_size,
                pfo->error_message);
    class_alloc(ddln_pk_table, sizeof(double)*pfo->k_size*zvec_size,
                pfo->error_message);
  }
  if (pfo->has_pk_cb == _TRUE_) {
    class_alloc(ln_pk_cb_table, sizeof(double)*pfo->k_size*zvec_size,
                pfo->error_message);
    class_alloc(ddln_pk_cb_table, sizeof(double)*pfo->k_size*zvec_size,
                pfo->error_message);
  }

  /** - Construct table of log(P(k_n,z_j)) for pre-computed wavenumbers but requested redshifts: */

  for (index_zvec=0; index_zvec<zvec_size; index_zvec++){

    if (pfo->has_pk_m == _TRUE_) {
      class_call(fourier_pk_at_z(pba,
                                 pfo,
                                 logarithmic,
                                 pk_output,
                                 zvec[index_zvec],
                                 pfo->index_pk_m,
                                 &(ln_pk_table[index_zvec * pfo->k_size]),
                                 NULL),
                 pfo->error_message,
                 pfo->error_message);
    }
    if (pfo->has_pk_cb == _TRUE_) {
      class_call(fourier_pk_at_z(pba,
                                 pfo,
                                 logarithmic,
                                 pk_output,
                                 zvec[index_zvec],
                                 pfo->index_pk_cb,
                                 &(ln_pk_cb_table[index_zvec * pfo->k_size]),
                                 NULL),
                 pfo->error_message,
                 pfo->error_message);
    }
  }

  /** - Spline it for interpolation along k */

  if (pfo->has_pk_m == _TRUE_) {

    class_call(array_spline_table_columns2(pfo->ln_k,
                                           pfo->k_size,
                                           ln_pk_table,
                                           zvec_size,
                                           ddln_pk_table,
                                           _SPLINE_NATURAL_,
                                           pfo->error_message),
               pfo->error_message,
               pfo->error_message);
  }
  if (pfo->has_pk_cb == _TRUE_) {

    class_call(array_spline_table_columns2(pfo->ln_k,
                                           pfo->k_size,
                                           ln_pk_cb_table,
                                           zvec_size,
                                           ddln_pk_cb_table,
                                           _SPLINE_NATURAL_,
                                           pfo->error_message),
               pfo->error_message,
               pfo->error_message);
  }

  /** - Construct ln(kvec): */

  for (index_kvec=0; index_kvec<kvec_size; index_kvec++)
    ln_kvec[index_kvec] = log(kvec[index_kvec]);

  /** - Loop over first k values. If k<kmin, fill output with zeros. If not, go to next step. */

  for (index_kvec = 0; index_kvec<kvec_size; index_kvec++){

    /* check whether one should go to next step */
    if (ln_kvec[index_kvec] >= pfo->ln_k[0])
      break;

    /* deal with k<k_min */
    for (index_zvec = 0; index_zvec < zvec_size; index_zvec++) {
      if (pfo->has_pk_m == _TRUE_)     out_pk[index_zvec*kvec_size+index_kvec] = 0.;
      if (pfo->has_pk_cb == _TRUE_) out_pk_cb[index_zvec*kvec_size+index_kvec] = 0.;
      /* (If needed, one could add instead some extrapolation here) */
    }
  }

  /** - Deal with case kmin<=k<=kmax. For better performance, do not
      loop through kvec, but through pre-computed k values. */

  for (index_k=0; index_k < (pfo->k_size-1); index_k++){

    /** --> Loop through k_i's that fall in interval [k_n,k_n+1] */

    while ((index_kvec < kvec_size) && (ln_kvec[index_kvec] <= pfo->ln_k[index_k+1])){

      /** --> for each of them, perform spine interpolation */

      h = pfo->ln_k[index_k+1]-pfo->ln_k[index_k];
      b = (ln_kvec[index_kvec] - pfo->ln_k[index_k])/h;
      a = 1.-b;

      for (index_zvec = 0; index_zvec < zvec_size; index_zvec++) {

        if (pfo->has_pk_m == _TRUE_) {

          out_pk[index_zvec*kvec_size+index_kvec] =
            exp(
                array_spline_eval(ln_pk_table,
                                  ddln_pk_table,
                                  (index_zvec * pfo->k_size + index_k),
                                  (index_zvec * pfo->k_size + index_k+1),
                                  h,a,b)
                );
        }
        if (pfo->has_pk_cb == _TRUE_) {

          out_pk_cb[index_zvec*kvec_size+index_kvec] =
            exp(
                array_spline_eval(ln_pk_cb_table,
                                  ddln_pk_cb_table,
                                  (index_zvec * pfo->k_size + index_k),
                                  (index_zvec * pfo->k_size + index_k+1),
                                  h,a,b)
                );
        }
      }
      index_kvec++;
    }
  }

  /** - Loop over possible remaining k values with k > kmax, to fill output with zeros. */

  while (index_kvec < kvec_size) {

    for (index_zvec = 0; index_zvec < zvec_size; index_zvec++) {
      if (pfo->has_pk_m == _TRUE_)     out_pk[index_zvec*kvec_size+index_kvec] = 0.;
      if (pfo->has_pk_cb == _TRUE_) out_pk_cb[index_zvec*kvec_size+index_kvec] = 0.;
      /* (If needed, one could add instead some extrapolation here) */
    }
    index_kvec++;
  }

  free(ln_kvec);
  if (pfo->has_pk_m == _TRUE_) {
    free(ln_pk_table);
    free(ddln_pk_table);
  }
  if (pfo->has_pk_cb == _TRUE_) {
    free(ln_pk_cb_table);
    free(ddln_pk_cb_table);
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x898, %rsp            # imm = 0x898
movq %r9, %r15
movq %rcx, %r14
movl %edx, 0x28(%rsp)
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
movl %r8d, 0x34(%rsp)
movslq %r8d, %rax
movq %rax, 0x68(%rsp)
leaq (,%rax,8), %r13
movq %r13, %rdi
callq 0x8490
pushq $0x1
popq %rbp
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x99adb
movq %r15, 0x58(%rsp)
movq %r14, 0x50(%rsp)
movl 0x8d0(%rsp), %r12d
cmpw $0x1, 0x50(%rbx)
movslq %r12d, %r15
jne 0x99b23
movq %r13, %r12
movslq 0x6c(%rbx), %r14
movq %r14, %r13
imulq %r15, %r13
shlq $0x3, %r13
movq %r13, %rdi
callq 0x8490
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x99cc7
movq %r13, %rdi
callq 0x8490
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x99f0d
movq %r12, %r13
movl 0x8d0(%rsp), %r12d
jmp 0x99b35
leaq 0x4b522(%rip), %rsi     # 0xe5004
leaq 0x79424(%rip), %rdx     # 0x112f0d
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b528(%rip), %rsi     # 0xe5034
leaq 0x79402(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x353, %ecx            # imm = 0x353
movq %r15, %r8
jmp 0x99fa8
movq $0x0, 0x48(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r14d, %r14d
cmpw $0x1, 0x52(%rbx)
jne 0x99b81
movslq 0x6c(%rbx), %r12
imulq %r12, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8490
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x99e33
movq %r15, %rdi
callq 0x8490
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x99f5a
movl 0x8d0(%rsp), %r12d
jmp 0x99b93
movq $0x0, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
testl %r12d, %r12d
movl $0x0, %eax
cmovgl %r12d, %eax
movq %rax, 0x60(%rsp)
pushq $0x1
popq %rbp
movq 0x58(%rsp), %r15
movzwl 0x50(%rbx), %eax
cmpq %r14, 0x60(%rsp)
je 0x99c4c
cmpw $0x1, %ax
jne 0x99bff
movsd (%r15,%r14,8), %xmm0
movl 0x54(%rbx), %r8d
movslq 0x6c(%rbx), %rax
movslq %r14d, %rcx
imulq %rax, %rcx
movq 0x18(%rsp), %rax
leaq (%rax,%rcx,8), %r9
andq $0x0, (%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl 0x28(%rsp), %ecx
callq 0x98198
testl %eax, %eax
jne 0x99e83
cmpw $0x1, 0x52(%rbx)
jne 0x99c44
movsd (%r15,%r14,8), %xmm0
movl 0x58(%rbx), %r8d
movslq 0x6c(%rbx), %rax
movslq %r14d, %rcx
imulq %rax, %rcx
movq 0x10(%rsp), %rax
leaq (%rax,%rcx,8), %r9
andq $0x0, (%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl 0x28(%rsp), %ecx
callq 0x98198
testl %eax, %eax
jne 0x99ec8
incq %r14
jmp 0x99bac
cmpw $0x1, %ax
jne 0x99d17
movq 0x80(%rbx), %rdi
movl 0x6c(%rbx), %esi
leaq 0x192(%rbx), %r14
movq %r14, (%rsp)
movq 0x18(%rsp), %rdx
movl %r12d, %ecx
movq 0x48(%rsp), %r8
xorl %r9d, %r9d
callq 0x141fa
cmpl $0x1, %eax
jne 0x99d17
leaq 0x4b760(%rip), %rsi     # 0xe53f0
leaq 0x793d4(%rip), %rdx     # 0x11306b
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4b381(%rip), %rsi     # 0xe5034
leaq 0x7925b(%rip), %rdx     # 0x112f15
movq %r14, %rdi
movl $0x38c, %ecx            # imm = 0x38C
jmp 0x99d86
movl 0x8d0(%rsp), %ecx
imull %r14d, %ecx
shll $0x3, %ecx
leaq 0x4b328(%rip), %rsi     # 0xe5004
leaq 0x79251(%rip), %rdx     # 0x112f34
leaq 0x90(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b331(%rip), %rsi     # 0xe5034
leaq 0x7920b(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x357, %ecx            # imm = 0x357
jmp 0x99fa5
cmpw $0x1, 0x52(%rbx)
jne 0x99d8e
movq 0x80(%rbx), %rdi
movl 0x6c(%rbx), %esi
leaq 0x192(%rbx), %r14
movq %r14, (%rsp)
movq 0x10(%rsp), %rdx
movl %r12d, %ecx
movq 0x40(%rsp), %r8
xorl %r9d, %r9d
callq 0x141fa
cmpl $0x1, %eax
jne 0x99d8e
leaq 0x4b69c(%rip), %rsi     # 0xe53f0
leaq 0x79382(%rip), %rdx     # 0x1130dd
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4b2bd(%rip), %rsi     # 0xe5034
leaq 0x79197(%rip), %rdx     # 0x112f15
movq %r14, %rdi
movl $0x398, %ecx            # imm = 0x398
movq %rbx, %r8
jmp 0x99fa8
xorl %r14d, %r14d
movl 0x34(%rsp), %eax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
movq 0x50(%rsp), %r12
cmpq %r14, %r15
je 0x99dc6
movsd (%r12,%r14,8), %xmm0
callq 0x82e0
movq 0x38(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
jmp 0x99da6
xorl %eax, %eax
movq 0x8e0(%rsp), %rcx
movq 0x8d8(%rsp), %rdx
cmpq %r15, %rax
je 0x99fc3
movq 0x38(%rsp), %rsi
movsd (%rsi,%rax,8), %xmm0
movq 0x80(%rbx), %rsi
ucomisd (%rsi), %xmm0
jae 0x99fc8
xorl %esi, %esi
movq 0x60(%rsp), %rdi
subq $0x1, %rdi
jb 0x99e26
cmpw $0x1, 0x50(%rbx)
jne 0x99e15
andq $0x0, (%rdx,%rsi)
cmpw $0x1, 0x52(%rbx)
jne 0x99e21
andq $0x0, (%rcx,%rsi)
addq %r13, %rsi
jmp 0x99e03
incq %rax
addq $0x8, %rdx
addq $0x8, %rcx
jmp 0x99dd8
movl 0x8d0(%rsp), %ecx
imull %r12d, %ecx
shll $0x3, %ecx
leaq 0x4b1bc(%rip), %rsi     # 0xe5004
leaq 0x790f3(%rip), %rdx     # 0x112f42
leaq 0x90(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b1c5(%rip), %rsi     # 0xe5034
leaq 0x7909f(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x35d, %ecx            # imm = 0x35D
jmp 0x99fa5
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b55f(%rip), %rsi     # 0xe53f0
leaq 0x790b9(%rip), %rdx     # 0x112f51
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4b180(%rip), %rsi     # 0xe5034
leaq 0x7905a(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x370, %ecx            # imm = 0x370
jmp 0x99fa5
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b51a(%rip), %rsi     # 0xe53f0
leaq 0x790ff(%rip), %rdx     # 0x112fdc
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4b13b(%rip), %rsi     # 0xe5034
leaq 0x79015(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x37c, %ecx            # imm = 0x37C
jmp 0x99fa5
movl 0x8d0(%rsp), %ecx
imull %r14d, %ecx
shll $0x3, %ecx
leaq 0x4b0e2(%rip), %rsi     # 0xe5004
leaq 0x79009(%rip), %rdx     # 0x112f32
leaq 0x90(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b0eb(%rip), %rsi     # 0xe5034
leaq 0x78fc5(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x359, %ecx            # imm = 0x359
jmp 0x99fa5
movl 0x8d0(%rsp), %ecx
imull %r12d, %ecx
shll $0x3, %ecx
leaq 0x4b095(%rip), %rsi     # 0xe5004
leaq 0x78fca(%rip), %rdx     # 0x112f40
leaq 0x90(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x192, %rbx            # imm = 0x192
leaq 0x4b09e(%rip), %rsi     # 0xe5034
leaq 0x78f78(%rip), %rdx     # 0x112f15
movq %rbx, %rdi
movl $0x35f, %ecx            # imm = 0x35F
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
movl %ebp, %eax
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r14
jmp 0x99fce
movq %r13, %r14
movl %eax, %r15d
xorl %r13d, %r13d
movslq 0x6c(%rbx), %rax
decq %rax
movslq %r15d, %r15
cmpq %rax, %r13
jge 0x9a1ec
movl 0x34(%rsp), %eax
cmpl %eax, %r15d
cmovgl %r15d, %eax
movq %rax, 0x80(%rsp)
movq 0x8d8(%rsp), %rax
leaq (%rax,%r15,8), %rax
movq %rax, 0x70(%rsp)
movq 0x8e0(%rsp), %rax
leaq (%rax,%r15,8), %rbp
cmpq 0x68(%rsp), %r15
jge 0x9a1da
movq 0x38(%rsp), %rax
movsd (%rax,%r15,8), %xmm1
movq 0x80(%rbx), %rax
movsd 0x8(%rax,%r13,8), %xmm3
ucomisd %xmm1, %xmm3
jb 0x9a1e4
movq %r15, 0x88(%rsp)
movsd (%rax,%r13,8), %xmm0
subsd %xmm0, %xmm3
subsd %xmm0, %xmm1
divsd %xmm3, %xmm1
movsd 0x4b1fc(%rip), %xmm0    # 0xe5260
subsd %xmm1, %xmm0
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm0, 0x58(%rsp)
subsd %xmm0, %xmm2
movsd %xmm2, 0x50(%rsp)
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movsd %xmm1, 0x28(%rsp)
movsd %xmm3, 0x20(%rsp)
cmpq %r12, 0x60(%rsp)
je 0x9a1c0
cmpw $0x1, 0x50(%rbx)
jne 0x9a138
movl 0x6c(%rbx), %eax
imull %r12d, %eax
addl %r13d, %eax
cltq
movq 0x18(%rsp), %rcx
movsd 0x8(%rcx,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd (%rcx,%rax,8), %xmm1
mulsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movq 0x48(%rsp), %rcx
movsd 0x8(%rcx,%rax,8), %xmm2
mulsd 0x78(%rsp), %xmm2
movsd (%rcx,%rax,8), %xmm0
mulsd 0x50(%rsp), %xmm0
addsd %xmm2, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
divsd 0x4c538(%rip), %xmm0    # 0xe6650
addsd %xmm1, %xmm0
callq 0x86a0
movsd 0x20(%rsp), %xmm3
movsd 0x28(%rsp), %xmm1
movq 0x70(%rsp), %rax
movsd %xmm0, (%rax,%r15)
cmpw $0x1, 0x52(%rbx)
jne 0x9a1b5
movl 0x6c(%rbx), %eax
imull %r12d, %eax
addl %r13d, %eax
cltq
movq 0x10(%rsp), %rcx
movsd 0x8(%rcx,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd (%rcx,%rax,8), %xmm1
mulsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movq 0x40(%rsp), %rcx
movsd 0x8(%rcx,%rax,8), %xmm2
mulsd 0x78(%rsp), %xmm2
movsd (%rcx,%rax,8), %xmm0
mulsd 0x50(%rsp), %xmm0
addsd %xmm2, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
divsd 0x4c4b7(%rip), %xmm0    # 0xe6650
addsd %xmm1, %xmm0
callq 0x86a0
movsd 0x20(%rsp), %xmm3
movsd 0x28(%rsp), %xmm1
movsd %xmm0, (%rbp,%r15)
incq %r12
addq %r14, %r15
jmp 0x9a0ac
movq 0x88(%rsp), %r15
incq %r15
addq $0x8, 0x70(%rsp)
addq $0x8, %rbp
jmp 0x9a014
movq 0x80(%rsp), %r15
jmp 0x9a1e4
incq %r13
jmp 0x99fd1
movq 0x8d8(%rsp), %rax
leaq (%rax,%r15,8), %rax
movq 0x8e0(%rsp), %rcx
leaq (%rcx,%r15,8), %rcx
cmpq 0x68(%rsp), %r15
jge 0x9a242
xorl %edx, %edx
movq 0x60(%rsp), %rsi
subq $0x1, %rsi
jb 0x9a235
cmpw $0x1, 0x50(%rbx)
jne 0x9a224
andq $0x0, (%rax,%rdx)
cmpw $0x1, 0x52(%rbx)
jne 0x9a230
andq $0x0, (%rcx,%rdx)
addq %r14, %rdx
jmp 0x9a212
incq %r15
addq $0x8, %rax
addq $0x8, %rcx
jmp 0x9a204
movq 0x38(%rsp), %rdi
callq 0x8430
cmpw $0x1, 0x50(%rbx)
jne 0x9a267
movq 0x18(%rsp), %rdi
callq 0x8430
movq 0x48(%rsp), %rdi
callq 0x8430
xorl %ebp, %ebp
cmpw $0x1, 0x52(%rbx)
jne 0x99faf
movq 0x10(%rsp), %rdi
callq 0x8430
movq 0x40(%rsp), %rdi
callq 0x8430
jmp 0x99faf