// File: /workspace/github_c_makefile_star2_O3/lesgourg[P]class_public/build/../source/background.c
// Function: background_derivs
int background_derivs(
                      double loga,
                      double* y, /* vector with argument y[index_bi] (must be already allocated with size pba->bi_size) */
                      double* dy, /* vector with argument dy[index_bi]
                                     (must be already allocated with
                                     size pba->bi_size) */
                      void * parameters_and_workspace,
                      ErrorMsg error_message
                      ) {

  /** Summary: */

  /** - define local variables */

  struct background_parameters_and_workspace * pbpaw;
  struct background * pba;
  double * pvecback, a, H, rho_M;

  pbpaw = parameters_and_workspace;
  pba =  pbpaw->pba;
  pvecback = pbpaw->pvecback;

  /** - scale factor a (in fact, given our normalisation conventions, this stands for a/a_0) */
  a = exp(loga);

  /** - calculate functions of \f$ a \f$ with background_functions() */
  class_call(background_functions(pba, a, y, normal_info, pvecback),
             pba->error_message,
             error_message);

  /** - Short hand notation for Hubble */
  H = pvecback[pba->index_bg_H];

  /** - calculate derivative of cosmological time \f$ dt/dloga = 1/H \f$ */
  dy[pba->index_bi_time] = 1./H;

  /** - calculate derivative of conformal time \f$ d\tau/dloga = 1/aH \f$ */
  dy[pba->index_bi_tau] = 1./a/H;

  class_test(pvecback[pba->index_bg_rho_g] <= 0.,
             error_message,
             "rho_g = %e instead of strictly positive",pvecback[pba->index_bg_rho_g]);

  /** - calculate detivative of sound horizon \f$ drs/dloga = drs/dtau * dtau/dloga = c_s/aH \f$*/
  dy[pba->index_bi_rs] = 1./a/H/sqrt(3.*(1.+3.*pvecback[pba->index_bg_rho_b]/4./pvecback[pba->index_bg_rho_g]))*sqrt(1.-pba->K*y[pba->index_bi_rs]*y[pba->index_bi_rs]); // TBC: curvature correction

  /** - solve second order growth equation \f$ [D''(\tau)=-aHD'(\tau)+3/2 a^2 \rho_M D(\tau) \f$
      written as \f$ dD/dloga = D' / (aH) \f$ and \f$ dD'/dloga = -D' + (3/2) (a/H) \rho_M D \f$ */
  rho_M = pvecback[pba->index_bg_rho_b];
  if (pba->has_cdm == _TRUE_) {
    rho_M += pvecback[pba->index_bg_rho_cdm];
  }
  if (pba->has_idm == _TRUE_){
    rho_M += pvecback[pba->index_bg_rho_idm];
  }

  dy[pba->index_bi_D] = y[pba->index_bi_D_prime]/a/H;
  dy[pba->index_bi_D_prime] = -y[pba->index_bi_D_prime] + 1.5*a*rho_M*y[pba->index_bi_D]/H;

  if (pba->has_dcdm == _TRUE_) {
    /** - compute dcdm density \f$ d\rho/dloga = -3 \rho - \Gamma/H \rho \f$*/
    dy[pba->index_bi_rho_dcdm] = -3.*y[pba->index_bi_rho_dcdm] - pba->Gamma_dcdm/H*y[pba->index_bi_rho_dcdm];
  }

  if ((pba->has_dcdm == _TRUE_) && (pba->has_dr == _TRUE_)) {
    /** - Compute dr density \f$ d\rho/dloga = -4\rho - \Gamma/H \rho \f$ */
    dy[pba->index_bi_rho_dr] = -4.*y[pba->index_bi_rho_dr]+pba->Gamma_dcdm/H*y[pba->index_bi_rho_dcdm];
  }

  if (pba->has_fld == _TRUE_) {
    /** - Compute fld density \f$ d\rho/dloga = -3 (1+w_{fld}(a)) \rho \f$ */
    dy[pba->index_bi_rho_fld] = -3.*(1.+pvecback[pba->index_bg_w_fld])*y[pba->index_bi_rho_fld];
  }

  if (pba->has_scf == _TRUE_) {
    /** - Scalar field equation: \f$ \phi'' + 2 a H \phi' + a^2 dV = 0 \f$  (note H is wrt cosmological time)
        written as \f$ d\phi/dlna = phi' / (aH) \f$ and \f$ d\phi'/dlna = -2*phi' - (a/H) dV \f$ */
    dy[pba->index_bi_phi_scf] = y[pba->index_bi_phi_prime_scf]/a/H;
    dy[pba->index_bi_phi_prime_scf] = - 2*y[pba->index_bi_phi_prime_scf] - a*dV_scf(pba,y[pba->index_bi_phi_scf])/H ;
  }

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movq %rcx, %r13
movq %rsi, %r14
movq %rdi, %r15
movq (%rdx), %rbx
movq 0x8(%rdx), %r12
callq 0x8670
movl $0x1, %ebp
movq %rbx, %rdi
movsd %xmm0, 0x10(%rsp)
movq %r15, %rsi
movl $0x1, %edx
movq %r12, %rcx
callq 0x550ea
testl %eax, %eax
je 0x5aef6
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x8452e(%rip), %rsi     # 0xdf3f0
leaq 0x9f52b(%rip), %rdx     # 0xfa3f4
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x84152(%rip), %rsi     # 0xdf034
leaq 0x9f542(%rip), %rdx     # 0xfa42b
movq %r13, %rdi
movl $0xa33, %ecx            # imm = 0xA33
jmp 0x5afee
movslq 0x20c(%rbx), %rax
movsd (%r12,%rax,8), %xmm3
movsd 0x84355(%rip), %xmm5    # 0xdf260
movapd %xmm5, %xmm0
divsd %xmm3, %xmm0
movslq 0x304(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movapd %xmm5, %xmm4
movsd 0x10(%rsp), %xmm0
divsd %xmm0, %xmm4
divsd %xmm3, %xmm4
movslq 0x30c(%rbx), %rax
movsd %xmm4, (%r14,%rax,8)
movslq 0x214(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
jae 0x5af9f
movsd %xmm3, 0x18(%rsp)
movslq 0x218(%rbx), %rax
movsd 0x85715(%rip), %xmm3    # 0xe0680
movsd (%r12,%rax,8), %xmm1
mulsd %xmm3, %xmm1
mulsd 0x87603(%rip), %xmm1    # 0xe2580
divsd %xmm0, %xmm1
addsd 0x842d7(%rip), %xmm1    # 0xdf260
mulsd %xmm3, %xmm1
ucomisd %xmm2, %xmm1
jb 0x5b00c
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x5b029
leaq 0x9f497(%rip), %rsi     # 0xfa43d
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x30af0
leaq 0x840c6(%rip), %rsi     # 0xdf082
leaq 0x9f4a2(%rip), %rdx     # 0xfa465
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x84055(%rip), %rsi     # 0xdf034
leaq 0x9f445(%rip), %rdx     # 0xfa42b
movq %r13, %rdi
movl $0xa40, %ecx            # imm = 0xA40
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl %ebp, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movapd %xmm1, %xmm0
movsd %xmm4, 0x8(%rsp)
callq 0x82b0
movsd 0x8423d(%rip), %xmm5    # 0xdf260
movsd 0x8(%rsp), %xmm4
divsd %xmm0, %xmm4
movslq 0x308(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x1a0(%rbx), %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
subsd %xmm1, %xmm5
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm5
jb 0x5b061
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
jmp 0x5b076
movapd %xmm5, %xmm0
movsd %xmm4, 0x8(%rsp)
callq 0x82b0
movsd 0x8(%rsp), %xmm4
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
mulsd %xmm0, %xmm4
movslq 0x308(%rbx), %rax
movsd %xmm4, (%r14,%rax,8)
movslq 0x218(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
cmpw $0x1, 0x320(%rbx)
jne 0x5b0b7
movslq 0x21c(%rbx), %rax
addsd (%r12,%rax,8), %xmm0
cmpw $0x1, 0x322(%rbx)
jne 0x5b0ce
movslq 0x220(%rbx), %rax
addsd (%r12,%rax,8), %xmm0
movslq 0x314(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
divsd %xmm2, %xmm1
divsd %xmm3, %xmm1
movslq 0x310(%rbx), %rcx
movsd %xmm1, (%r14,%rcx,8)
movsd 0x86ed0(%rip), %xmm1    # 0xe1fc8
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
mulsd (%r15,%rcx,8), %xmm1
divsd %xmm3, %xmm1
subsd (%r15,%rax,8), %xmm1
movsd %xmm1, (%r14,%rax,8)
cmpw $0x1, 0x324(%rbx)
jne 0x5b184
movslq 0x2f0(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x8733e(%rip), %xmm0    # 0xe2480
subsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rax,8)
cmpw $0x1, 0x326(%rbx)
jne 0x5b184
movslq 0x2f4(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd (%r15,%rax,8), %xmm1
mulsd 0x872ee(%rip), %xmm0    # 0xe2468
addsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rcx,8)
cmpw $0x1, 0x32e(%rbx)
jne 0x5b1be
movslq 0x22c(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
addsd 0x840bd(%rip), %xmm0    # 0xdf260
mulsd 0x872d5(%rip), %xmm0    # 0xe2480
movslq 0x2f8(%rbx), %rax
mulsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%r14,%rax,8)
xorl %ebp, %ebp
cmpw $0x1, 0x328(%rbx)
jne 0x5aff8
movslq 0x300(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
divsd %xmm2, %xmm0
divsd %xmm3, %xmm0
movslq 0x2fc(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%r15,%rcx,8), %xmm0
movq %rbx, %rdi
callq 0x55dc8
mulsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd 0x85542(%rip), %xmm1    # 0xe0760
divsd 0x18(%rsp), %xmm0
subsd %xmm0, %xmm1
movslq 0x300(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
jmp 0x5aff8