// File: /workspace/github_c_makefile_star2_O1/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 0xb07c8
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 0x5ed53
cmpl $0x1, %eax
je 0xb07dc
movslq 0x380(%r15), %rax
movsd 0x40b61(%rip), %xmm0    # 0xf1260
divsd (%rbx,%rax,8), %xmm0
addsd 0x410dc(%rip), %xmm0    # 0xf17e8
leaq (%r14,%rbp), %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq (%rsp), %rdx
movl 0x898(%rsp), %ecx
movq %r12, %r8
callq 0xb021a
testl %eax, %eax
jne 0xb0823
movslq 0x384(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
mulsd (%r12), %xmm0
movsd %xmm0, (%r12)
addq $0x8, %rbp
cmpq %rbp, %r13
jne 0xb06c0
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 0x1b465
cmpl $0x1, %eax
jne 0xb0885
leaq 0x40c5c(%rip), %rsi     # 0xf13f0
leaq 0x72403(%rip), %rdx     # 0x122b9e
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x40880(%rip), %rsi     # 0xf1034
leaq 0x7237c(%rip), %rdx     # 0x122b37
movq %r15, %rdi
movl $0xc66, %ecx            # imm = 0xC66
jmp 0xb0864
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r14)
xorl %eax, %eax
jmp 0xb0873
addq $0xd1c, %r15            # imm = 0xD1C
leaq 0x40c06(%rip), %rsi     # 0xf13f0
leaq 0x722fa(%rip), %rdx     # 0x122aeb
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
movq (%rsp), %rdi
addq $0x96a, %rdi            # imm = 0x96A
leaq 0x4081f(%rip), %rsi     # 0xf1034
leaq 0x7231b(%rip), %rdx     # 0x122b37
movl $0xc4b, %ecx            # imm = 0xC4B
jmp 0xb0864
movq (%rsp), %r14
addq $0x96a, %r14            # imm = 0x96A
leaq 0x40bbb(%rip), %rsi     # 0xf13f0
leaq 0x72316(%rip), %rdx     # 0x122b52
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x407df(%rip), %rsi     # 0xf1034
leaq 0x722db(%rip), %rdx     # 0x122b37
movq %r14, %rdi
movl $0xc58, %ecx            # imm = 0xC58
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
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 0xb0894
jmp 0xb0873