// File: /workspace/github_c_makefile_star2_O2/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 0x3adde(%rip), %xmm3    # 0xe5cb0
addsd %xmm0, %xmm3
divsd %xmm1, %xmm3
ucomisd (%r8), %xmm3
ja 0xaaef1
movslq %edi, %rax
movsd -0x8(%r8,%rax,8), %xmm2
ucomisd %xmm3, %xmm2
jbe 0xaaf02
andq $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 0xaaf30
cmpq %rax, %rcx
movq %rdx, %rcx
jl 0xaaf18
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 0x18aef
cmpl $0x1, %eax
jne 0xaafbc
leaq 0x3a475(%rip), %rsi     # 0xe53f0
leaq 0x6c2bc(%rip), %rdx     # 0x11723e
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x3a099(%rip), %rsi     # 0xe5034
leaq 0x6c386(%rip), %rdx     # 0x117328
movq %rbx, %rdi
movl $0xf40, %ecx            # imm = 0xF40
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
jmp 0xaaef7
movsd (%rsp), %xmm4
addsd %xmm4, %xmm4
addsd 0x3a293(%rip), %xmm4    # 0xe5260
movsd 0x3cfc3(%rip), %xmm0    # 0xe7f98
divsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xaafe9
sqrtsd %xmm0, %xmm0
jmp 0xaaff8
movsd %xmm4, (%rsp)
callq 0x82d0
movsd (%rsp), %xmm4
movsd 0x3d7d0(%rip), %xmm1    # 0xe87d0
divsd %xmm4, %xmm1
divsd %xmm4, %xmm1
addsd 0x3a250(%rip), %xmm1    # 0xe5260
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 0x3ac74(%rip), %xmm2    # 0xe5cb0
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 0xaaef5