// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/transfer.c
// Function: transfer_selection_function
int transfer_selection_function(
                                struct precision * ppr,
                                struct perturbations * ppt,
                                struct transfer * ptr,
                                int bin,
                                double z,
                                double * selection) {

  double x;
  double dNdz;
  double dln_dNdz_dz;
  int last_index;

  /* trivial dirac case */
  if (ppt->selection==dirac) {

    *selection=1.;

    return _SUCCESS_;
  }

  /* difference between z and the bin center (we can take the absolute
     value as long as all selection functions are symmetric around
     x=0) */
  x=fabs(z-ppt->selection_mean[bin]);

  /* gaussian case (the function is anyway normalized later
     automatically, but could not resist to normalize it already
     here) */
  if (ppt->selection==gaussian) {

    *selection = exp(-0.5*pow(x/ppt->selection_width[bin],2))
      /ppt->selection_width[bin]/sqrt(2.*_PI_);

    if ((ptr->has_nz_file == _TRUE_) || (ptr->has_nz_analytic == _TRUE_)) {

      if (ptr->has_nz_file == _TRUE_) {

        class_test((z<ptr->nz_z[0]) || (z>ptr->nz_z[ptr->nz_size-1]),
                   ptr->error_message,
                   "Your input file for the selection function only covers the redshift range [%f : %f]. However, your input for the selection function requires z=%f",
                   ptr->nz_z[0],
                   ptr->nz_z[ptr->nz_size-1],
                   z);

        class_call(array_interpolate_spline(
                                            ptr->nz_z,
                                            ptr->nz_size,
                                            ptr->nz_nz,
                                            ptr->nz_ddnz,
                                            1,
                                            z,
                                            &last_index,
                                            &dNdz,
                                            1,
                                            ptr->error_message),
                   ptr->error_message,
                   ptr->error_message);
      }
      else {

        class_call(transfer_dNdz_analytic(ptr,
                                          z,
                                          &dNdz,
                                          &dln_dNdz_dz),
                   ptr->error_message,
                   ptr->error_message);
      }

      *selection *= dNdz;
    }

    return _SUCCESS_;
  }

  /* top-hat case, with smoothed edges. The problem with sharp edges
     is that the final result will be affected by random
     noise. Indeed, the values of k at which the transfer functions
     Delta_l(k) are sampled will never coincide with the actual edges
     of the true transfer function (computed with or even without the
     Limber approximation). Hence the integral Cl=\int dk
     Delta_l(k)**2 (...) will be imprecise and will fluctuate randomly
     with the resolution along k. With smooth edges, the problem is
     solved, and the final Cls become mildly dependent on the
     resolution along k. */

  if (ppt->selection==tophat) {

    /* selection function, centered on z=mean (i.e. on x=0), equal to
       one around x=0, with tanh step centered on x=width, of width
       delta x = 0.1*width
    */
    *selection=(1.-tanh((x-ppt->selection_width[bin])/(ppr->selection_tophat_edge*ppt->selection_width[bin])))/2.;

    if ((ptr->has_nz_file == _TRUE_) || (ptr->has_nz_analytic == _TRUE_)) {

      if (ptr->has_nz_file == _TRUE_) {

        class_call(array_interpolate_spline(
                                            ptr->nz_z,
                                            ptr->nz_size,
                                            ptr->nz_nz,
                                            ptr->nz_ddnz,
                                            1,
                                            z,
                                            &last_index,
                                            &dNdz,
                                            1,
                                            ptr->error_message),
                   ptr->error_message,
                   ptr->error_message);
      }
      else {

        class_call(transfer_dNdz_analytic(ptr,
                                          z,
                                          &dNdz,
                                          &dln_dNdz_dz),
                   ptr->error_message,
                   ptr->error_message);
      }

      *selection *= dNdz;
    }

    return _SUCCESS_;
  }

  /* get here only if selection type was recognized */
  class_stop(ptr->error_message,
             "invalid choice of selection function");

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1020, %rsp           # imm = 0x1020
movq %r8, %r14
movl 0x68(%rsi), %eax
cmpl $0x2, %eax
jne 0xb0248
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r14)
xorl %ebp, %ebp
jmp 0xb04a1
movapd %xmm0, %xmm2
movq %rdx, %rbx
movq %rsi, %r15
movslq %ecx, %r12
subsd 0x70(%rsi,%r12,8), %xmm0
andpd 0x40fdc(%rip), %xmm0    # 0xf1240
cmpl $0x1, %eax
je 0xb0354
testl %eax, %eax
jne 0xb0443
divsd 0x390(%r15,%r12,8), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x441dd(%rip), %xmm0    # 0xf4468
movsd %xmm2, 0x8(%rsp)
callq 0x8670
movsd 0x8(%rsp), %xmm2
divsd 0x390(%r15,%r12,8), %xmm0
divsd 0x5d7ca(%rip), %xmm0    # 0x10da78
movsd %xmm0, (%r14)
movzwl 0x658(%rbx), %eax
cmpw $0x1, %ax
jne 0xb04b3
movq 0x760(%rbx), %rdi
movsd (%rdi), %xmm0
ucomisd %xmm2, %xmm0
ja 0xb02e8
movslq 0x75c(%rbx), %rsi
ucomisd -0x8(%rdi,%rsi,8), %xmm2
jbe 0xb0543
movsd (%rdi), %xmm0
movslq 0x75c(%rbx), %rax
movsd -0x8(%rdi,%rax,8), %xmm1
leaq 0x72479(%rip), %rsi     # 0x122779
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movb $0x3, %al
callq 0x30c2c
leaq 0x40d69(%rip), %rsi     # 0xf1082
leaq 0x724eb(%rip), %rdx     # 0x12280b
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x96a, %rbx            # imm = 0x96A
leaq 0x40cf4(%rip), %rsi     # 0xf1034
leaq 0x724f6(%rip), %rdx     # 0x12283d
movq %rbx, %rdi
movl $0xa7d, %ecx            # imm = 0xA7D
jmp 0xb0492
movsd 0x390(%r15,%r12,8), %xmm1
subsd %xmm1, %xmm0
mulsd 0x828(%rdi), %xmm1
divsd %xmm1, %xmm0
movsd %xmm2, 0x8(%rsp)
callq 0x80d0
movsd 0x8(%rsp), %xmm2
movsd 0x40ed9(%rip), %xmm1    # 0xf1260
subsd %xmm0, %xmm1
mulsd 0x4193d(%rip), %xmm1    # 0xf1cd0
movsd %xmm1, (%r14)
movzwl 0x658(%rbx), %eax
cmpw $0x1, %ax
jne 0xb04cd
movq 0x760(%rbx), %rdi
movl 0x75c(%rbx), %esi
movq 0x768(%rbx), %rdx
movq 0x770(%rbx), %rcx
addq $0x96a, %rbx            # imm = 0x96A
subq $0x8, %rsp
leaq 0x28(%rsp), %rax
movl $0x1, %ebp
leaq 0x24(%rsp), %r9
movl $0x1, %r8d
movapd %xmm2, %xmm0
pushq %rbx
pushq $0x1
pushq %rax
callq 0x17ee6
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xb05c5
leaq 0x40feb(%rip), %rsi     # 0xf13f0
leaq 0x7244d(%rip), %rdx     # 0x122859
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x40c0c(%rip), %rsi     # 0xf1034
leaq 0x7240e(%rip), %rdx     # 0x12283d
movq %rbx, %rdi
movl $0xac0, %ecx            # imm = 0xAC0
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
jmp 0xb04a1
leaq 0x7248d(%rip), %rsi     # 0x1228d7
leaq 0x820(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x41122(%rip), %rsi     # 0xf1585
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
addq $0x96a, %rbx            # imm = 0x96A
leaq 0x40bb1(%rip), %rsi     # 0xf1034
leaq 0x723b3(%rip), %rdx     # 0x12283d
movq %rbx, %rdi
movl $0xad4, %ecx            # imm = 0xAD4
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %ebp
movl %ebp, %eax
addq $0x1020, %rsp           # imm = 0x1020
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpw $0x1, 0x65a(%rbx)
jne 0xb0241
cmpw $0x1, %ax
je 0xb02c4
jmp 0xb04e5
cmpw $0x1, 0x65a(%rbx)
jne 0xb0241
cmpw $0x1, %ax
je 0xb03a9
divsd 0x70e23(%rip), %xmm2    # 0x121310
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x43aaf(%rip), %xmm1    # 0xf3fb8
movapd %xmm2, %xmm0
callq 0x8620
xorpd 0x40d16(%rip), %xmm0    # 0xf1230
callq 0x8670
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x43a7f(%rip), %xmm1    # 0xf3fb8
callq 0x8620
jmp 0xb05c5
movq 0x768(%rbx), %rdx
movq 0x770(%rbx), %rcx
addq $0x96a, %rbx            # imm = 0x96A
subq $0x8, %rsp
leaq 0x28(%rsp), %rax
movl $0x1, %ebp
leaq 0x24(%rsp), %r9
movl $0x1, %r8d
movapd %xmm2, %xmm0
pushq %rbx
pushq $0x1
pushq %rax
callq 0x17ee6
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xb05c5
leaq 0x40e62(%rip), %rsi     # 0xf13f0
leaq 0x722c4(%rip), %rdx     # 0x122859
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x40a83(%rip), %rsi     # 0xf1034
leaq 0x72285(%rip), %rdx     # 0x12283d
movq %rbx, %rdi
movl $0xa8b, %ecx            # imm = 0xA8B
jmp 0xb0437
movsd 0x20(%rsp), %xmm0
mulsd (%r14), %xmm0
movsd %xmm0, (%r14)
jmp 0xb0241