// File: /workspace/github_c_makefile_star2_O3/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 0x9d0(%rdi), %rax
movslq %edx, %rcx
movq (%rax,%rcx,8), %rdx
movsd 0x8(%rdx), %xmm1
subsd (%rdx), %xmm1
movq 0x9c8(%rdi), %rax
movslq (%rax,%rcx,4), %rcx
xorl %eax, %eax
cmpq $0x2, %rcx
jl 0xab3f4
movsd 0x8(%rdx), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xab3f4
leal -0x1(%rcx), %eax
leaq -0x1(%rax), %r8
xorl %esi, %esi
movapd %xmm2, %xmm3
cmpq %rsi, %r8
je 0xab3ea
movsd 0x10(%rdx,%rsi,8), %xmm2
incq %rsi
ucomisd %xmm2, %xmm0
ja 0xab3c4
movsd 0x8(%rdx,%rsi,8), %xmm1
subsd %xmm3, %xmm1
movl %esi, %eax
jmp 0xab3f4
movsd 0x10(%rdx,%rsi,8), %xmm1
subsd %xmm3, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xab468
jp 0xab468
leaq 0x44936(%rip), %rsi     # 0xefd3d
leaq 0x800(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x42c62(%rip), %rsi     # 0xee082
leaq 0x740da(%rip), %rdx     # 0x11f501
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x96a, %rbx            # imm = 0x96A
leaq 0x42bef(%rip), %rsi     # 0xee034
leaq 0x740bb(%rip), %rdx     # 0x11f507
movq %rbx, %rdi
movl $0x8d9, %ecx            # imm = 0x8D9
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
jmp 0xab531
movslq 0x9f8(%rdi), %rsi
testq %rsi, %rsi
jle 0xab52f
movq 0x1028(%rsp), %rdi
movq 0x1020(%rsp), %r8
movl %eax, %r10d
subsd (%rdx,%r10,8), %xmm0
divsd %xmm1, %xmm0
movsd 0x42dc3(%rip), %xmm2    # 0xee260
subsd %xmm0, %xmm2
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm2, %xmm3
subsd %xmm2, %xmm3
movapd %xmm0, %xmm4
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
subsd %xmm0, %xmm4
movslq %eax, %rdx
incq %rdx
xorl %eax, %eax
movsd 0x4419f(%rip), %xmm5    # 0xef670
xorl %r10d, %r10d
movsd (%r9,%rdx,8), %xmm6
movsd (%r8,%rdx,8), %xmm7
mulsd %xmm4, %xmm7
movsd -0x8(%r8,%rdx,8), %xmm8
mulsd %xmm3, %xmm8
mulsd %xmm0, %xmm6
addsd %xmm7, %xmm8
movsd -0x8(%r9,%rdx,8), %xmm7
mulsd %xmm2, %xmm7
addsd %xmm6, %xmm7
mulsd %xmm1, %xmm8
mulsd %xmm1, %xmm8
divsd %xmm5, %xmm8
addsd %xmm7, %xmm8
movsd %xmm8, (%rdi,%r10,8)
incq %r10
addq %rcx, %rdx
cmpq %r10, %rsi
jne 0xab4d4
jmp 0xab531
xorl %eax, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq