// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x1040, %rsp           # imm = 0x1040
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 0x1c0e9(%rip), %xmm0    # 0xe5260
movsd 0x1d5c9(%rip), %xmm1    # 0xe6748
callq 0x8650
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x500(%r14)
mulsd 0x3b435(%rip), %xmm0    # 0x1045d0
movsd 0x1c0bd(%rip), %xmm1    # 0xe5260
addsd 0x4d8(%r14), %xmm1
addsd 0x4f8(%r14), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x4e8(%r14)
andq $0x0, 0x10(%rsp)
movslq 0x384(%r15), %rax
movsd (%rbx,%rax,8), %xmm0
mulsd 0x208d4(%rip), %xmm0    # 0xe9ab0
divsd 0x207c4(%rip), %xmm0    # 0xe99a8
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 0x562b2(%rip), %xmm0    # 0x11f4c8
movsd %xmm0, 0x4b8(%r14)
movslq 0x394(%r15), %rax
movsd 0x3b392(%rip), %xmm0    # 0x1045c0
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 0x17d10
cmpl $0x1, %eax
jne 0xc92eb
leaq 0x1c139(%rip), %rsi     # 0xe53f0
leaq 0x565af(%rip), %rdx     # 0x11f86d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1bd5d(%rip), %rsi     # 0xe5034
leaq 0x565f4(%rip), %rdx     # 0x11f8d2
movq %rbx, %rdi
movl $0x132, %ecx            # imm = 0x132
jmp 0xc93dd
cmpl $0x1, 0x62c(%r14)
movsd 0x8(%rsp), %xmm0
jne 0xc933b
movsd 0x28(%rsp), %xmm3
movsd 0x1c4df(%rip), %xmm2    # 0xe57e8
addsd %xmm3, %xmm2
andpd 0x1bf2b(%rip), %xmm2    # 0xe5240
movsd 0x518(%r14), %xmm1
ucomisd %xmm2, %xmm1
jbe 0xc9329
incl (%r15)
jmp 0xc933b
andpd 0x1bf0f(%rip), %xmm3    # 0xe5240
ucomisd %xmm3, %xmm1
jbe 0xc93f7
leaq 0xc0(%r14), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0xc956a
testl %eax, %eax
je 0xc938b
leaq 0x1c096(%rip), %rsi     # 0xe53f0
leaq 0x565ec(%rip), %rdx     # 0x11f94d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1bcba(%rip), %rsi     # 0xe5034
leaq 0x56551(%rip), %rdx     # 0x11f8d2
movq %rbx, %rdi
movl $0x14b, %ecx            # imm = 0x14B
jmp 0xc93dd
movq %r15, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xc9913
testl %eax, %eax
je 0xc945d
leaq 0x1c042(%rip), %rsi     # 0xe53f0
leaq 0x565cb(%rip), %rdx     # 0x11f980
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1bc66(%rip), %rsi     # 0xe5034
leaq 0x564fd(%rip), %rdx     # 0x11f8d2
movq %rbx, %rdi
movl $0x152, %ecx            # imm = 0x152
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x1040, %rsp           # imm = 0x1040
popq %rbx
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 0x564d4(%rip), %rsi     # 0x11f8eb
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x2e014
leaq 0x1c158(%rip), %rsi     # 0xe5585
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
leaq 0x1bbeb(%rip), %rsi     # 0xe5034
leaq 0x56482(%rip), %rdx     # 0x11f8d2
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
movq %r15, %r8
jmp 0xc93e0
movl 0x60c(%r14), %eax
movsd 0x10(%rsp), %xmm0
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0xc9497
movq 0x5f0(%r14), %rdx
movq 0x610(%r14), %rsi
movsd (%rdx,%rcx,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%rcx,8)
incq %rcx
jmp 0xc9471
cmpl $0x1, 0x62c(%r14)
jne 0xc955b
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xc94d4
movq 0x5e8(%r14), %rdx
movq 0x610(%r14), %rsi
movsd (%rsi,%rcx,8), %xmm0
movq (%rdx,%rcx,8), %rdx
movslq 0x540(%r14), %rsi
movsd %xmm0, (%rdx,%rsi,8)
incq %rcx
jmp 0xc94a7
movl 0x520(%r14), %ecx
movl 0x540(%r14), %eax
decl %ecx
cmpl %ecx, %eax
jge 0xc953c
leaq 0x564bf(%rip), %rsi     # 0x11f9ae
leaq 0x40(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x1bb7d(%rip), %rsi     # 0xe5082
leaq 0x56513(%rip), %rdx     # 0x11fa1f
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x1bb0c(%rip), %rsi     # 0xe5034
leaq 0x563a3(%rip), %rdx     # 0x11f8d2
movq %rbx, %rdi
movl $0x161, %ecx            # imm = 0x161
jmp 0xc9458
movslq %eax, %rcx
movl %eax, 0x520(%r14)
movq 0x508(%r14), %rax
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x528(%r14)
andl $0x0, 0x62c(%r14)
xorl %eax, %eax
jmp 0xc93ea