// File: /workspace/github_c_makefile_star2_O1/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 0x57294
testl %eax, %eax
je 0x5d239
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x841eb(%rip), %rsi     # 0xe13f0
leaq 0x9f1b8(%rip), %rdx     # 0xfc3c4
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x83e0f(%rip), %rsi     # 0xe1034
leaq 0x9f1cf(%rip), %rdx     # 0xfc3fb
movq %r13, %rdi
movl $0xa33, %ecx            # imm = 0xA33
jmp 0x5d33f
movslq 0x20c(%rbx), %rax
movsd (%r12,%rax,8), %xmm3
movsd 0x84012(%rip), %xmm5    # 0xe1260
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), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
jae 0x5d2e3
movsd %xmm3, 0x18(%rsp)
movslq 0x218(%rbx), %rax
movsd 0x853d2(%rip), %xmm3    # 0xe2680
movsd (%r12,%rax,8), %xmm0
mulsd %xmm3, %xmm0
mulsd 0x872b0(%rip), %xmm0    # 0xe4570
divsd %xmm2, %xmm0
addsd 0x83f94(%rip), %xmm0    # 0xe1260
mulsd %xmm3, %xmm0
ucomisd %xmm1, %xmm0
jb 0x5d35d
sqrtsd %xmm0, %xmm0
jmp 0x5d376
movslq 0x214(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
leaq 0x9f116(%rip), %rsi     # 0xfc40d
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x30c2c
leaq 0x83d75(%rip), %rsi     # 0xe1082
leaq 0x9f121(%rip), %rdx     # 0xfc435
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x83d04(%rip), %rsi     # 0xe1034
leaq 0x9f0c4(%rip), %rdx     # 0xfc3fb
movq %r13, %rdi
movl $0xa40, %ecx            # imm = 0xA40
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl %ebp, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm4, 0x8(%rsp)
callq 0x82b0
movsd 0x83ef0(%rip), %xmm5    # 0xe1260
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 0x5d3ae
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
jmp 0x5d3c3
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 0x5d404
movslq 0x21c(%rbx), %rax
addsd (%r12,%rax,8), %xmm0
cmpw $0x1, 0x322(%rbx)
jne 0x5d41b
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 0x86b73(%rip), %xmm1    # 0xe3fb8
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 0x5d4d8
movslq 0x2f0(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x86fe1(%rip), %xmm0    # 0xe4470
subsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rax,8)
cmpw $0x1, 0x326(%rbx)
jne 0x5d4d8
movslq 0x2f4(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
movslq 0x2f0(%rbx), %rcx
mulsd (%r15,%rcx,8), %xmm1
mulsd 0x86f8a(%rip), %xmm0    # 0xe4458
addsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rax,8)
cmpw $0x1, 0x32e(%rbx)
jne 0x5d512
movslq 0x22c(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
addsd 0x83d69(%rip), %xmm0    # 0xe1260
mulsd 0x86f71(%rip), %xmm0    # 0xe4470
movslq 0x2f8(%rbx), %rax
mulsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%r14,%rax,8)
xorl %ebp, %ebp
cmpw $0x1, 0x328(%rbx)
jne 0x5d349
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 0x57f5f
mulsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd 0x851e6(%rip), %xmm1    # 0xe2758
divsd 0x18(%rsp), %xmm0
subsd %xmm0, %xmm1
movslq 0x300(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
jmp 0x5d349