// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/background.c
// Function: background_functions
int background_functions(
                         struct background * pba,
                         double a,
                         double * pvecback_B, /* vector with argument pvecback[index_bi] */
                         enum vecback_format return_format,
                         double * pvecback /* vector with argument pvecback[index_bg] (must be already allocated with a size compatible with return_format) */
                         ) {

  /** Summary: */

  /** - define local variables */

  /* total density */
  double rho_tot;

  /* critical density */
  double rho_crit;
  /* total pressure */
  double p_tot;
  /* total relativistic density */
  double rho_r;
  /* total non-relativistic density */
  double rho_m;
  /* background ncdm quantities */
  double rho_ncdm,p_ncdm,pseudo_p_ncdm;
  /* index for n_ncdm species */
  int n_ncdm;
  /* fluid's time-dependent equation of state parameter */
  double w_fld, dw_over_da, integral_fld;
  // short kg_fld_switch;
  /* scalar field quantities */
  double phi = 0, phi_prime = 0;
  //printf("Inside background_functions.\n");//print_trigger

  /* Since we only know a_prime_over_a after we have rho_tot,
     it is not possible to simply sum up p_tot_prime directly.
     Instead we sum up dp_dloga = p_prime/a_prime_over_a. The formula is
     p_prime = a_prime_over_a * dp_dloga = a_prime_over_a * Sum [ (w_prime/a_prime_over_a -3(1+w)w)rho].
     Note: The scalar field contribution must be added in the end, as an exception!*/
  double dp_dloga;

  /** - initialize local variables */
  rho_tot = 0.;
  p_tot = 0.;

  dp_dloga = 0.;
  rho_r=0.;
  rho_m=0.;

  class_test(a <= 0.,
             pba->error_message,
             "a = %e instead of strictly positive",a);

  /** - pass value of \f$ a\f$ to output */
  pvecback[pba->index_bg_a] = a;

  /** - compute each component's density and pressure */

  /* photons */
  pvecback[pba->index_bg_rho_g] = pba->Omega0_g * pow(pba->H0,2) / pow(a,4);
  rho_tot += pvecback[pba->index_bg_rho_g];
  p_tot += (1./3.) * pvecback[pba->index_bg_rho_g];
  dp_dloga += -(4./3.) * pvecback[pba->index_bg_rho_g];
  rho_r += pvecback[pba->index_bg_rho_g];

  /* baryons */
  pvecback[pba->index_bg_rho_b] = pba->Omega0_b * pow(pba->H0,2) / pow(a,3);
  rho_tot += pvecback[pba->index_bg_rho_b];
  p_tot += 0;
  rho_m += pvecback[pba->index_bg_rho_b];

  /* cdm */
  if (pba->has_cdm == _TRUE_) {
    pvecback[pba->index_bg_rho_cdm] = pba->Omega0_cdm * pow(pba->H0,2) / pow(a,3);
    rho_tot += pvecback[pba->index_bg_rho_cdm];
    p_tot += 0.;
    rho_m += pvecback[pba->index_bg_rho_cdm];
  }

  /* idm */
  if (pba->has_idm == _TRUE_) {
    pvecback[pba->index_bg_rho_idm] = pba->Omega0_idm * pow(pba->H0,2) / pow(a,3);
    rho_tot += pvecback[pba->index_bg_rho_idm];
    p_tot += 0.;
    rho_m += pvecback[pba->index_bg_rho_idm];
  }

  /* dcdm */
  if (pba->has_dcdm == _TRUE_) {
    /* Pass value of rho_dcdm to output */
    pvecback[pba->index_bg_rho_dcdm] = pvecback_B[pba->index_bi_rho_dcdm];
    rho_tot += pvecback[pba->index_bg_rho_dcdm];
    p_tot += 0.;
    rho_m += pvecback[pba->index_bg_rho_dcdm];
  }
  /* dr */
  if (pba->has_dr == _TRUE_) {
    /* Pass value of rho_dr to output */
    pvecback[pba->index_bg_rho_dr] = pvecback_B[pba->index_bi_rho_dr];
    rho_tot += pvecback[pba->index_bg_rho_dr];
    p_tot += (1./3.)*pvecback[pba->index_bg_rho_dr];
    dp_dloga += -(4./3.) * pvecback[pba->index_bg_rho_dr];
    rho_r += pvecback[pba->index_bg_rho_dr];
  }

    //printf("Scalar field? %f \n", pba->has_scf);//print_trigger
    /* Scalar field */
    if (pba->has_scf == _TRUE_ && pba->scf_kg_eq == _TRUE_) {

    pba->kg_fld_switch = _FALSE_;
    //printf("Inside scf table update\n"); //print_trigger
    phi = pvecback_B[pba->index_bi_phi_scf];
    phi_prime = pvecback_B[pba->index_bi_phi_prime_scf];
    //At this point phi and phi prime have already been updated, from their evolution equations, rho_scf is still from the last step,
    //The next few lines then calculate the new values for the density etc... from the new values of phi and phi prime
    pvecback[pba->index_bg_phi_scf] = phi; // value of the scalar field phi
    pvecback[pba->index_bg_phi_prime_scf] = phi_prime; // value of the scalar field phi derivative wrt conformal time
    pvecback[pba->index_bg_V_scf] = V_scf(pba,phi); //V_scf(pba,phi); //write here potential as function of phi
    pvecback[pba->index_bg_dV_scf] = dV_scf(pba,phi); // dV_scf(pba,phi); //potential' as function of phi
    pvecback[pba->index_bg_ddV_scf] = ddV_scf(pba,phi); // ddV_scf(pba,phi); //potential'' as function of phi
    pvecback[pba->index_bg_rho_scf] = (phi_prime*phi_prime/(2*a*a) + V_scf(pba,phi))/3.; // energy of the scalar field. The field units are set automatically by setting the initial conditions
    pvecback[pba->index_bg_p_scf] = (phi_prime*phi_prime/(2*a*a) - V_scf(pba,phi))/3.; // pressure of the scalar field

    pvecback[pba->index_bg_w_scf] =pvecback[pba->index_bg_p_scf]/pvecback[pba->index_bg_rho_scf]; // e.o.s of the scalar field, only used for outputs
    pvecback_B[pba->index_bi_rho_scf] = pvecback[pba->index_bg_rho_scf];

    rho_tot += pvecback[pba->index_bg_rho_scf];
    p_tot += pvecback[pba->index_bg_p_scf];
    dp_dloga += 0.0; /** <-- This depends on a_prime_over_a, so we cannot add it now! */

    rho_r += 3.*pvecback[pba->index_bg_p_scf]; //field pressure contributes radiation
    rho_m += pvecback[pba->index_bg_rho_scf] - 3.* pvecback[pba->index_bg_p_scf]; //the rest contributes matter

    if(pba->background_verbose>11) printf("here KG equation, a %e phi: %e, phi': %e rho_scf: %e \n", a, pvecback_B[pba->index_bi_phi_scf], pvecback_B[pba->index_bi_phi_prime_scf], pvecback[pba->index_bg_rho_scf]);

  }
  else if(pba->has_scf == _TRUE_ &&  pba->scf_kg_eq == _FALSE_){
    // phi = pvecback[pba->index_bg_phi_scf]; //phi is frozen to its last value.
    phi = pvecback_B[pba->index_bi_phi_scf];
    phi_prime = pvecback_B[pba->index_bi_phi_prime_scf];
    /*** WE STORE THESE DUMMY QUANTITIES ANYWAY ***/
    pvecback[pba->index_bg_phi_scf] = phi; // value of the scalar field phi
    pvecback[pba->index_bg_phi_prime_scf] = phi_prime; // value of the scalar field phi derivative wrt conformal time
    pvecback[pba->index_bg_V_scf] = V_scf(pba,phi); //V_scf(pba,phi); //write here potential as function of phi
    pvecback[pba->index_bg_dV_scf] = dV_scf(pba,phi); // dV_scf(pba,phi); //potential' as function of phi
    pvecback[pba->index_bg_ddV_scf] = ddV_scf(pba,phi); // ddV_scf(pba,phi); //potential'' as function of phi

    if(pba->kg_fld_switch == _FALSE_){
      pba->kg_fld_switch = _TRUE_;
      //if we just switched from KG to fluid, we need to correctly initialize the density.
      pvecback_B[pba->index_bi_rho_scf] = (phi_prime*phi_prime/(2*a*a) + V_scf(pba,phi))/3.;
    }
    /****THE REAL QUANTITIES ARE ASSIGNED HERE****/
    //pvecback[pba->index_bg_rho_scf] = pba->Omega0_scf * pow(pba->H0,2) / pow(a_rel,3);

    pvecback[pba->index_bg_rho_scf] = pvecback_B[pba->index_bi_rho_scf];
    pvecback[pba->index_bg_p_scf] = pba->w_scf*pvecback_B[pba->index_bi_rho_scf];
    if(pba->log10_axion_ac > -30){
      /* approximate fluid equation of state for the axion */
      pvecback[pba->index_bg_w_scf] = (1+pba->w_scf)/(1+pow(pba->a_c/a,3*(1+pba->w_scf)))-1;
    }
    else{
      pvecback[pba->index_bg_w_scf] = pba->w_scf;
    }


      rho_tot += pvecback[pba->index_bg_rho_scf];
      p_tot += pvecback[pba->index_bg_p_scf];
      rho_r += 3.*pvecback[pba->index_bg_p_scf]; //field pressure contributes radiation
      rho_m += pvecback[pba->index_bg_rho_scf] - 3.* pvecback[pba->index_bg_p_scf]; //the rest contributes matter

    if(pba->background_verbose>11) printf("now fluid equation H %e p %e rho %e \n",3*pvecback[pba->index_bg_H],pvecback[pba->index_bg_p_scf],pvecback[pba->index_bg_rho_scf]);

  }
  //printf("Scalar field? %f \n", pba->has_scf); //print_trigger


  /* ncdm */
  if (pba->has_ncdm == _TRUE_) {

    /* Loop over species: */
    for (n_ncdm=0; n_ncdm<pba->N_ncdm; n_ncdm++) {

      /* function returning background ncdm[n_ncdm] quantities (only
         those for which non-NULL pointers are passed) */
      class_call(background_ncdm_momenta(
                                         pba->q_ncdm_bg[n_ncdm],
                                         pba->w_ncdm_bg[n_ncdm],
                                         pba->q_size_ncdm_bg[n_ncdm],
                                         pba->M_ncdm[n_ncdm],
                                         pba->factor_ncdm[n_ncdm],
                                         1./a-1.,
                                         NULL,
                                         &rho_ncdm,
                                         &p_ncdm,
                                         NULL,
                                         &pseudo_p_ncdm),
                 pba->error_message,
                 pba->error_message);

      pvecback[pba->index_bg_rho_ncdm1+n_ncdm] = rho_ncdm;
      rho_tot += rho_ncdm;
      pvecback[pba->index_bg_p_ncdm1+n_ncdm] = p_ncdm;
      p_tot += p_ncdm;
      pvecback[pba->index_bg_pseudo_p_ncdm1+n_ncdm] = pseudo_p_ncdm;
      /** See e.g. Eq. A6 in 1811.00904. */
      dp_dloga += (pseudo_p_ncdm - 5*p_ncdm);

      /* (3 p_ncdm1) is the "relativistic" contribution to rho_ncdm1 */
      rho_r += 3.* p_ncdm;

      /* (rho_ncdm1 - 3 p_ncdm1) is the "non-relativistic" contribution
         to rho_ncdm1 */
      rho_m += rho_ncdm - 3.* p_ncdm;
    }
  }

  /* Lambda */
  if (pba->has_lambda == _TRUE_) {
    pvecback[pba->index_bg_rho_lambda] = pba->Omega0_lambda * pow(pba->H0,2);
    rho_tot += pvecback[pba->index_bg_rho_lambda];
    p_tot -= pvecback[pba->index_bg_rho_lambda];
  }

  /* fluid with w(a) and constant cs2 */
  /* or whatever other fluid species you have defined under background_w_fld */
  if (pba->has_fld == _TRUE_) {

    /* get rho_fld from vector of integrated variables */
    pvecback[pba->index_bg_rho_fld] = pvecback_B[pba->index_bi_rho_fld];

    /* get w_fld from dedicated function */
    class_call(background_w_fld(pba,a,&w_fld,&dw_over_da,&integral_fld), pba->error_message, pba->error_message);
    pvecback[pba->index_bg_w_fld] = w_fld;

    // Obsolete: at the beginning, we had here the analytic integral solution corresponding to the case w=w0+w1(1-a/a0):
    // pvecback[pba->index_bg_rho_fld] = pba->Omega0_fld * pow(pba->H0,2) / pow(a,3.*(1.+pba->w0_fld+pba->wa_fld)) * exp(3.*pba->wa_fld*(a-1.));
    // But now everthing is integrated numerically for a given w_fld(a) defined in the function background_w_fld.
    // printf("pvecback[pba->index_bg_rho_fld] %e\n", pvecback[pba->index_bg_rho_fld]);
    rho_tot += pvecback[pba->index_bg_rho_fld];
    p_tot += w_fld * pvecback[pba->index_bg_rho_fld];
    dp_dloga += (a*dw_over_da-3*(1+w_fld)*w_fld)*pvecback[pba->index_bg_rho_fld];

    // printf("w_fld %e\n", w_fld);
    if(w_fld>0){
      rho_m += pvecback[pba->index_bg_rho_fld] - 3.* w_fld * pvecback[pba->index_bg_rho_fld]; //the rest contributes matter
      rho_r += 3.* w_fld * pvecback[pba->index_bg_rho_fld]; //the rest contributes matter
      // printf("w_fld %e pvecback[pba->index_bg_rho_fld] - 3.* w_fld * pvecback[pba->index_bg_rho_fld] %e\n", w_fld,pvecback[pba->index_bg_rho_fld] - 3.* w_fld * pvecback[pba->index_bg_rho_fld]);
    }
  }

  /* relativistic neutrinos (and all relativistic relics) */
  if (pba->has_ur == _TRUE_) {
    pvecback[pba->index_bg_rho_ur] = pba->Omega0_ur * pow(pba->H0,2) / pow(a,4);
    rho_tot += pvecback[pba->index_bg_rho_ur];
    p_tot += (1./3.) * pvecback[pba->index_bg_rho_ur];
    dp_dloga += -(4./3.) * pvecback[pba->index_bg_rho_ur];
    rho_r += pvecback[pba->index_bg_rho_ur];
  }

  /* interacting dark radiation */
  if (pba->has_idr == _TRUE_) {
    pvecback[pba->index_bg_rho_idr] = pba->Omega0_idr * pow(pba->H0,2) / pow(a,4);
    rho_tot += pvecback[pba->index_bg_rho_idr];
    p_tot += (1./3.) * pvecback[pba->index_bg_rho_idr];
    rho_r += pvecback[pba->index_bg_rho_idr];
  }

  /** - compute expansion rate H from Friedmann equation: this is the
      only place where the Friedmann equation is assumed. Remember
      that densities are all expressed in units of \f$ [3c^2/8\pi G] \f$, ie
      \f$ \rho_{class} = [8 \pi G \rho_{physical} / 3 c^2]\f$ */
  pvecback[pba->index_bg_H] = sqrt(rho_tot-pba->K/a/a);

  /** - compute derivative of H with respect to conformal time */
  pvecback[pba->index_bg_H_prime] = - (3./2.) * (rho_tot + p_tot) * a + pba->K/a;

  if(pba->has_scf == _TRUE_){
    pvecback[pba->index_bg_Omega_scf] = pvecback[pba->index_bg_rho_scf] / rho_tot;
  }

  /* Total energy density*/
  pvecback[pba->index_bg_rho_tot] = rho_tot;

  /* Total pressure */
  pvecback[pba->index_bg_p_tot] = p_tot;

  /* Derivative of total pressure w.r.t. conformal time */
  pvecback[pba->index_bg_p_tot_prime] = a*pvecback[pba->index_bg_H]*dp_dloga;
  if (pba->has_scf == _TRUE_) {
    /** The contribution of scf was not added to dp_dloga, add p_scf_prime here: */
    pvecback[pba->index_bg_p_prime_scf] = pvecback[pba->index_bg_phi_prime_scf]*
      (-pvecback[pba->index_bg_phi_prime_scf]*pvecback[pba->index_bg_H]/a-2./3.*pvecback[pba->index_bg_dV_scf]);
    pvecback[pba->index_bg_p_tot_prime] += pvecback[pba->index_bg_p_prime_scf];
  }

  /** - compute critical density */
  rho_crit = rho_tot-pba->K/a/a;

  class_test(rho_crit <= 0.,
             pba->error_message,
             "rho_crit = %e instead of strictly positive",rho_crit);

  /** - compute relativistic density to total density ratio */
  pvecback[pba->index_bg_Omega_r] = rho_r / rho_crit;

  /** - compute other quantities in the exhaustive, redundant format */
  if (return_format == long_info) {

    /** - store critical density */
    pvecback[pba->index_bg_rho_crit] = rho_crit;

    /** - compute Omega_m */
    pvecback[pba->index_bg_Omega_m] = rho_m / rho_crit;

    /** - cosmological time */
    pvecback[pba->index_bg_time] = pvecback_B[pba->index_bi_time];

    /** - comoving sound horizon */
    pvecback[pba->index_bg_rs] = pvecback_B[pba->index_bi_rs];

    /** - growth factor */
    pvecback[pba->index_bg_D] = pvecback_B[pba->index_bi_D];

    /** - velocity growth factor */
    pvecback[pba->index_bg_f] = pvecback_B[pba->index_bi_D_prime]/( pvecback_B[pba->index_bi_D]*a*pvecback[pba->index_bg_H]);

    /**- Varying fundamental constants */
    if (pba->has_varconst == _TRUE_) {
      class_call(background_varconst_of_z(pba,
                                          1./a-1.,
                                          &(pvecback[pba->index_bg_varc_alpha]),
                                          &(pvecback[pba->index_bg_varc_me])
                                          ),
                 pba->error_message,
                 pba->error_message);
    }

    /* one can put other variables here */
    /*  */
    /*  */

    /** - compute and store fractional energy density of fluid
          to later calculate the location of the peak of f_EDE */
    // if( (pba->has_fld == _TRUE_) && ((pba->fluid_equation_of_state == EDE) && (pba->ede_parametrization == pheno_axion)) ){
    if( (pba->has_fld == _TRUE_)){
      // TK ????????? do we want to make this only for the pheno_axion case of EDE?
      pvecback[pba->index_bg_Omega_fld] = pvecback[pba->index_bg_rho_fld] / rho_tot;
    }


  }

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10a8, %rsp           # imm = 0x10A8
movq %rdi, %rbx
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jae 0x590c6
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r15
movslq 0x380(%rbx), %rax
movsd %xmm0, (%rcx,%rax,8)
movsd (%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0x10(%rbx), %xmm1
movapd %xmm1, 0x20(%rsp)
movsd 0x8f753(%rip), %xmm1    # 0xe83f8
movsd %xmm0, 0x8(%rsp)
callq 0x8650
movapd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x38c(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
movapd %xmm1, %xmm0
addsd 0x8c585(%rip), %xmm0    # 0xe5258
movapd %xmm0, 0x50(%rsp)
movsd 0x8f727(%rip), %xmm0    # 0xe8408
movapd %xmm1, 0x20(%rsp)
mulsd %xmm1, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd (%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x20(%rbx), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x8da3c(%rip), %xmm1    # 0xe6748
movsd 0x8(%rsp), %xmm0
callq 0x8650
movapd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
movslq 0x390(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
xorpd %xmm3, %xmm3
unpcklpd 0x50(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
addpd %xmm1, %xmm3
cmpw $0x1, 0x4b4(%rbx)
jne 0x58d9b
movsd (%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0x28(%rbx), %xmm1
movapd %xmm1, 0x40(%rsp)
movsd 0x8d9dd(%rip), %xmm1    # 0xe6748
movapd %xmm3, 0x30(%rsp)
callq 0x8650
movapd 0x30(%rsp), %xmm3
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x394(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
addpd %xmm1, %xmm3
xorpd %xmm1, %xmm1
movapd 0x10(%rsp), %xmm2
addsd %xmm1, %xmm2
movapd 0x20(%rsp), %xmm5
mulsd 0xa8b89(%rip), %xmm5    # 0x101940
cmpw $0x1, 0x4b6(%rbx)
jne 0x58e31
movsd (%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0xf0(%rbx), %xmm0
movapd %xmm0, 0x40(%rsp)
movsd 0x8d969(%rip), %xmm1    # 0xe6748
movsd 0x8(%rsp), %xmm0
movapd %xmm3, 0x30(%rsp)
movapd %xmm5, 0x20(%rsp)
movapd %xmm2, 0x10(%rsp)
callq 0x8650
movapd 0x10(%rsp), %xmm2
xorpd %xmm1, %xmm1
movapd 0x20(%rsp), %xmm5
movapd 0x30(%rsp), %xmm3
movapd 0x40(%rsp), %xmm4
divsd %xmm0, %xmm4
movslq 0x398(%rbx), %rax
movsd %xmm4, (%r14,%rax,8)
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
addpd %xmm4, %xmm3
addsd %xmm1, %xmm5
addsd %xmm1, %xmm2
cmpw $0x1, 0x4b8(%rbx)
jne 0x58e65
movslq 0x480(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movslq 0x3b4(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
addpd %xmm0, %xmm3
cmpw $0x1, 0x4ba(%rbx)
unpcklpd %xmm2, %xmm5            # xmm5 = xmm5[0],xmm2[0]
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
jne 0x58eb9
movslq 0x484(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
movslq 0x3b8(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
addsd %xmm1, %xmm0
movapd 0x50(%rsp), %xmm2
addsd %xmm1, %xmm2
movapd %xmm2, 0x50(%rsp)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd 0xa8b3b(%rip), %xmm1    # 0x1019f0
addpd %xmm1, %xmm5
cmpw $0x1, 0x4bc(%rbx)
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
jne 0x59384
movzwl 0x230(%rbx), %eax
testl %eax, %eax
je 0x59124
cmpl $0x1, %eax
jne 0x59384
andw $0x0, 0x232(%rbx)
movslq 0x490(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0x494(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
movsd %xmm1, 0x40(%rsp)
movslq 0x3bc(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movslq 0x3c0(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
movq %rbx, %rdi
movapd %xmm3, 0x30(%rsp)
movapd %xmm5, 0x20(%rsp)
callq 0x59b15
movslq 0x3c4(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59bed
movslq 0x3c8(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59d41
movslq 0x3cc(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movsd 0x40(%rsp), %xmm2
mulsd %xmm2, %xmm2
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x40(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59b15
addsd 0x40(%rsp), %xmm0
movsd 0x8d784(%rip), %xmm1    # 0xe6748
divsd %xmm1, %xmm0
movslq 0x3d0(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59b15
movapd 0x20(%rsp), %xmm5
movsd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8d74d(%rip), %xmm2    # 0xe6748
divsd %xmm2, %xmm1
movslq 0x3d8(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
movslq 0x3d0(%rbx), %rcx
divsd (%r14,%rcx,8), %xmm1
movslq 0x3e0(%rbx), %rdx
movsd %xmm1, (%r14,%rdx,8)
movsd (%r14,%rcx,8), %xmm3
movslq 0x48c(%rbx), %rcx
movsd %xmm3, (%r15,%rcx,8)
movsd (%r14,%rax,8), %xmm0
xorpd %xmm1, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
addpd %xmm1, %xmm5
movapd %xmm0, %xmm1
mulsd %xmm2, %xmm1
addsd 0x50(%rsp), %xmm1
movapd %xmm1, 0x50(%rsp)
mulsd 0x8f3d9(%rip), %xmm0    # 0xe8440
addsd %xmm3, %xmm0
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
movapd 0x30(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
cmpw $0xc, 0xd1a(%rbx)
jl 0x5937e
movslq 0x490(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
movslq 0x494(%rbx), %rax
movsd (%r15,%rax,8), %xmm2
leaq 0xa8f9e(%rip), %rdi     # 0x10204c
movsd 0x8(%rsp), %xmm0
movb $0x4, %al
movapd %xmm5, 0x20(%rsp)
callq 0x8030
jmp 0x59378
leaq 0xa8f3e(%rip), %rsi     # 0x10200b
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x2e014
leaq 0x8bf9c(%rip), %rsi     # 0xe5082
leaq 0xa8f42(%rip), %rdx     # 0x10202f
leaq 0x8a0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8bf24(%rip), %rsi     # 0xe5034
leaq 0xa8f20(%rip), %rdx     # 0x102037
movq %rbx, %rdi
movl $0x1a8, %ecx            # imm = 0x1A8
jmp 0x59a32
movapd %xmm5, 0x20(%rsp)
movapd %xmm3, 0x30(%rsp)
movslq 0x490(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0x494(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
movslq 0x3bc(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movslq 0x3c0(%rbx), %rax
movsd %xmm1, 0x40(%rsp)
movsd %xmm1, (%r14,%rax,8)
movq %rbx, %rdi
callq 0x59b15
movslq 0x3c4(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59bed
movslq 0x3c8(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59d41
movslq 0x3cc(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
cmpw $0x0, 0x232(%rbx)
je 0x591d4
movslq 0x48c(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
jmp 0x5922c
movw $0x1, 0x232(%rbx)
movsd 0x40(%rsp), %xmm2
mulsd %xmm2, %xmm2
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x40(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x59b15
addsd 0x40(%rsp), %xmm0
divsd 0x8d529(%rip), %xmm0    # 0xe6748
movslq 0x48c(%rbx), %rcx
movsd %xmm0, (%r15,%rcx,8)
movslq 0x3d0(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movsd 0x218(%rbx), %xmm0
mulsd (%r15,%rcx,8), %xmm0
movslq 0x3d8(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movsd 0x1b8(%rbx), %xmm0
movsd 0x218(%rbx), %xmm1
ucomisd 0x907c4(%rip), %xmm0    # 0xe9a30
jbe 0x592d6
addsd 0x8bfea(%rip), %xmm1    # 0xe5260
movsd 0x1c8(%rbx), %xmm0
divsd 0x8(%rsp), %xmm0
movapd %xmm1, %xmm2
movsd %xmm1, 0x10(%rsp)
movsd 0x8d4b2(%rip), %xmm1    # 0xe6748
mulsd %xmm2, %xmm1
callq 0x8650
addsd 0x8bfb9(%rip), %xmm0    # 0xe5260
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
addsd 0x8c52f(%rip), %xmm1    # 0xe57e8
movslq 0x3e0(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
movslq 0x3d0(%rbx), %rax
movslq 0x3d8(%rbx), %rcx
jmp 0x592e3
movslq 0x3e0(%rbx), %rdx
movsd %xmm1, (%r14,%rdx,8)
movapd 0x20(%rsp), %xmm5
movsd (%r14,%rax,8), %xmm2
movsd (%r14,%rcx,8), %xmm1
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
addsd %xmm1, %xmm0
movsd 0x8d43f(%rip), %xmm3    # 0xe6748
mulsd %xmm1, %xmm3
addsd 0x50(%rsp), %xmm3
movapd %xmm3, 0x50(%rsp)
movsd 0x8f11f(%rip), %xmm3    # 0xe8440
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
movapd 0x30(%rsp), %xmm4
addpd %xmm3, %xmm4
movapd %xmm4, %xmm3
cmpw $0xc, 0xd1a(%rbx)
unpcklpd %xmm0, %xmm5            # xmm5 = xmm5[0],xmm0[0]
jl 0x59384
movslq 0x384(%rbx), %rax
movsd (%r14,%rax,8), %xmm0
mulsd 0x8d3ea(%rip), %xmm0    # 0xe6748
leaq 0xa8d1e(%rip), %rdi     # 0x102083
movb $0x3, %al
movapd %xmm3, 0x30(%rsp)
movapd %xmm5, 0x20(%rsp)
callq 0x8030
movapd 0x20(%rsp), %xmm5
movapd 0x30(%rsp), %xmm3
cmpw $0x1, 0x4be(%rbx)
jne 0x594fb
movapd %xmm5, 0x20(%rsp)
movapd %xmm3, 0x30(%rsp)
movl %ebp, 0x68(%rsp)
movq %r15, 0x40(%rsp)
movsd 0x8beb1(%rip), %xmm1    # 0xe5260
movsd 0x8(%rsp), %xmm0
divsd %xmm0, %xmm1
addsd 0x8c427(%rip), %xmm1    # 0xe57e8
movsd %xmm1, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x80(%rsp), %r15
leaq 0x90(%rsp), %r12
leaq 0x88(%rsp), %r13
movslq 0x248(%rbx), %rax
cmpq %rax, %rbp
jge 0x59503
movq 0x4d8(%rbx), %rax
movq (%rax,%rbp,8), %rdi
movq 0x4e0(%rbx), %rax
movq (%rax,%rbp,8), %rsi
movq 0x500(%rbx), %rax
movl (%rax,%rbp,4), %edx
movq 0x270(%rbx), %rax
movsd (%rax,%rbp,8), %xmm0
movq 0x510(%rbx), %rax
movsd (%rax,%rbp,8), %xmm1
movsd 0x10(%rsp), %xmm2
xorl %ecx, %ecx
movq %r12, %r8
movq %r13, %r9
pushq %r15
pushq $0x0
callq 0x59e8b
popq %rcx
popq %rdx
movsd 0x90(%rsp), %xmm4
movslq 0x3ec(%rbx), %rax
addq %rbp, %rax
movsd %xmm4, (%r14,%rax,8)
movsd 0x88(%rsp), %xmm1
movslq 0x3f0(%rbx), %rax
addq %rbp, %rax
movsd %xmm1, (%r14,%rax,8)
movsd 0x80(%rsp), %xmm2
movslq 0x3f4(%rbx), %rax
addq %rbp, %rax
movsd %xmm2, (%r14,%rax,8)
movapd %xmm1, %xmm3
mulsd 0xa84af(%rip), %xmm3    # 0x101948
addsd %xmm2, %xmm3
unpcklpd %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
movapd 0x20(%rsp), %xmm0
addpd %xmm3, %xmm0
movapd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
movapd %xmm1, %xmm2
mulsd 0x8d285(%rip), %xmm2    # 0xe6748
movapd 0x50(%rsp), %xmm3
addsd %xmm2, %xmm3
movapd %xmm3, 0x50(%rsp)
mulsd 0x8ef65(%rip), %xmm1    # 0xe8440
addsd %xmm4, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
movapd 0x30(%rsp), %xmm2
addpd %xmm1, %xmm2
movapd %xmm2, 0x30(%rsp)
incq %rbp
jmp 0x593e1
movsd 0x8(%rsp), %xmm0
jmp 0x59518
movq 0x40(%rsp), %r15
movl 0x68(%rsp), %ebp
movapd 0x30(%rsp), %xmm3
movapd 0x20(%rsp), %xmm5
cmpw $0x1, 0x4c0(%rbx)
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
jne 0x59554
movsd (%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0x30(%rbx), %xmm1
movslq 0x39c(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
addsd %xmm1, %xmm4
subsd %xmm1, %xmm6
cmpw $0x1, 0x4c2(%rbx)
jne 0x595fe
movapd %xmm6, 0x40(%rsp)
movapd %xmm4, 0x10(%rsp)
movapd %xmm5, 0x20(%rsp)
movapd %xmm3, 0x30(%rsp)
movslq 0x488(%rbx), %rax
movsd (%r15,%rax,8), %xmm1
movslq 0x3a0(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
leaq 0x78(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x98(%rsp), %rcx
movq %rbx, %rdi
callq 0x5a0e7
testl %eax, %eax
je 0x59a55
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8be2c(%rip), %rsi     # 0xe53f0
leaq 0xa8ade(%rip), %rdx     # 0x1020a9
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x8ba4d(%rip), %rsi     # 0xe5034
leaq 0xa8a49(%rip), %rdx     # 0x102037
movq %rbx, %rdi
movl $0x25d, %ecx            # imm = 0x25D
movq %r14, %r8
jmp 0x59a35
movsd %xmm5, 0x40(%rsp)
cmpw $0x1, 0x4c4(%rbx)
movapd %xmm3, 0x30(%rsp)
jne 0x596a6
movsd (%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0xe8(%rbx), %xmm1
movsd %xmm1, 0x68(%rsp)
movsd 0x8edc2(%rip), %xmm1    # 0xe83f8
movapd %xmm4, 0x10(%rsp)
movsd %xmm6, 0x20(%rsp)
callq 0x8650
movsd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movsd 0x68(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x3ac(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
addsd %xmm1, %xmm4
movsd 0x8ed92(%rip), %xmm0    # 0xe8408
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm6
movapd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0x50(%rsp)
mulsd 0xa82aa(%rip), %xmm1    # 0x101940
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
cmpw $0x1, 0x4c6(%rbx)
jne 0x59734
movsd (%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0xf8(%rbx), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x8ed26(%rip), %xmm1    # 0xe83f8
movsd 0x8(%rsp), %xmm0
movapd %xmm4, 0x10(%rsp)
movsd %xmm6, 0x20(%rsp)
callq 0x8650
movsd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movsd 0x68(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x3b0(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
addsd %xmm1, %xmm4
movapd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0x50(%rsp)
mulsd 0x8ecda(%rip), %xmm1    # 0xe8408
addsd %xmm1, %xmm6
jmp 0x5973a
movsd 0x8(%rsp), %xmm3
movsd 0x318(%rbx), %xmm1
divsd %xmm3, %xmm1
divsd %xmm3, %xmm1
movapd %xmm4, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x59762
sqrtsd %xmm0, %xmm0
jmp 0x59785
movapd %xmm4, 0x10(%rsp)
movsd %xmm6, 0x20(%rsp)
callq 0x82d0
movsd 0x20(%rsp), %xmm6
movapd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movslq 0x384(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
movapd %xmm4, %xmm0
addsd %xmm6, %xmm0
mulsd 0x8f02e(%rip), %xmm0    # 0xe87d0
movsd 0x318(%rbx), %xmm1
divsd %xmm3, %xmm1
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movslq 0x388(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movzwl 0x4bc(%rbx), %edx
cmpw $0x1, %dx
jne 0x597ee
movslq 0x3d0(%rbx), %rcx
movsd (%r14,%rcx,8), %xmm0
divsd %xmm4, %xmm0
movslq 0x3d4(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movslq 0x3f8(%rbx), %rcx
movsd %xmm4, (%r14,%rcx,8)
movslq 0x3fc(%rbx), %rcx
movsd %xmm6, (%r14,%rcx,8)
movsd (%r14,%rax,8), %xmm0
mulsd %xmm3, %xmm0
movsd 0x40(%rsp), %xmm1
mulsd %xmm0, %xmm1
movslq 0x400(%rbx), %rcx
movsd %xmm1, (%r14,%rcx,8)
cmpw $0x1, %dx
jne 0x59880
movslq 0x3c0(%rbx), %rdx
movsd (%r14,%rdx,8), %xmm0
movsd (%r14,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movslq 0x3c8(%rbx), %rdx
movsd (%r14,%rdx,8), %xmm2
mulsd 0x8ec65(%rip), %xmm2    # 0xe84c0
divsd %xmm3, %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
movslq 0x3dc(%rbx), %rdx
movsd %xmm2, (%r14,%rdx,8)
addsd (%r14,%rcx,8), %xmm2
movsd %xmm2, (%r14,%rcx,8)
movsd 0x318(%rbx), %xmm1
divsd %xmm3, %xmm1
divsd %xmm3, %xmm1
movapd %xmm4, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jae 0x599d9
movapd 0x50(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x404(%rbx), %rcx
movsd %xmm1, (%r14,%rcx,8)
xorl %r12d, %r12d
cmpl $0x2, %ebp
jne 0x59a40
movslq 0x408(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movapd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
movslq 0x40c(%rbx), %rcx
movsd %xmm1, (%r14,%rcx,8)
movslq 0x498(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
movslq 0x41c(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movslq 0x49c(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
movslq 0x420(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movslq 0x4a4(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm0
movslq 0x424(%rbx), %rcx
movsd %xmm0, (%r14,%rcx,8)
movslq 0x4a8(%rbx), %rcx
movsd (%r15,%rcx,8), %xmm1
mulsd %xmm3, %xmm0
mulsd (%r14,%rax,8), %xmm0
divsd %xmm0, %xmm1
movslq 0x428(%rbx), %rax
movsd %xmm1, (%r14,%rax,8)
cmpw $0x1, 0x4ca(%rbx)
jne 0x599ab
movsd 0x8b8eb(%rip), %xmm0    # 0xe5260
divsd %xmm3, %xmm0
addsd 0x8be67(%rip), %xmm0    # 0xe57e8
movslq 0x42c(%rbx), %rax
leaq (%r14,%rax,8), %rsi
movslq 0x430(%rbx), %rax
leaq (%r14,%rax,8), %rdx
movq %rbx, %rdi
movapd %xmm4, 0x10(%rsp)
callq 0x5a991
movapd 0x10(%rsp), %xmm4
cmpw $0x1, 0x4c2(%rbx)
jne 0x59a40
movslq 0x3a0(%rbx), %rax
movsd (%r14,%rax,8), %xmm0
divsd %xmm4, %xmm0
movslq 0x3a8(%rbx), %rax
movsd %xmm0, (%r14,%rax,8)
jmp 0x59a40
leaq 0xa8702(%rip), %rsi     # 0x1020e2
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movb $0x1, %al
callq 0x2e014
leaq 0x8b689(%rip), %rsi     # 0xe5082
leaq 0xa870d(%rip), %rdx     # 0x10210d
leaq 0x8a0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0xd1c, %rbx            # imm = 0xD1C
leaq 0x8b611(%rip), %rsi     # 0xe5034
leaq 0xa860d(%rip), %rdx     # 0x102037
movq %rbx, %rdi
movl $0x2a2, %ecx            # imm = 0x2A2
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %r12
movl %r12d, %eax
addq $0x10a8, %rsp           # imm = 0x10A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x78(%rsp), %xmm3
movslq 0x3a4(%rbx), %rax
movsd %xmm3, (%r14,%rax,8)
movslq 0x3a0(%rbx), %rax
movsd (%r14,%rax,8), %xmm1
movapd 0x10(%rsp), %xmm4
addsd %xmm1, %xmm4
movapd %xmm3, %xmm6
mulsd %xmm1, %xmm6
addsd 0x40(%rsp), %xmm6
movsd 0x8b7cb(%rip), %xmm2    # 0xe5260
addsd %xmm3, %xmm2
mulsd 0x8e99f(%rip), %xmm2    # 0xe8440
mulsd %xmm3, %xmm2
movsd 0x70(%rsp), %xmm0
movsd 0x8(%rsp), %xmm5
mulsd %xmm5, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm3
movapd %xmm5, %xmm0
jbe 0x59b0a
mulsd 0x8cc69(%rip), %xmm3    # 0xe6748
mulsd %xmm1, %xmm3
subsd %xmm3, %xmm1
movapd 0x30(%rsp), %xmm2
addsd %xmm1, %xmm2
movapd 0x50(%rsp), %xmm1
addsd %xmm3, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm2, %xmm3
jmp 0x59604
movapd 0x30(%rsp), %xmm3
jmp 0x59604