// File: /workspace/github_c_makefile_star2_O3/lesgourg[P]class_public/build/../source/background.c
// Function: background_w_fld
int background_w_fld(
                     struct background * pba,
                     double a,
                     double * w_fld,
                     double * dw_over_da_fld,
                     double * integral_fld
                     ) {

  double Omega_ede = 0.;
  double dOmega_ede_over_da = 0.;
  double d2Omega_ede_over_da2 = 0.;
  double a_eq, Omega_r, Omega_m;

  /** - first, define the function w(a) */
  switch (pba->fluid_equation_of_state) {
  case CLP:
    *w_fld = pba->w0_fld + pba->wa_fld * (1. - a);
    break;
  case EDE:
    // Omega_ede(a) taken from eq. (10) in 1706.00730
    Omega_ede = (pba->Omega0_fld - pba->Omega_EDE*(1.-pow(a,-3.*pba->w0_fld)))
      /(pba->Omega0_fld+(1.-pba->Omega0_fld)*pow(a,3.*pba->w0_fld))
      + pba->Omega_EDE*(1.-pow(a,-3.*pba->w0_fld));

    // d Omega_ede / d a taken analytically from the above
    dOmega_ede_over_da = - pba->Omega_EDE* 3.*pba->w0_fld*pow(a,-3.*pba->w0_fld-1.)/(pba->Omega0_fld+(1.-pba->Omega0_fld)*pow(a,3.*pba->w0_fld))
      - (pba->Omega0_fld - pba->Omega_EDE*(1.-pow(a,-3.*pba->w0_fld)))*(1.-pba->Omega0_fld)*3.*pba->w0_fld*pow(a,3.*pba->w0_fld-1.)/pow(pba->Omega0_fld+(1.-pba->Omega0_fld)*pow(a,3.*pba->w0_fld),2)
      + pba->Omega_EDE*3.*pba->w0_fld*pow(a,-3.*pba->w0_fld-1.);

    // find a_equality (needed because EDE tracks first radiation, then matter)
    Omega_r = pba->Omega0_g * (1. + 3.044 * 7./8.*pow(4./11.,4./3.)); // assumes LambdaCDM + eventually massive neutrinos so light that they are relativistic at equality; needs to be generalised later on.
    Omega_m = pba->Omega0_b;
    if (pba->has_cdm == _TRUE_) Omega_m += pba->Omega0_cdm;
    if (pba->has_idm == _TRUE_) Omega_m += pba->Omega0_idm;
    if (pba->has_dcdm == _TRUE_)
      class_stop(pba->error_message,"Early Dark Energy not compatible with decaying Dark Matter because we omitted to code the calculation of a_eq in that case, but it would not be difficult to add it if necessary, should be a matter of 5 minutes");
    a_eq = Omega_r/Omega_m; // assumes a flat universe with a=1 today

    // w_ede(a) taken from eq. (11) in 1706.00730
    *w_fld = - dOmega_ede_over_da*a/Omega_ede/3./(1.-Omega_ede)+a_eq/3./(a+a_eq);
    break;
  }


  /** - then, give the corresponding analytic derivative dw/da (used
      by perturbation equations; we could compute it numerically,
      but with a loss of precision; as long as there is a simple
      analytic expression of the derivative of the previous
      function, let's use it! */
  switch (pba->fluid_equation_of_state) {
  case CLP:
    *dw_over_da_fld = - pba->wa_fld;
    break;
  case EDE:
    d2Omega_ede_over_da2 = 0.;
    *dw_over_da_fld = - d2Omega_ede_over_da2*a/3./(1.-Omega_ede)/Omega_ede
      - dOmega_ede_over_da/3./(1.-Omega_ede)/Omega_ede
      + dOmega_ede_over_da*dOmega_ede_over_da*a/3./(1.-Omega_ede)/(1.-Omega_ede)/Omega_ede
      + a_eq/3./(a+a_eq)/(a+a_eq);
    break;
  }

  /** - finally, give the analytic solution of the following integral:
      \f$ \int_{a}^{a0} da 3(1+w_{fld})/a \f$. This is used in only
      one place, in the initial conditions for the background, and
      with a=a_ini. If your w(a) does not lead to a simple analytic
      solution of this integral, no worry: instead of writing
      something here, the best would then be to leave it equal to
      zero, and then in background_initial_conditions() you should
      implement a numerical calculation of this integral only for
      a=a_ini, using for instance Romberg integration. It should be
      fast, simple, and accurate enough. */
  switch (pba->fluid_equation_of_state) {
  case CLP:
    *integral_fld = 3.*((1.+pba->w0_fld+pba->wa_fld)*log(1./a) + pba->wa_fld*(a-1.));
    break;
  case EDE:
    class_stop(pba->error_message,"EDE implementation not finished: to finish it, read the comments in background.c just before this line\n");
    break;
  }

  /** note: of course you can generalise these formulas to anything,
      defining new parameters pba->w..._fld. Just remember that so
      far, HyRec explicitely assumes that w(a)= w0 + wa (1-a/a0); but
      Recfast does not assume anything */

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10d0, %rsp           # imm = 0x10D0
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movapd %xmm0, %xmm6
movq %rdi, %rbx
movl 0x120(%rdi), %eax
cmpl $0x1, %eax
je 0x562c2
testl %eax, %eax
jne 0x5658c
movsd 0x88fc1(%rip), %xmm1    # 0xdf260
subsd %xmm6, %xmm1
mulsd 0x130(%rbx), %xmm1
addsd 0x128(%rbx), %xmm1
xorpd %xmm7, %xmm7
xorl %eax, %eax
xorpd %xmm5, %xmm5
jmp 0x5672b
movsd 0x100(%rbx), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0x140(%rbx), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x128(%rbx), %xmm1
mulsd 0x8c18c(%rip), %xmm1    # 0xe2480
movapd %xmm6, %xmm0
movsd %xmm6, 0x8(%rsp)
callq 0x8620
movsd %xmm0, 0x88(%rsp)
movsd 0x100(%rbx), %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0x8a35b(%rip), %xmm0    # 0xe0680
movapd %xmm0, 0x10(%rsp)
movsd 0x128(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x90(%rsp)
movsd 0x140(%rbx), %xmm0
movaps %xmm0, 0xc0(%rsp)
movsd 0x128(%rbx), %xmm1
mulsd 0x8c115(%rip), %xmm1    # 0xe2480
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0xa8(%rsp)
movsd 0x140(%rbx), %xmm0
movsd 0x8c0f1(%rip), %xmm2    # 0xe2480
mulsd %xmm2, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x128(%rbx), %xmm1
movsd %xmm1, 0x70(%rsp)
mulsd %xmm2, %xmm1
addsd 0x89432(%rip), %xmm1    # 0xdf7e8
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x78(%rsp)
movsd 0x100(%rbx), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x128(%rbx), %xmm1
movsd 0x8a298(%rip), %xmm0    # 0xe0680
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x50(%rsp)
movsd 0x100(%rbx), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x140(%rbx), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x128(%rbx), %xmm1
mulsd 0x8c057(%rip), %xmm1    # 0xe2480
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x28(%rsp)
movsd 0x88e1e(%rip), %xmm0    # 0xdf260
subsd 0x100(%rbx), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x128(%rbx), %xmm1
movsd %xmm1, 0x60(%rsp)
movsd 0x8a21a(%rip), %xmm0    # 0xe0680
mulsd %xmm0, %xmm1
addsd 0x89376(%rip), %xmm1    # 0xdf7e8
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x68(%rsp)
movsd 0x100(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x128(%rbx), %xmm1
movsd 0x8a1df(%rip), %xmm0    # 0xe0680
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd %xmm0, 0x20(%rsp)
movapd 0x10(%rsp), %xmm0
mulsd 0x140(%rbx), %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x128(%rbx), %xmm1
movsd %xmm1, 0x48(%rsp)
mulsd 0x8bfa0(%rip), %xmm1    # 0xe2480
addsd 0x89300(%rip), %xmm1    # 0xdf7e8
movsd 0x8(%rsp), %xmm0
callq 0x8620
movsd 0x20(%rbx), %xmm1
cmpw $0x1, 0x320(%rbx)
jne 0x56507
addsd 0x30(%rbx), %xmm1
cmpw $0x1, 0x322(%rbx)
movsd 0x8(%rsp), %xmm6
movapd 0xc0(%rsp), %xmm7
movapd 0x10(%rsp), %xmm5
jne 0x5652b
addsd 0x38(%rbx), %xmm1
cmpw $0x1, 0x324(%rbx)
jne 0x56599
leaq 0xa255b(%rip), %rsi     # 0xf8a97
leaq 0x8d0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x89030(%rip), %rsi     # 0xdf585
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x88abc(%rip), %rsi     # 0xdf034
leaq 0xa25ea(%rip), %rdx     # 0xf8b69
movq %rbx, %rdi
movl $0x2bb, %ecx            # imm = 0x2BB
jmp 0x56899
xorpd %xmm7, %xmm7
xorpd %xmm5, %xmm5
jmp 0x56731
movsd 0x88cbe(%rip), %xmm8    # 0xdf260
movapd %xmm8, %xmm2
subsd 0x28(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
mulsd %xmm2, %xmm3
movsd 0x58(%rsp), %xmm10
subsd %xmm3, %xmm10
mulsd 0x30(%rsp), %xmm10
mulsd 0x8bead(%rip), %xmm10   # 0xe2480
movapd %xmm8, %xmm2
movsd 0x40(%rsp), %xmm14
subsd %xmm14, %xmm2
mulsd 0x20(%rsp), %xmm2
movapd %xmm8, %xmm3
subsd 0x88(%rsp), %xmm3
movsd 0xa0(%rsp), %xmm4
mulsd %xmm3, %xmm4
movsd 0xb8(%rsp), %xmm9
subsd %xmm4, %xmm9
movsd 0x98(%rsp), %xmm11
mulsd 0x70(%rsp), %xmm11
movapd %xmm8, %xmm3
movsd 0x80(%rsp), %xmm12
subsd %xmm12, %xmm3
mulsd 0x50(%rsp), %xmm3
movsd 0x60(%rsp), %xmm13
mulsd %xmm10, %xmm13
addsd %xmm14, %xmm2
movapd %xmm8, %xmm4
movsd 0xb0(%rsp), %xmm10
subsd %xmm10, %xmm4
mulsd 0x90(%rsp), %xmm4
mulsd 0x78(%rsp), %xmm11
addsd %xmm12, %xmm3
divsd %xmm3, %xmm11
movsd 0x68(%rsp), %xmm3
mulsd %xmm13, %xmm3
mulsd %xmm2, %xmm2
divsd %xmm2, %xmm3
addsd %xmm11, %xmm3
addsd %xmm10, %xmm4
divsd %xmm4, %xmm9
movapd %xmm8, %xmm2
subsd 0xa8(%rsp), %xmm2
mulsd %xmm2, %xmm7
mulsd 0x48(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm9, %xmm7
movsd 0x10(%rbx), %xmm2
addsd %xmm3, %xmm5
mulsd 0xa1d0e(%rip), %xmm2    # 0xf83e0
movapd 0x88b56(%rip), %xmm0    # 0xdf230
xorpd %xmm5, %xmm0
mulsd %xmm6, %xmm0
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
subsd %xmm7, %xmm8
movapd %xmm7, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
divpd %xmm2, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm0, %xmm1
addsd %xmm6, %xmm1
unpcklpd %xmm1, %xmm8            # xmm8 = xmm8[0],xmm1[0]
divpd 0xa1d5c(%rip), %xmm2    # 0xf8470
divpd %xmm8, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movl 0x120(%rbx), %eax
movsd %xmm1, (%r12)
cmpl $0x1, %eax
je 0x567ba
xorl %ebp, %ebp
testl %eax, %eax
jne 0x568a8
movsd 0x130(%rbx), %xmm0
xorps 0x88add(%rip), %xmm0    # 0xdf230
movlps %xmm0, (%r14)
movsd 0x88b01(%rip), %xmm0    # 0xdf260
movsd 0x128(%rbx), %xmm1
addsd %xmm0, %xmm1
addsd 0x130(%rbx), %xmm1
movsd %xmm1, 0x10(%rsp)
divsd %xmm6, %xmm0
movsd %xmm6, 0x8(%rsp)
callq 0x82c0
movsd 0x8(%rsp), %xmm1
addsd 0x89052(%rip), %xmm1    # 0xdf7e8
mulsd 0x130(%rbx), %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
mulsd 0x89ed0(%rip), %xmm0    # 0xe0680
movsd %xmm0, (%r15)
jmp 0x568a8
movsd 0x8bd46(%rip), %xmm1    # 0xe2508
mulsd %xmm6, %xmm1
movsd 0x88a92(%rip), %xmm3    # 0xdf260
subsd %xmm7, %xmm3
movsd 0x89ea6(%rip), %xmm2    # 0xe0680
movapd %xmm5, %xmm4
divsd %xmm2, %xmm4
divsd %xmm3, %xmm4
divsd %xmm7, %xmm4
mulsd %xmm5, %xmm5
mulsd %xmm6, %xmm5
divsd %xmm2, %xmm5
unpcklpd %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0]
movapd 0x89f7e(%rip), %xmm5    # 0xe0780
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
divpd %xmm5, %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm1
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
divpd %xmm7, %xmm1
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm3, %xmm1
movapd %xmm0, %xmm3
divsd %xmm2, %xmm3
addsd %xmm6, %xmm0
divsd %xmm0, %xmm3
divsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd %xmm3, (%r14)
leaq 0xa232c(%rip), %rsi     # 0xf8b7a
leaq 0x8d0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x88d1e(%rip), %rsi     # 0xdf585
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
addq $0xb84, %rbx            # imm = 0xB84
leaq 0x887aa(%rip), %rsi     # 0xdf034
leaq 0xa22d8(%rip), %rdx     # 0xf8b69
movq %rbx, %rdi
movl $0x2e5, %ecx            # imm = 0x2E5
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebp
movl %ebp, %eax
addq $0x10d0, %rsp           # imm = 0x10D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq