// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../external/heating/injection.c
// Function: injection_deposition_function_at_z
int injection_deposition_function_at_z(struct injection* pin,
                                       double x,
                                       double z){

  /** - Define local variables */
  int index_dep;

  if(z > pin->z_start_chi_approx){
    /** - In the verz early universe, whole energy goes into injection */
    pin->chi[pin->index_dep_heat]  = 1.;
    pin->chi[pin->index_dep_ionH]  = 0.;
    pin->chi[pin->index_dep_ionHe] = 0.;
    pin->chi[pin->index_dep_lya]   = 0.;
    pin->chi[pin->index_dep_lowE]  = 0.;
  }
  else{
    /** - Use the deposition factors for each channel */
    /* Old approximation from Chen and Kamionkowski */
    if(pin->chi_type == chi_CK){
      if(x<1.){
        pin->chi[pin->index_dep_heat]  = (1.+2.*x)/3.;
        pin->chi[pin->index_dep_ionH]  = (1.-x)/3.;
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = (1.-x)/3.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
      else{
        pin->chi[pin->index_dep_heat]  = 1.;
        pin->chi[pin->index_dep_ionH]  = 0.;
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = 0.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
    }
    /* Old approximation from Padmanabhan and Finkbeiner */
    else if(pin->chi_type == chi_PF){
      if(x<1.+pin->fHe){
        pin->chi[pin->index_dep_heat]  = (1.+2.*x/(1+pin->fHe))/3.;
        pin->chi[pin->index_dep_ionH]  = (1.-x/(1+pin->fHe))/3.;
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = (1.-x/(1+pin->fHe))/3.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
      else{
        pin->chi[pin->index_dep_heat]  = 1.;
        pin->chi[pin->index_dep_ionH]  = 0.;
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = 0.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
    }
    /* Coefficient as revised by Galli et al. 2013 */
    else if(pin->chi_type == chi_Galli_file){
      for(index_dep=0; index_dep<pin->dep_size; ++index_dep){
        class_call(array_interpolate_spline_transposed(pin->chix_table,
                                                       pin->chix_size,
                                                       2*pin->dep_size+1,
                                                       0,
                                                       index_dep+1,
                                                       index_dep+pin->dep_size+1,
                                                       x,
                                                       &pin->last_index_x_chi,
                                                       &(pin->chi[index_dep]),
                                                       pin->error_message),
                   pin->error_message,
                   pin->error_message);
      }
    }
    /* coefficient as revised by Vivian Poulin (analytical interpolation of Galli et al. 2013) */
    else if(pin->chi_type == chi_Galli_analytic){
      if(x<1.){
        pin->chi[pin->index_dep_heat]  = MIN(0.996857*(1.-pow(1.-pow(x,0.300134),1.51035)),1);
        pin->chi[pin->index_dep_ionH]  = 0.369202*pow(1.-pow(x,0.463929),1.70237);
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = 0.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
      else{
        pin->chi[pin->index_dep_heat]  = 1.;
        pin->chi[pin->index_dep_ionH]  = 0.;
        pin->chi[pin->index_dep_ionHe] = 0.;
        pin->chi[pin->index_dep_lya]   = 0.;
        pin->chi[pin->index_dep_lowE]  = 0.;
      }
    }
    else if(pin->chi_type == chi_full_heating){
      pin->chi[pin->index_dep_heat]  = 1.;
      pin->chi[pin->index_dep_ionH]  = 0.;
      pin->chi[pin->index_dep_ionHe] = 0.;
      pin->chi[pin->index_dep_lya]   = 0.;
      pin->chi[pin->index_dep_lowE]  = 0.;
    }
    /* Read file in ionization fraction */
    else if(pin->chi_type == chi_from_x_file){
      for(index_dep=0; index_dep<pin->dep_size; ++index_dep){
        class_call(array_interpolate_spline_transposed(pin->chix_table,
                                                       pin->chix_size,
                                                       2*pin->dep_size+1,
                                                       0,
                                                       index_dep+1,
                                                       index_dep+pin->dep_size+1,
                                                       x,
                                                       &pin->last_index_x_chi,
                                                       &(pin->chi[index_dep]),
                                                       pin->error_message),
                   pin->error_message,
                   pin->error_message);
      }
    }
    /* Read file in redshift */
    else if(pin->chi_type == chi_from_z_file){
      for(index_dep=0;index_dep<pin->dep_size;++index_dep){
        class_call(array_interpolate_spline_transposed(pin->chiz_table,
                                                       pin->chiz_size,
                                                       2*pin->dep_size+1,
                                                       0,
                                                       index_dep+1,
                                                       index_dep+pin->dep_size+1,
                                                       z,
                                                       &pin->last_index_z_chi,
                                                       &(pin->chi[index_dep]),
                                                       pin->error_message),
                   pin->error_message,
                   pin->error_message);
      }
    }
    else{
      class_stop(pin->error_message,"No valid deposition function has been found found.");
    }
  }

  /** - Read the correction factor f_eff */
  /* For the on the spot, we take the user input */
  if(pin->f_eff_type == f_eff_on_the_spot){
    // pin->f_eff has already been seet by user
  }
  /* For the file, read in f_eff from file and multiply */
  else if(pin->f_eff_type == f_eff_from_file){
    class_call(array_interpolate_spline_transposed(pin->feff_table,
                                                   pin->feff_z_size,
                                                   3,
                                                   0,
                                                   1,
                                                   2,
                                                   z,
                                                   &(pin->last_index_z_feff),
                                                   &(pin->f_eff),
                                                   pin->error_message),
               pin->error_message,
               pin->error_message);
  }
  /* Otherwise, something must have gone wrong */
  else{
    class_stop(pin->error_message,
               "Unknown energy deposition mechanism");
  }

  /** Multiply deposition factors with overall correction factor */
  for(index_dep=0; index_dep<pin->dep_size; ++index_dep){
    pin->chi[index_dep] *= pin->f_eff;
  }

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1010, %rsp           # imm = 0x1010
movq %rdi, %rbx
movsd %xmm1, 0x8(%rsp)
ucomisd 0x3b8(%rdi), %xmm1
jbe 0xd4a80
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
movslq 0x53c(%rbx), %rcx
xorl %edx, %edx
movq %rdx, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
movq %rdx, (%rax,%rcx,8)
xorpd %xmm4, %xmm4
movslq 0x544(%rbx), %rcx
movsd %xmm4, (%rax,%rcx,8)
movslq 0x548(%rbx), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0xa0(%rbx), %eax
testl %eax, %eax
je 0xd4b0a
cmpl $0x1, %eax
jne 0xd4b45
movq 0x500(%rbx), %rdi
movl 0x4f8(%rbx), %esi
leaq 0x470(%rbx), %rax
leaq 0x4f0(%rbx), %r10
leaq 0x570(%rbx), %r15
subq $0x8, %rsp
movl $0x1, %r14d
movl $0x3, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
movsd 0x10(%rsp), %xmm0
pushq %r15
pushq %r10
pushq %rax
callq 0x17bef
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xd4b0a
leaq 0x1c9ae(%rip), %rsi     # 0xf13f0
leaq 0x57465(%rip), %rdx     # 0x12beae
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1c5d2(%rip), %rsi     # 0xf1034
leaq 0x57325(%rip), %rdx     # 0x12bd8e
movq %r15, %rdi
movl $0x278, %ecx            # imm = 0x278
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
jmp 0xd4fd4
movl 0x1a4(%rbx), %eax
cmpq $0x6, %rax
ja 0xd4e11
leaq 0x56d29(%rip), %rcx     # 0x12b7c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movsd %xmm0, (%rsp)
jmpq *%rax
movsd 0x1c7b3(%rip), %xmm4    # 0xf1260
ucomisd %xmm0, %xmm4
jbe 0xd4975
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
addsd %xmm4, %xmm1
movsd 0x1dbb5(%rip), %xmm2    # 0xf2680
divsd %xmm2, %xmm1
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
subsd %xmm0, %xmm4
divsd %xmm2, %xmm4
movslq 0x53c(%rbx), %rcx
movsd %xmm4, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xd49ad
movslq 0x54c(%rbx), %rax
testq %rax, %rax
jle 0xd4b9c
movq 0x530(%rbx), %rcx
xorl %r14d, %r14d
xorl %edx, %edx
movsd 0x4f0(%rbx), %xmm0
mulsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xd4b26
jmp 0xd4fd4
leaq 0x573f6(%rip), %rsi     # 0x12bf42
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x1ca23(%rip), %rsi     # 0xf1585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
addq $0x570, %rbx            # imm = 0x570
leaq 0x1c4af(%rip), %rsi     # 0xf1034
leaq 0x57202(%rip), %rdx     # 0x12bd8e
movq %rbx, %rdi
movl $0x27d, %ecx            # imm = 0x27D
movq %r15, %r8
jmp 0xd4fc7
xorl %r14d, %r14d
jmp 0xd4fd4
movsd 0x1c6b4(%rip), %xmm1    # 0xf1260
ucomisd %xmm0, %xmm1
jbe 0xd4975
movsd 0x56a32(%rip), %xmm1    # 0x12b5f0
callq 0x8620
movsd 0x1c695(%rip), %xmm2    # 0xf1260
subsd %xmm0, %xmm2
movsd 0x56a21(%rip), %xmm1    # 0x12b5f8
movapd %xmm2, %xmm0
callq 0x8620
movsd 0x1c678(%rip), %xmm2    # 0xf1260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
mulsd 0x56a08(%rip), %xmm1    # 0x12b600
ucomisd %xmm1, %xmm2
movapd %xmm2, %xmm1
jbe 0xd4c45
movsd 0x569e6(%rip), %xmm1    # 0x12b5f0
movsd (%rsp), %xmm0
callq 0x8620
movsd 0x1c644(%rip), %xmm2    # 0xf1260
subsd %xmm0, %xmm2
movsd 0x569d0(%rip), %xmm1    # 0x12b5f8
movapd %xmm2, %xmm0
callq 0x8620
movsd 0x1c627(%rip), %xmm1    # 0xf1260
subsd %xmm0, %xmm1
mulsd 0x569bb(%rip), %xmm1    # 0x12b600
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
movsd 0x569a8(%rip), %xmm1    # 0x12b608
movsd (%rsp), %xmm0
callq 0x8620
movsd 0x1c5ee(%rip), %xmm2    # 0xf1260
subsd %xmm0, %xmm2
movsd 0x56992(%rip), %xmm1    # 0x12b610
movapd %xmm2, %xmm0
callq 0x8620
mulsd 0x56989(%rip), %xmm0    # 0x12b618
movq 0x530(%rbx), %rax
movslq 0x53c(%rbx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xd49a9
movsd 0x418(%rbx), %xmm2
addsd 0x1c59a(%rip), %xmm2    # 0xf1260
ucomisd %xmm0, %xmm2
jbe 0xd4975
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd 0x1c57c(%rip), %xmm4    # 0xf1260
addsd %xmm4, %xmm1
movsd 0x1d990(%rip), %xmm2    # 0xf2680
divsd %xmm2, %xmm1
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
movsd 0x418(%rbx), %xmm1
addsd %xmm4, %xmm1
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
movapd %xmm4, %xmm1
subsd %xmm3, %xmm1
divsd %xmm2, %xmm1
movslq 0x53c(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
movq $0x0, (%rax,%rcx,8)
movsd 0x418(%rbx), %xmm1
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
subsd %xmm0, %xmm4
divsd %xmm2, %xmm4
jmp 0xd49ad
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd49c8
movl %eax, %eax
movq 0x518(%rbx), %rdi
movl 0x520(%rbx), %esi
leal 0x1(,%rax,2), %edx
leaq 0x1(%rcx), %r15
leal (%rcx,%rax), %r9d
incl %r9d
movq 0x530(%rbx), %rax
addq %r13, %rax
subq $0x8, %rsp
xorl %ecx, %ecx
movl %r15d, %r8d
pushq %r14
pushq %rax
pushq %r12
callq 0x17bef
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd4d72
leaq 0x1c613(%rip), %rsi     # 0xf13f0
leaq 0x56ee0(%rip), %rdx     # 0x12bcc4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1c237(%rip), %rsi     # 0xf1034
leaq 0x56f8a(%rip), %rdx     # 0x12bd8e
movq %r14, %rdi
movl $0x224, %ecx            # imm = 0x224
jmp 0xd4fc4
leaq 0x57063(%rip), %rsi     # 0x12be7b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x1c757(%rip), %rsi     # 0xf1585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
addq $0x570, %rbx            # imm = 0x570
leaq 0x1c1e3(%rip), %rsi     # 0xf1034
leaq 0x56f36(%rip), %rdx     # 0x12bd8e
movq %rbx, %rdi
movl $0x262, %ecx            # imm = 0x262
jmp 0xd4b94
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd49c8
movl %eax, %eax
movq 0x518(%rbx), %rdi
movl 0x520(%rbx), %esi
leal 0x1(,%rax,2), %edx
leaq 0x1(%rcx), %r15
leal (%rcx,%rax), %r9d
incl %r9d
movq 0x530(%rbx), %rax
addq %r13, %rax
subq $0x8, %rsp
xorl %ecx, %ecx
movl %r15d, %r8d
pushq %r14
pushq %rax
pushq %r12
callq 0x17bef
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd4e78
leaq 0x1c50d(%rip), %rsi     # 0xf13f0
leaq 0x56dda(%rip), %rdx     # 0x12bcc4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1c131(%rip), %rsi     # 0xf1034
leaq 0x56e84(%rip), %rdx     # 0x12bd8e
movq %r14, %rdi
movl $0x24d, %ecx            # imm = 0x24D
jmp 0xd4fc4
leaq 0x474(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd49c8
movl %eax, %eax
movq 0x508(%rbx), %rdi
movl 0x510(%rbx), %esi
leal 0x1(,%rax,2), %edx
leaq 0x1(%rcx), %r15
leal (%rcx,%rax), %r9d
incl %r9d
movq 0x530(%rbx), %rax
addq %r13, %rax
subq $0x8, %rsp
xorl %ecx, %ecx
movl %r15d, %r8d
movsd 0x10(%rsp), %xmm0
pushq %r14
pushq %rax
pushq %r12
callq 0x17bef
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd4f2a
leaq 0x1c45b(%rip), %rsi     # 0xf13f0
leaq 0x56e15(%rip), %rdx     # 0x12bdb1
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1c07f(%rip), %rsi     # 0xf1034
leaq 0x56dd2(%rip), %rdx     # 0x12bd8e
movq %r14, %rdi
movl $0x25e, %ecx            # imm = 0x25E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %r14d
movl %r14d, %eax
addq $0x1010, %rsp           # imm = 0x1010
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq