// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../external/heating/injection.c
// Function: injection_calculate_at_z
int injection_calculate_at_z(struct background* pba,
                             struct thermodynamics* pth,
                             double x,
                             double z,
                             double Tmat,
                             double* pvecback){

  /** - Define local variables */
  struct injection * pin = &(pth->in);
  int index_dep;
  double h,a,b;
  double dEdt_inj;

  /** - Store input parameters in struct */
  pin->T_b = Tmat;                                                                                  // [K]
  pin->x_e = x;                                                                                     // [-]
  pin->nH = pin->N_e0*pow(1.+z,3);                                                                  // [1/m^3]
  pin->heat_capacity = (3./2.)*_k_B_*pin->nH*(1.+pin->fHe+pin->x_e);                                // [J/(K m^3)]
  dEdt_inj = 0.;

  /** - Import varying quantities from background structure, convert to SI units */
  pin->H = pvecback[pba->index_bg_H]*_c_/_Mpc_over_m_;                                              // [1/s]
  pin->a = pvecback[pba->index_bg_a];                                                               // [-]
  pin->t = pvecback[pba->index_bg_time]/_s_over_Mpc_;                                               // [s]
  pin->rho_cdm = pvecback[pba->index_bg_rho_cdm]*_Jm3_over_Mpc2_;                                   // [J/m^3]
  pin->rho_g = pvecback[pba->index_bg_rho_g]*_Jm3_over_Mpc2_;                                       // [J/m^3]
  pin->rho_b = pvecback[pba->index_bg_rho_b]*_Jm3_over_Mpc2_;                                       // [J/m^3]

  /** - Hunt within the redshift table for the given index of deposition */
  class_call(array_spline_hunt(pin->z_table,
                               pin->z_size,
                               z,
                               &(pin->index_z_store),
                               &h,&a,&b,
                               pin->error_message),
             pin->error_message,
             pin->error_message);

  /** - Test if and where the new values should be stored in the injection table */
  /* If this value is important, store it */
  if(pin->to_store == _TRUE_){
    /* Calculate where to store the value */
    if(fabs(b-1) < pin->tol_z_table){
      pin->index_z_store = pin->index_z_store+1;
    }
    else if(fabs(b) < pin->tol_z_table){
      pin->index_z_store = pin->index_z_store;
    }
    /* Could not find a matching index in the z table for this z */
    else{
      class_stop(pin->error_message,
                 "Should store z = %.10e, but it was not in the z table (next lower = %.10e , next higher = %.10e )",
                 pin->z_table[pin->index_z_store], pin->z_table[pin->index_z_store+1]);
    }
  }

  /** - Get the injected energy that needs to be deposited (i.e. excluding adiabatic terms) */
  class_call(injection_energy_injection_at_z(pin,
                                             z,
                                             &dEdt_inj),
             pin->error_message,
             pin->error_message);

  /** - Get the deposition and the efficiency functions */
  class_call(injection_deposition_function_at_z(pin,
                                                x,
                                                z),
             pin->error_message,
             pin->error_message);

  /** - Put result into deposition vector */
  for(index_dep = 0; index_dep < pin->dep_size; ++index_dep){
    pin->pvecdeposition[index_dep] = pin->chi[index_dep]*dEdt_inj;
  }

  /** - Store z values in table */
  if(pin->to_store == _TRUE_){
    for(index_dep = 0; index_dep < pin->dep_size; ++index_dep){
      pin->deposition_table[index_dep][pin->index_z_store] = pin->pvecdeposition[index_dep];
    }

    class_test(pin->index_z_store < pin->filled_until_index_z-1,
               pin->error_message,
               "Skipping too far ahead in z_table. Check that the injection and thermodynamics module agree in their z sampling.");
    pin->filled_until_index_z = pin->index_z_store;
    pin->filled_until_z = pin->z_table[pin->index_z_store];
  }

  pin->to_store = _FALSE_;

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movq %rdx, %rbx
movsd %xmm1, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movsd %xmm2, 0x4f0(%rsi)
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x4f8(%rsi)
movsd 0x4e0(%rsi), %xmm0
movsd %xmm0, 0x20(%rsp)
movapd %xmm1, %xmm0
addsd 0x1d90e(%rip), %xmm0    # 0xee260
movsd 0x1ed26(%rip), %xmm1    # 0xef680
callq 0x8620
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x500(%r14)
mulsd 0x3cd9a(%rip), %xmm0    # 0x10d710
movsd 0x1d8e2(%rip), %xmm1    # 0xee260
addsd 0x4d8(%r14), %xmm1
addsd 0x4f8(%r14), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x4e8(%r14)
movq $0x0, 0x10(%rsp)
movslq 0x384(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
mulsd 0x22236(%rip), %xmm0    # 0xf2bf0
divsd 0x22126(%rip), %xmm0    # 0xf2ae8
movsd %xmm0, 0x4a8(%r14)
movslq 0x380(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
movsd %xmm0, 0x4b0(%r14)
movslq 0x41c(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
divsd 0x57c24(%rip), %xmm0    # 0x128618
movsd %xmm0, 0x4b8(%r14)
movslq 0x394(%r15), %rax
movsd 0x3ccf4(%rip), %xmm0    # 0x10d700
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x4d0(%r14)
movslq 0x38c(%r15), %rax
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x4c0(%r14)
movslq 0x390(%r15), %rax
mulsd (%rbx,%rax,8), %xmm0
movsd %xmm0, 0x4c8(%r14)
movq 0x508(%r14), %rdi
movl 0x510(%r14), %esi
leaq 0x540(%r14), %r15
leaq 0x630(%r14), %rbx
movq %rbx, (%rsp)
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x28(%rsp), %r9
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
callq 0x19e56
cmpl $0x1, %eax
jne 0xd0ac9
leaq 0x1d95b(%rip), %rsi     # 0xee3f0
leaq 0x57f21(%rip), %rdx     # 0x1289bd
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1d57f(%rip), %rsi     # 0xee034
leaq 0x57f66(%rip), %rdx     # 0x128a22
movq %rbx, %rdi
movl $0x132, %ecx            # imm = 0x132
jmp 0xd0bbb
cmpl $0x1, 0x62c(%r14)
movsd 0x8(%rsp), %xmm0
jne 0xd0b19
movsd 0x28(%rsp), %xmm3
movsd 0x1dd01(%rip), %xmm2    # 0xee7e8
addsd %xmm3, %xmm2
andpd 0x1d74d(%rip), %xmm2    # 0xee240
movsd 0x518(%r14), %xmm1
ucomisd %xmm2, %xmm1
jbe 0xd0b07
incl (%r15)
jmp 0xd0b19
andpd 0x1d731(%rip), %xmm3    # 0xee240
ucomisd %xmm3, %xmm1
jbe 0xd0bd9
leaq 0xc0(%r14), %r12
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0xd0d60
testl %eax, %eax
je 0xd0b69
leaq 0x1d8b8(%rip), %rsi     # 0xee3f0
leaq 0x57f5e(%rip), %rdx     # 0x128a9d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1d4dc(%rip), %rsi     # 0xee034
leaq 0x57ec3(%rip), %rdx     # 0x128a22
movq %rbx, %rdi
movl $0x14b, %ecx            # imm = 0x14B
jmp 0xd0bbb
movq %r12, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xd1140
testl %eax, %eax
je 0xd0c42
leaq 0x1d864(%rip), %rsi     # 0xee3f0
leaq 0x57f3d(%rip), %rdx     # 0x128ad0
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1d488(%rip), %rsi     # 0xee034
leaq 0x57e6f(%rip), %rdx     # 0x128a22
movq %rbx, %rdi
movl $0x152, %ecx            # imm = 0x152
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x508(%r14), %rax
movslq 0x540(%r14), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x8(%rax,%rcx,8), %xmm1
leaq 0x57e42(%rip), %rsi     # 0x128a3b
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30af0
leaq 0x1d976(%rip), %rsi     # 0xee585
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
leaq 0x1d409(%rip), %rsi     # 0xee034
leaq 0x57df0(%rip), %rdx     # 0x128a22
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
movq %r15, %r8
jmp 0xd0bbe
movslq 0x60c(%r14), %rax
testq %rax, %rax
jle 0xd0cbd
movq 0x5f0(%r14), %rcx
movq 0x610(%r14), %rdx
movsd 0x10(%rsp), %xmm0
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xd0c64
cmpl $0x1, 0x62c(%r14)
jne 0xd0d4e
movl (%r15), %ecx
testl %eax, %eax
jle 0xd0cce
movslq %ecx, %rdx
movq 0x5e8(%r14), %rsi
movq 0x610(%r14), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm0
movq (%rsi,%r8,8), %r9
movsd %xmm0, (%r9,%rdx,8)
incq %r8
cmpq %r8, %rax
jne 0xd0ca3
jmp 0xd0cce
cmpl $0x1, 0x62c(%r14)
jne 0xd0d4e
movl (%r15), %ecx
movl 0x520(%r14), %eax
decl %eax
cmpl %eax, %ecx
jge 0xd0d2f
leaq 0x57e1c(%rip), %rsi     # 0x128afe
leaq 0x40(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x1d38a(%rip), %rsi     # 0xee082
leaq 0x57e70(%rip), %rdx     # 0x128b6f
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x1d319(%rip), %rsi     # 0xee034
leaq 0x57d00(%rip), %rdx     # 0x128a22
movq %rbx, %rdi
movl $0x161, %ecx            # imm = 0x161
jmp 0xd0c3a
movl %ecx, 0x520(%r14)
movq 0x508(%r14), %rax
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x528(%r14)
movl $0x0, 0x62c(%r14)
xorl %eax, %eax
jmp 0xd0bca