// File: /workspace/github_c_makefile_star2_O1/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 0x1d0f0(%rip), %xmm0    # 0xf1260
movsd 0x1e508(%rip), %xmm1    # 0xf2680
callq 0x8620
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x500(%r14)
mulsd 0x3c55c(%rip), %xmm0    # 0x1106f0
movsd 0x1d0c4(%rip), %xmm1    # 0xf1260
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 0x219e8(%rip), %xmm0    # 0xf5bc0
divsd 0x218d8(%rip), %xmm0    # 0xf5ab8
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 0x573d6(%rip), %xmm0    # 0x12b5e8
movsd %xmm0, 0x4b8(%r14)
movslq 0x394(%r15), %rax
movsd 0x3c4b6(%rip), %xmm0    # 0x1106e0
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 0x19cfd
cmpl $0x1, %eax
jne 0xd42e7
leaq 0x1d13d(%rip), %rsi     # 0xf13f0
leaq 0x576d3(%rip), %rdx     # 0x12b98d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1cd61(%rip), %rsi     # 0xf1034
leaq 0x57718(%rip), %rdx     # 0x12b9f2
movq %rbx, %rdi
movl $0x132, %ecx            # imm = 0x132
jmp 0xd43d9
cmpl $0x1, 0x62c(%r14)
movsd 0x8(%rsp), %xmm0
jne 0xd4337
movsd 0x28(%rsp), %xmm3
movsd 0x1d4e3(%rip), %xmm2    # 0xf17e8
addsd %xmm3, %xmm2
andpd 0x1cf2f(%rip), %xmm2    # 0xf1240
movsd 0x518(%r14), %xmm1
ucomisd %xmm2, %xmm1
jbe 0xd4325
incl (%r15)
jmp 0xd4337
andpd 0x1cf13(%rip), %xmm3    # 0xf1240
ucomisd %xmm3, %xmm1
jbe 0xd43f5
leaq 0xc0(%r14), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0xd456c
testl %eax, %eax
je 0xd4387
leaq 0x1d09a(%rip), %rsi     # 0xf13f0
leaq 0x57710(%rip), %rdx     # 0x12ba6d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1ccbe(%rip), %rsi     # 0xf1034
leaq 0x57675(%rip), %rdx     # 0x12b9f2
movq %rbx, %rdi
movl $0x14b, %ecx            # imm = 0x14B
jmp 0xd43d9
movq %r15, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xd494e
testl %eax, %eax
je 0xd445b
leaq 0x1d046(%rip), %rsi     # 0xf13f0
leaq 0x576ef(%rip), %rdx     # 0x12baa0
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1cc6a(%rip), %rsi     # 0xf1034
leaq 0x57621(%rip), %rdx     # 0x12b9f2
movq %rbx, %rdi
movl $0x152, %ecx            # imm = 0x152
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
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 0x575f6(%rip), %rsi     # 0x12ba0b
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30c2c
leaq 0x1d15a(%rip), %rsi     # 0xf1585
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1cbed(%rip), %rsi     # 0xf1034
leaq 0x575a4(%rip), %rdx     # 0x12b9f2
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
movq %r15, %r8
jmp 0xd43dc
movslq 0x60c(%r14), %rax
testq %rax, %rax
jle 0xd4493
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 0xd447d
cmpl $0x1, 0x62c(%r14)
jne 0xd455a
testl %eax, %eax
jle 0xd44d3
movq 0x5e8(%r14), %rcx
movq 0x610(%r14), %rdx
movslq 0x540(%r14), %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm0
movq (%rcx,%rdi,8), %r8
movsd %xmm0, (%r8,%rsi,8)
incq %rdi
cmpq %rdi, %rax
jne 0xd44bc
movl 0x520(%r14), %ecx
movl 0x540(%r14), %eax
decl %ecx
cmpl %ecx, %eax
jge 0xd453b
leaq 0x575e0(%rip), %rsi     # 0x12bace
leaq 0x40(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x1cb7e(%rip), %rsi     # 0xf1082
leaq 0x57634(%rip), %rdx     # 0x12bb3f
leaq 0x840(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x1cb0d(%rip), %rsi     # 0xf1034
leaq 0x574c4(%rip), %rdx     # 0x12b9f2
movq %rbx, %rdi
movl $0x161, %ecx            # imm = 0x161
jmp 0xd4456
movslq %eax, %rcx
movl %eax, 0x520(%r14)
movq 0x508(%r14), %rax
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x528(%r14)
movl $0x0, 0x62c(%r14)
xorl %eax, %eax
jmp 0xd43e8