// File: /workspace/github_c_makefile_star2_O3/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 0xd1272
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 0xd12fc
cmpl $0x1, %eax
jne 0xd1337
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 0x17d7a
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xd12fc
leaq 0x1d1bc(%rip), %rsi     # 0xee3f0
leaq 0x57ca3(%rip), %rdx     # 0x128ede
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1cde0(%rip), %rsi     # 0xee034
leaq 0x57b63(%rip), %rdx     # 0x128dbe
movq %r15, %rdi
movl $0x278, %ecx            # imm = 0x278
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
jmp 0xd17c6
movl 0x1a4(%rbx), %eax
cmpq $0x6, %rax
ja 0xd1603
leaq 0x57567(%rip), %rcx     # 0x1287f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movsd %xmm0, (%rsp)
jmpq *%rax
movsd 0x1cfc1(%rip), %xmm4    # 0xee260
ucomisd %xmm0, %xmm4
jbe 0xd1167
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
addsd %xmm4, %xmm1
movsd 0x1e3c3(%rip), %xmm2    # 0xef680
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 0xd119f
movslq 0x54c(%rbx), %rax
testq %rax, %rax
jle 0xd138e
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 0xd1318
jmp 0xd17c6
leaq 0x57c34(%rip), %rsi     # 0x128f72
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x1d231(%rip), %rsi     # 0xee585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
addq $0x570, %rbx            # imm = 0x570
leaq 0x1ccbd(%rip), %rsi     # 0xee034
leaq 0x57a40(%rip), %rdx     # 0x128dbe
movq %rbx, %rdi
movl $0x27d, %ecx            # imm = 0x27D
movq %r15, %r8
jmp 0xd17b9
xorl %r14d, %r14d
jmp 0xd17c6
movsd 0x1cec2(%rip), %xmm1    # 0xee260
ucomisd %xmm0, %xmm1
jbe 0xd1167
movsd 0x57270(%rip), %xmm1    # 0x128620
callq 0x8620
movsd 0x1cea3(%rip), %xmm2    # 0xee260
subsd %xmm0, %xmm2
movsd 0x5725f(%rip), %xmm1    # 0x128628
movapd %xmm2, %xmm0
callq 0x8620
movsd 0x1ce86(%rip), %xmm2    # 0xee260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
mulsd 0x57246(%rip), %xmm1    # 0x128630
ucomisd %xmm1, %xmm2
movapd %xmm2, %xmm1
jbe 0xd1437
movsd 0x57224(%rip), %xmm1    # 0x128620
movsd (%rsp), %xmm0
callq 0x8620
movsd 0x1ce52(%rip), %xmm2    # 0xee260
subsd %xmm0, %xmm2
movsd 0x5720e(%rip), %xmm1    # 0x128628
movapd %xmm2, %xmm0
callq 0x8620
movsd 0x1ce35(%rip), %xmm1    # 0xee260
subsd %xmm0, %xmm1
mulsd 0x571f9(%rip), %xmm1    # 0x128630
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
movsd 0x571e6(%rip), %xmm1    # 0x128638
movsd (%rsp), %xmm0
callq 0x8620
movsd 0x1cdfc(%rip), %xmm2    # 0xee260
subsd %xmm0, %xmm2
movsd 0x571d0(%rip), %xmm1    # 0x128640
movapd %xmm2, %xmm0
callq 0x8620
mulsd 0x571c7(%rip), %xmm0    # 0x128648
movq 0x530(%rbx), %rax
movslq 0x53c(%rbx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xd119b
movsd 0x418(%rbx), %xmm2
addsd 0x1cda8(%rip), %xmm2    # 0xee260
ucomisd %xmm0, %xmm2
jbe 0xd1167
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd 0x1cd8a(%rip), %xmm4    # 0xee260
addsd %xmm4, %xmm1
movsd 0x1e19e(%rip), %xmm2    # 0xef680
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 0xd119f
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd11ba
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 0x17d7a
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd1564
leaq 0x1ce21(%rip), %rsi     # 0xee3f0
leaq 0x5771e(%rip), %rdx     # 0x128cf4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1ca45(%rip), %rsi     # 0xee034
leaq 0x577c8(%rip), %rdx     # 0x128dbe
movq %r14, %rdi
movl $0x224, %ecx            # imm = 0x224
jmp 0xd17b6
leaq 0x578a1(%rip), %rsi     # 0x128eab
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x1cf65(%rip), %rsi     # 0xee585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
addq $0x570, %rbx            # imm = 0x570
leaq 0x1c9f1(%rip), %rsi     # 0xee034
leaq 0x57774(%rip), %rdx     # 0x128dbe
movq %rbx, %rdi
movl $0x262, %ecx            # imm = 0x262
jmp 0xd1386
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd11ba
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 0x17d7a
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd166a
leaq 0x1cd1b(%rip), %rsi     # 0xee3f0
leaq 0x57618(%rip), %rdx     # 0x128cf4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1c93f(%rip), %rsi     # 0xee034
leaq 0x576c2(%rip), %rdx     # 0x128dbe
movq %r14, %rdi
movl $0x24d, %ecx            # imm = 0x24D
jmp 0xd17b6
leaq 0x474(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xd11ba
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 0x17d7a
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xd171c
leaq 0x1cc69(%rip), %rsi     # 0xee3f0
leaq 0x57653(%rip), %rdx     # 0x128de1
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1c88d(%rip), %rsi     # 0xee034
leaq 0x57610(%rip), %rdx     # 0x128dbe
movq %r14, %rdi
movl $0x25e, %ecx            # imm = 0x25E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %r14d
movl %r14d, %eax
addq $0x1010, %rsp           # imm = 0x1010
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq