// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/transfer.c
// Function: transfer_selection_compute
int transfer_selection_compute(
                               struct precision * ppr,
                               struct background * pba,
                               struct perturbations * ppt,
                               struct transfer * ptr,
                               double * selection,
                               double * tau0_minus_tau,
                               double * w_trapz,
                               int tau_size,
                               double * pvecback,
                               double tau0,
                               int bin) {

  /* running index over time */
  int index_tau;

  /* running value of time */
  double tau;

  /* used for normalizing the selection to one */
  double norm;

  /* used for calling background_at_tau() */
  int last_index;

  /* running value of redshift */
  double z;

  if (tau_size > 1) {

    /* loop over time */
    for (index_tau = 0; index_tau < tau_size; index_tau++) {

      /* running value of time */
      tau = tau0 - tau0_minus_tau[index_tau];

      /* get background quantities at this time */
      class_call(background_at_tau(pba,
                                   tau,
                                   long_info,
                                   inter_normal,
                                   &last_index,
                                   pvecback),
                 pba->error_message,
                 ptr->error_message);

      /* infer redshift (remember that a in the code is in fact a/a_0) */
      z = 1./pvecback[pba->index_bg_a]-1.;

      /* get corresponding dN/dz(z,bin) */
      class_call(transfer_selection_function(ppr,
                                             ppt,
                                             ptr,
                                             bin,
                                             z,
                                             &(selection[index_tau])),
                 ptr->error_message,
                 ptr->error_message);

      /* get corresponding dN/dtau = dN/dz * dz/dtau = dN/dz * H */
      selection[index_tau] *= pvecback[pba->index_bg_H];

    }

    /* compute norm = \int W(tau) dtau */
    class_call(array_trapezoidal_integral(selection,
                                          tau_size,
                                          w_trapz,
                                          &norm,
                                          ptr->error_message),
               ptr->error_message,
               ptr->error_message);


    /* divide W by norm so that \int W(tau) dtau = 1 */
    for (index_tau = 0; index_tau < tau_size; index_tau++) {
      selection[index_tau]/=norm;
    }

  }

  /* trivial case: dirac distribution */
  else {
    selection[0] = 1.;
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movsd %xmm0, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %r8, %r14
movq %rdx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x888(%rsp), %eax
cmpl $0x2, %eax
jl 0xad732
movq %rsi, %r15
movq %rcx, (%rsp)
movq 0x890(%rsp), %rbx
movl %eax, %eax
movq %rax, 0x8(%rsp)
leaq (,%rax,8), %r13
xorl %ebp, %ebp
movsd 0x28(%rsp), %xmm0
movq 0x20(%rsp), %rax
subsd (%rax,%rbp), %xmm0
movq %r15, %rdi
movl $0x2, %esi
xorl %edx, %edx
leaq 0x3c(%rsp), %rcx
movq %rbx, %r8
callq 0x5c63f
cmpl $0x1, %eax
je 0xad746
movslq 0x380(%r15), %rax
movsd 0x40bf7(%rip), %xmm0    # 0xee260
divsd (%rbx,%rax,8), %xmm0
addsd 0x41172(%rip), %xmm0    # 0xee7e8
leaq (%r14,%rbp), %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq (%rsp), %rdx
movl 0x898(%rsp), %ecx
movq %r12, %r8
callq 0xad1b7
testl %eax, %eax
jne 0xad78d
movslq 0x384(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
mulsd (%r12), %xmm0
movsd %xmm0, (%r12)
addq $0x8, %rbp
cmpq %rbp, %r13
jne 0xad62a
movq (%rsp), %r15
addq $0x96a, %r15            # imm = 0x96A
leaq 0x30(%rsp), %rcx
movq %r14, %rdi
movl 0x888(%rsp), %esi
movq 0x880(%rsp), %rdx
movq %r15, %r8
callq 0x1b518
cmpl $0x1, %eax
jne 0xad7ef
leaq 0x40cf2(%rip), %rsi     # 0xee3f0
leaq 0x724d9(%rip), %rdx     # 0x11fbde
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x40916(%rip), %rsi     # 0xee034
leaq 0x72452(%rip), %rdx     # 0x11fb77
movq %r15, %rdi
movl $0xc66, %ecx            # imm = 0xC66
jmp 0xad7ce
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r14)
xorl %eax, %eax
jmp 0xad7dd
addq $0xd1c, %r15            # imm = 0xD1C
leaq 0x40c9c(%rip), %rsi     # 0xee3f0
leaq 0x723d0(%rip), %rdx     # 0x11fb2b
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
movq (%rsp), %rdi
addq $0x96a, %rdi            # imm = 0x96A
leaq 0x408b5(%rip), %rsi     # 0xee034
leaq 0x723f1(%rip), %rdx     # 0x11fb77
movl $0xc4b, %ecx            # imm = 0xC4B
jmp 0xad7ce
movq (%rsp), %r14
addq $0x96a, %r14            # imm = 0x96A
leaq 0x40c51(%rip), %rsi     # 0xee3f0
leaq 0x723ec(%rip), %rdx     # 0x11fb92
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x40875(%rip), %rsi     # 0xee034
leaq 0x723b1(%rip), %rdx     # 0x11fb77
movq %r14, %rdi
movl $0xc58, %ecx            # imm = 0xC58
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x30(%rsp), %xmm0
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
movsd (%r14,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0xad7fe
jmp 0xad7dd