// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/transfer.c
// Function: transfer_interpolate_sources
int transfer_interpolate_sources(
                                 struct perturbations * ppt,
                                 struct transfer * ptr,
                                 double k,
                                 int index_md,
                                 int index_ic,
                                 int index_type,
                                 double * pert_source,       /* array with argument pert_source[index_tau*ppt->k_size[index_md]+index_k] (must be allocated) */
                                 double * pert_source_spline, /* array with argument pert_source_spline[index_tau*ppt->k_size[index_md]+index_k] (must be allocated) */
                                 double * interpolated_sources /* array with argument interpolated_sources[index_tau] (must be allocated) */
                                 ) {

  /** Summary: */

  /** - define local variables */

  /* index running on k values in the original source array */
  int index_k;

  /* index running on time */
  int index_tau;

  /* variables used for spline interpolation algorithm */
  double h, a, b;

  /** - interpolate at each k value using the usual
      spline interpolation algorithm. */

  index_k = 0;
  h = ppt->k[index_md][index_k+1] - ppt->k[index_md][index_k];

  while (((index_k+1) < ppt->k_size[index_md]) &&
         (ppt->k[index_md][index_k+1] < k)) {
    index_k++;
    h = ppt->k[index_md][index_k+1] - ppt->k[index_md][index_k];
  }

  class_test(h==0.,
             ptr->error_message,
             "stop to avoid division by zero");

  b = (k - ppt->k[index_md][index_k])/h;
  a = 1.-b;

  for (index_tau = 0; index_tau < ppt->tau_size; index_tau++) {

    interpolated_sources[index_tau] =
      a * pert_source[index_tau*ppt->k_size[index_md]+index_k]
      + b * pert_source[index_tau*ppt->k_size[index_md]+index_k+1]
      + ((a*a*a-a) * pert_source_spline[index_tau*ppt->k_size[index_md]+index_k]
         +(b*b*b-b) * pert_source_spline[index_tau*ppt->k_size[index_md]+index_k+1])*h*h/6.0;

  }

  return _SUCCESS_;

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movq %rsi, %rbx
movq 0x1028(%rsp), %rcx
movq 0x1020(%rsp), %rsi
movq 0x9c8(%rdi), %r8
movq 0x9d0(%rdi), %rax
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
movslq (%r8,%rdx,4), %rdx
pushq $0x1
popq %r8
cmpq %rdx, %r8
jge 0xa5ddb
movsd (%rax,%r8,8), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xa5ddb
movsd 0x8(%rax,%r8,8), %xmm1
subsd %xmm2, %xmm1
incq %r8
jmp 0xa5dba
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xa5e55
jp 0xa5e55
leaq 0x40f0f(%rip), %rsi     # 0xe6cfd
leaq 0x800(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x3f27b(%rip), %rsi     # 0xe5082
leaq 0x70583(%rip), %rdx     # 0x116391
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x96a, %rbx            # imm = 0x96A
leaq 0x3f208(%rip), %rsi     # 0xe5034
leaq 0x70564(%rip), %rdx     # 0x116397
movq %rbx, %rdi
movl $0x8d9, %ecx            # imm = 0x8D9
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq
subsd -0x8(%rax,%r8,8), %xmm0
divsd %xmm1, %xmm0
movsd 0x3f3f8(%rip), %xmm2    # 0xe5260
subsd %xmm0, %xmm2
movl 0x9f8(%rdi), %edi
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm2, %xmm3
subsd %xmm2, %xmm3
movapd %xmm0, %xmm4
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
subsd %xmm0, %xmm4
xorl %eax, %eax
testl %edi, %edi
cmovlel %eax, %edi
movsd 0x407af(%rip), %xmm5    # 0xe6650
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0xa5e48
movsd (%r9,%r8,8), %xmm6
mulsd %xmm0, %xmm6
movsd -0x8(%r9,%r8,8), %xmm7
mulsd %xmm2, %xmm7
addsd %xmm6, %xmm7
movsd (%rsi,%r8,8), %xmm6
mulsd %xmm4, %xmm6
movsd -0x8(%rsi,%r8,8), %xmm8
mulsd %xmm3, %xmm8
addsd %xmm6, %xmm8
mulsd %xmm1, %xmm8
mulsd %xmm1, %xmm8
divsd %xmm5, %xmm8
addsd %xmm7, %xmm8
movsd %xmm8, (%rcx,%r10,8)
incq %r10
addq %rdx, %r8
jmp 0xa5ea4