// File: /workspace/github_c_makefile_star2_O2/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 0x86a0
pushq $0x1
popq %rbp
movq %rbx, %rdi
movsd %xmm0, 0x10(%rsp)
movq %r15, %rsi
movl %ebp, %edx
movq %r12, %rcx
callq 0x51270
testl %eax, %eax
je 0x56cad
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x7f777(%rip), %rsi     # 0xd63f0
leaq 0x9a624(%rip), %rdx     # 0xf12a4
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7f39b(%rip), %rsi     # 0xd6034
leaq 0x9a63b(%rip), %rdx     # 0xf12db
movq %r13, %rdi
movl $0xa33, %ecx            # imm = 0xA33
jmp 0x56da2
movslq 0x20c(%rbx), %rax
movsd (%r12,%rax,8), %xmm3
movsd 0x7f59e(%rip), %xmm5    # 0xd6260
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 0x56d53
movsd %xmm3, 0x18(%rsp)
movslq 0x218(%rbx), %rax
movsd 0x80a26(%rip), %xmm3    # 0xd7748
movsd (%r12,%rax,8), %xmm1
mulsd %xmm3, %xmm1
mulsd 0x827cc(%rip), %xmm1    # 0xd9500
divsd %xmm0, %xmm1
addsd 0x7f520(%rip), %xmm1    # 0xd6260
mulsd %xmm3, %xmm1
ucomisd %xmm2, %xmm1
jb 0x56dc0
sqrtsd %xmm1, %xmm0
jmp 0x56ddd
leaq 0x9a593(%rip), %rsi     # 0xf12ed
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x2e014
leaq 0x7f312(%rip), %rsi     # 0xd6082
leaq 0x9a59e(%rip), %rdx     # 0xf1315
leaq 0x820(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x7f2a1(%rip), %rsi     # 0xd6034
leaq 0x9a541(%rip), %rdx     # 0xf12db
movq %r13, %rdi
movl $0xa40, %ecx            # imm = 0xA40
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
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 0x82d0
movsd 0x7f489(%rip), %xmm5    # 0xd6260
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 0x56e12
sqrtsd %xmm5, %xmm0
jmp 0x56e27
movapd %xmm5, %xmm0
movsd %xmm4, 0x8(%rsp)
callq 0x82d0
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 0x56e68
movslq 0x21c(%rbx), %rax
addsd (%r12,%rax,8), %xmm0
cmpw $0x1, 0x322(%rbx)
jne 0x56e7f
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 0x820df(%rip), %xmm1    # 0xd8f88
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 0x56f35
movslq 0x2f0(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x8254d(%rip), %xmm0    # 0xd9440
subsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rax,8)
cmpw $0x1, 0x326(%rbx)
jne 0x56f35
movslq 0x2f4(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
movsd 0x60(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd (%r15,%rax,8), %xmm1
mulsd 0x824fd(%rip), %xmm0    # 0xd9428
addsd %xmm1, %xmm0
movsd %xmm0, (%r14,%rcx,8)
cmpw $0x1, 0x32e(%rbx)
jne 0x56f6f
movslq 0x22c(%rbx), %rax
movsd (%r12,%rax,8), %xmm0
addsd 0x7f30c(%rip), %xmm0    # 0xd6260
mulsd 0x824e4(%rip), %xmm0    # 0xd9440
movslq 0x2f8(%rbx), %rax
mulsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%r14,%rax,8)
xorl %ebp, %ebp
cmpw $0x1, 0x328(%rbx)
jne 0x56dac
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 0x51ddb
mulsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd 0x80769(%rip), %xmm1    # 0xd7738
divsd 0x18(%rsp), %xmm0
subsd %xmm0, %xmm1
movslq 0x300(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
jmp 0x56dac