// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/transfer.c
// Function: transfer_limber2
int transfer_limber2(
                     int tau_size,
                     struct transfer * ptr,
                     int index_md,
                     int index_k,
                     double l,
                     double k,
                     double * tau0_minus_tau,
                     double * sources,
                     radial_function_type radial_type,
                     double * trsf
                     ){

  /** Summary: */

  /** - define local variables */

  /* conformal time at which source must be computed */
  double tau0_minus_tau_limber;
  int index_tau;

  /* interpolated source and its derivatives */
  double S, dS, ddS;

  /** - get k, l and infer tau such that k(tau0-tau)=l+1/2;
      check that tau is in appropriate range */

  tau0_minus_tau_limber = (l+0.5)/k;  //TBC: to be updated to include curvature effects

  if ((tau0_minus_tau_limber > tau0_minus_tau[0]) ||
      (tau0_minus_tau_limber < tau0_minus_tau[tau_size-1])) {
    *trsf = 0.;
    return _SUCCESS_;
  }

  /** - find  bracketing indices */
  index_tau=0;
  while ((tau0_minus_tau[index_tau] > tau0_minus_tau_limber) && (index_tau<tau_size-2))
    index_tau++;

  /** - interpolate by fitting a polynomial of order two; get source
      and its first two derivatives */
  class_call(array_interpolate_parabola(tau0_minus_tau[index_tau-1],
                                        tau0_minus_tau[index_tau],
                                        tau0_minus_tau[index_tau+1],
                                        tau0_minus_tau_limber,
                                        sources[index_tau-1],
                                        sources[index_tau],
                                        sources[index_tau+1],
                                        &S,
                                        &dS,
                                        &ddS,
                                        ptr->error_message),
             ptr->error_message,
             ptr->error_message);


  /** - get transfer from 2nd order Limber approx (inferred from 0809.5112 [astro-ph]) */

  *trsf = sqrt(_PI_/(2.*l+1.))/k*((1.-3./2./(2.*l+1.)/(2.*l+1.))*S+dS/k/(2.*l+1.)-0.5*ddS/k/k);

  return _SUCCESS_;

}

// Assembly:
pushq %r14
pushq %rbx
subq $0x838, %rsp            # imm = 0x838
movq 0x858(%rsp), %r14
movsd 0x3e5c5(%rip), %xmm3    # 0xeecd0
addsd %xmm0, %xmm3
divsd %xmm1, %xmm3
ucomisd (%r8), %xmm3
ja 0xb072a
movslq %edi, %rax
movsd -0x8(%r8,%rax,8), %xmm2
ucomisd %xmm3, %xmm2
jbe 0xb073e
movq $0x0, (%r14)
xorl %eax, %eax
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r14
retq
movq %rsi, %rbx
movsd %xmm0, (%rsp)
movapd %xmm1, 0x20(%rsp)
addl $-0x2, %edi
movslq %edi, %rax
xorl %ecx, %ecx
movsd (%r8,%rcx,8), %xmm1
leaq 0x1(%rcx), %rdx
ucomisd %xmm3, %xmm1
jbe 0xb076c
cmpq %rax, %rcx
movq %rdx, %rcx
jl 0xb0754
movsd -0x10(%r8,%rdx,8), %xmm0
movsd (%r8,%rdx,8), %xmm2
movsd -0x10(%r9,%rdx,8), %xmm4
movsd -0x8(%r9,%rdx,8), %xmm5
movsd (%r9,%rdx,8), %xmm6
addq $0x96a, %rbx            # imm = 0x96A
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0x1acc8
cmpl $0x1, %eax
jne 0xb07fa
leaq 0x3dc39(%rip), %rsi     # 0xee3f0
leaq 0x6fbf0(%rip), %rdx     # 0x1203ae
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3d85d(%rip), %rsi     # 0xee034
leaq 0x6fcba(%rip), %rdx     # 0x120498
movq %rbx, %rdi
movl $0xf40, %ecx            # imm = 0xF40
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
jmp 0xb0733
movsd (%rsp), %xmm4
addsd %xmm4, %xmm4
addsd 0x3da55(%rip), %xmm4    # 0xee260
movsd 0x407c5(%rip), %xmm0    # 0xf0fd8
divsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xb0827
sqrtsd %xmm0, %xmm0
jmp 0xb0836
movsd %xmm4, (%rsp)
callq 0x82b0
movsd (%rsp), %xmm4
movsd 0x41012(%rip), %xmm1    # 0xf1850
divsd %xmm4, %xmm1
divsd %xmm4, %xmm1
addsd 0x3da12(%rip), %xmm1    # 0xee260
movsd 0x10(%rsp), %xmm2
movapd 0x20(%rsp), %xmm3
divsd %xmm3, %xmm2
divsd %xmm4, %xmm2
mulsd 0x18(%rsp), %xmm1
addsd %xmm2, %xmm1
movsd 0x8(%rsp), %xmm2
mulsd 0x3e456(%rip), %xmm2    # 0xeecd0
divsd %xmm3, %xmm2
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
subsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r14)
jmp 0xb0731