// File: /workspace/github_c_makefile_star2_O2/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 0xc9a39
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
movslq 0x53c(%rbx), %rcx
andq $0x0, (%rax,%rcx,8)
movslq 0x540(%rbx), %rcx
andq $0x0, (%rax,%rcx,8)
xorpd %xmm4, %xmm4
movslq 0x544(%rbx), %rcx
movsd %xmm4, (%rax,%rcx,8)
movslq 0x548(%rbx), %rcx
andq $0x0, (%rax,%rcx,8)
movl 0xa0(%rbx), %eax
testl %eax, %eax
je 0xc9ac0
cmpl $0x1, %eax
jne 0xc9af8
movq 0x500(%rbx), %rdi
movl 0x4f8(%rbx), %esi
leaq 0x470(%rbx), %rax
leaq 0x4f0(%rbx), %r10
leaq 0x570(%rbx), %r15
subq $0x8, %rsp
pushq $0x3
popq %rdx
pushq $0x1
popq %r14
pushq $0x2
popq %r9
xorl %ecx, %ecx
movl %r14d, %r8d
movsd 0x10(%rsp), %xmm0
pushq %r15
pushq %r10
pushq %rax
callq 0x15d73
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xc9ac0
leaq 0x1b9f5(%rip), %rsi     # 0xe53f0
leaq 0x5638c(%rip), %rdx     # 0x11fd8e
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1b619(%rip), %rsi     # 0xe5034
leaq 0x5624c(%rip), %rdx     # 0x11fc6e
movq %r15, %rdi
movl $0x278, %ecx            # imm = 0x278
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
jmp 0xc9f6b
movl 0x1a4(%rbx), %eax
cmpq $0x6, %rax
ja 0xc9daa
leaq 0x55c50(%rip), %rcx     # 0x11f6a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movsd %xmm0, (%rsp)
jmpq *%rax
movsd 0x1b7fa(%rip), %xmm4    # 0xe5260
ucomisd %xmm0, %xmm4
jbe 0xc993a
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
addsd %xmm4, %xmm1
movsd 0x1ccc4(%rip), %xmm2    # 0xe6748
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
andq $0x0, (%rax,%rcx,8)
jmp 0xc9972
movl 0x54c(%rbx), %eax
xorl %r14d, %r14d
testl %eax, %eax
cmovlel %r14d, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xc9f6b
movsd 0x4f0(%rbx), %xmm0
movq 0x530(%rbx), %rdx
mulsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0xc9ad1
leaq 0x56323(%rip), %rsi     # 0x11fe22
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x1ba70(%rip), %rsi     # 0xe5585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
addq $0x570, %rbx            # imm = 0x570
leaq 0x1b4fc(%rip), %rsi     # 0xe5034
leaq 0x5612f(%rip), %rdx     # 0x11fc6e
movq %rbx, %rdi
movl $0x27d, %ecx            # imm = 0x27D
movq %r15, %r8
jmp 0xc9f60
movsd 0x1b709(%rip), %xmm1    # 0xe5260
ucomisd %xmm0, %xmm1
jbe 0xc993a
movsd 0x55967(%rip), %xmm1    # 0x11f4d0
callq 0x8650
movsd 0x1b6ea(%rip), %xmm2    # 0xe5260
subsd %xmm0, %xmm2
movsd 0x55956(%rip), %xmm1    # 0x11f4d8
movapd %xmm2, %xmm0
callq 0x8650
movsd 0x1b6cd(%rip), %xmm2    # 0xe5260
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
mulsd 0x5593d(%rip), %xmm1    # 0x11f4e0
ucomisd %xmm1, %xmm2
movapd %xmm2, %xmm1
jbe 0xc9bf0
movsd 0x5591b(%rip), %xmm1    # 0x11f4d0
movsd (%rsp), %xmm0
callq 0x8650
movsd 0x1b699(%rip), %xmm2    # 0xe5260
subsd %xmm0, %xmm2
movsd 0x55905(%rip), %xmm1    # 0x11f4d8
movapd %xmm2, %xmm0
callq 0x8650
movsd 0x1b67c(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
mulsd 0x558f0(%rip), %xmm1    # 0x11f4e0
movq 0x530(%rbx), %rax
movslq 0x538(%rbx), %rcx
movsd %xmm1, (%rax,%rcx,8)
movsd 0x558dd(%rip), %xmm1    # 0x11f4e8
movsd (%rsp), %xmm0
callq 0x8650
movsd 0x1b643(%rip), %xmm2    # 0xe5260
subsd %xmm0, %xmm2
movsd 0x558c7(%rip), %xmm1    # 0x11f4f0
movapd %xmm2, %xmm0
callq 0x8650
mulsd 0x558be(%rip), %xmm0    # 0x11f4f8
movq 0x530(%rbx), %rax
movslq 0x53c(%rbx), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0xc9962
movsd 0x418(%rbx), %xmm2
addsd 0x1b5fe(%rip), %xmm2    # 0xe5260
ucomisd %xmm0, %xmm2
jbe 0xc993a
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd 0x1b5e0(%rip), %xmm4    # 0xe5260
addsd %xmm4, %xmm1
movsd 0x1cabc(%rip), %xmm2    # 0xe6748
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
andq $0x0, (%rax,%rcx,8)
movsd 0x418(%rbx), %xmm1
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
subsd %xmm0, %xmm4
divsd %xmm2, %xmm4
jmp 0xc9972
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xc998a
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 0x15d73
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xc9d0b
leaq 0x1b67a(%rip), %rsi     # 0xe53f0
leaq 0x55e27(%rip), %rdx     # 0x11fba4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1b29e(%rip), %rsi     # 0xe5034
leaq 0x55ed1(%rip), %rdx     # 0x11fc6e
movq %r14, %rdi
movl $0x224, %ecx            # imm = 0x224
jmp 0xc9f5d
leaq 0x55faa(%rip), %rsi     # 0x11fd5b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x1b7be(%rip), %rsi     # 0xe5585
leaq 0x810(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
addq $0x570, %rbx            # imm = 0x570
leaq 0x1b24a(%rip), %rsi     # 0xe5034
leaq 0x55e7d(%rip), %rdx     # 0x11fc6e
movq %rbx, %rdi
movl $0x262, %ecx            # imm = 0x262
jmp 0xc9b47
leaq 0x484(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xc998a
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 0x15d73
movsd 0x20(%rsp), %xmm0
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xc9e11
leaq 0x1b574(%rip), %rsi     # 0xe53f0
leaq 0x55d21(%rip), %rdx     # 0x11fba4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1b198(%rip), %rsi     # 0xe5034
leaq 0x55dcb(%rip), %rdx     # 0x11fc6e
movq %r14, %rdi
movl $0x24d, %ecx            # imm = 0x24D
jmp 0xc9f5d
leaq 0x474(%rbx), %r12
leaq 0x570(%rbx), %r14
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x54c(%rbx), %rax
cmpq %rax, %rcx
jge 0xc998a
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 0x15d73
addq $0x20, %rsp
addq $0x8, %r13
movq %r15, %rcx
cmpl $0x1, %eax
jne 0xc9ec3
leaq 0x1b4c2(%rip), %rsi     # 0xe53f0
leaq 0x55d5c(%rip), %rdx     # 0x11fc91
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1b0e6(%rip), %rsi     # 0xe5034
leaq 0x55d19(%rip), %rdx     # 0x11fc6e
movq %r14, %rdi
movl $0x25e, %ecx            # imm = 0x25E
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %r14
movl %r14d, %eax
addq $0x1010, %rsp           # imm = 0x1010
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq