// File: /workspace/github_c_makefile_star2_O1/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 0x3e549(%rip), %xmm3    # 0xf1cd0
addsd %xmm0, %xmm3
divsd %xmm1, %xmm3
ucomisd (%r8), %xmm3
ja 0xb37a6
movslq %edi, %rax
movsd -0x8(%r8,%rax,8), %xmm2
ucomisd %xmm3, %xmm2
jbe 0xb37ba
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 0xb37e8
cmpq %rax, %rcx
movq %rdx, %rcx
jl 0xb37d0
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 0x1abd0
cmpl $0x1, %eax
jne 0xb3876
leaq 0x3dbbd(%rip), %rsi     # 0xf13f0
leaq 0x6fb34(%rip), %rdx     # 0x12336e
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x3d7e1(%rip), %rsi     # 0xf1034
leaq 0x6fbfe(%rip), %rdx     # 0x123458
movq %rbx, %rdi
movl $0xf40, %ecx            # imm = 0xF40
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
jmp 0xb37af
movsd (%rsp), %xmm4
addsd %xmm4, %xmm4
addsd 0x3d9d9(%rip), %xmm4    # 0xf1260
movsd 0x40739(%rip), %xmm0    # 0xf3fc8
divsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xb38a3
sqrtsd %xmm0, %xmm0
jmp 0xb38b2
movsd %xmm4, (%rsp)
callq 0x82b0
movsd (%rsp), %xmm4
movsd 0x40f86(%rip), %xmm1    # 0xf4840
divsd %xmm4, %xmm1
divsd %xmm4, %xmm1
addsd 0x3d996(%rip), %xmm1    # 0xf1260
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 0x3e3da(%rip), %xmm2    # 0xf1cd0
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 0xb37ad