// File: /workspace/github_c_makefile_star2_O3/lesgourg[P]class_public/build/../source/input.c
// Function: input_get_guess
int input_get_guess(double *xguess,
                    double *dxdy,
                    struct fzerofun_workspace * pfzw,
                    ErrorMsg errmsg){

  /** Summary: */

  /** Define local variables */
  struct precision pr;        /* for precision parameters */
  struct background ba;       /* for cosmological background */
  struct thermodynamics th;           /* for thermodynamics */
  struct perturbations pt;         /* for source functions */
  struct transfer tr;        /* for transfer functions */
  struct primordial pm;       /* for primordial spectra */
  struct harmonic hr;          /* for output spectra */
  struct fourier fo;        /* for non-linear spectra */
  struct lensing le;          /* for lensed spectra */
  struct distortions sd;      /* for spectral distortions */
  struct output op;           /* for output files */
  int i;
  double Omega_M, a_decay, gamma, Omega0_dcdmdr=1.0;
  int index_guess;
  int index_ncdm; double N_nonur_guess = 0.0;

  /* Cheat to read only known parameters: */
  pfzw->fc.size -= pfzw->target_size;

  /* Assume for now shooting did not fail */
  ba.shooting_failed = _FALSE_;

  class_call(input_read_precisions(&(pfzw->fc),&pr,&ba,&th,&pt,&tr,&pm,&hr,&fo,&le,&sd,&op,
                                   errmsg),
             errmsg,
             errmsg);
  class_call(input_read_parameters(&(pfzw->fc),&pr,&ba,&th,&pt,&tr,&pm,&hr,&fo,&le,&sd,&op,
                                   errmsg),
             errmsg,
             errmsg);

  pfzw->fc.size += pfzw->target_size;

  /** Estimate dxdy */
  for (index_guess=0; index_guess < pfzw->target_size; index_guess++) {
    switch (pfzw->target_name[index_guess]) {
    case theta_s:
    case theta_s_100:
      xguess[index_guess] = 3.54*pow(pfzw->target_value[index_guess],2)-5.455*pfzw->target_value[index_guess]+2.548;
      dxdy[index_guess] = (7.08*pfzw->target_value[index_guess]-5.455);
      /** Update pb to reflect guess */
      ba.h = xguess[index_guess];
      ba.H0 = ba.h *  1.e5 / _c_;
      break;
    case Neff:
      for(index_ncdm=0;index_ncdm<ba.N_ncdm;++index_ncdm){
        N_nonur_guess += ba.deg_ncdm[index_ncdm]* 1.0132;
      }
      N_nonur_guess += ba.Omega0_idr/ba.Omega0_g/(7./8.)*pow(11./4.,(4./3.));
      xguess[index_guess] = pfzw->target_value[index_guess] - N_nonur_guess;
      dxdy[index_guess] = 1.;
      break;
    case Omega_dcdmdr:
      Omega_M = ba.Omega0_cdm+ba.Omega0_idm+ba.Omega0_dcdmdr+ba.Omega0_b;
      /* *
       * This formula is exact in a Matter + Lambda Universe, but only for Omega_dcdm,
       * not the combined.
       * sqrt_one_minus_M = sqrt(1.0 - Omega_M);
       * xguess[index_guess] = pfzw->target_value[index_guess]*
       *                       exp(2./3.*ba.Gamma_dcdm/ba.H0*
       *                       atanh(sqrt_one_minus_M)/sqrt_one_minus_M);
       * dxdy[index_guess] = 1.0;//exp(2./3.*ba.Gamma_dcdm/ba.H0*atanh(sqrt_one_minus_M)/sqrt_one_minus_M);
       * */
      gamma = ba.Gamma_dcdm/ba.H0;
      if (gamma < 1)
        a_decay = 1.0;
      else
        a_decay = pow(1+(gamma*gamma-1.)/Omega_M,-1./3.);
      xguess[index_guess] = pfzw->target_value[index_guess]/a_decay;
      dxdy[index_guess] = 1./a_decay;
      break;
    case omega_dcdmdr:
      Omega_M = ba.Omega0_cdm+ba.Omega0_idm+ba.Omega0_dcdmdr+ba.Omega0_b;
      gamma = ba.Gamma_dcdm/ba.H0;
      if (gamma < 1)
        a_decay = 1.0;
      else
        a_decay = pow(1+(gamma*gamma-1.)/Omega_M,-1./3.);
      xguess[index_guess] = pfzw->target_value[index_guess]/ba.h/ba.h/a_decay;
      dxdy[index_guess] = 1./a_decay/ba.h/ba.h;
      break;
    case Omega_scf:
      /* *
       * This guess is arbitrary, something nice using WKB should be implemented.
       * Version 2 uses a fit
       * xguess[index_guess] = 1.77835*pow(ba.Omega0_scf,-2./7.);
       * dxdy[index_guess] = -0.5081*pow(ba.Omega0_scf,-9./7.)`;
       * Version 3: use attractor solution
       * */
      if (ba.scf_tuning_index == 0){
        xguess[index_guess] = sqrt(3.0/ba.Omega0_scf);
        dxdy[index_guess] = -0.5*sqrt(3.0)*pow(ba.Omega0_scf,-1.5);
      }
      else{
        /* Default: take the passed value as xguess and set dxdy to 1. */
        xguess[index_guess] = ba.scf_parameters[ba.scf_tuning_index];
        dxdy[index_guess] = 1.;
      }
      break;
    case omega_ini_dcdm:
      Omega0_dcdmdr = 1./(ba.h*ba.h);
    case Omega_ini_dcdm:
      /* This works since correspondence is Omega_ini_dcdm -> Omega_dcdmdr and
         omega_ini_dcdm -> omega_dcdmdr */
      Omega0_dcdmdr *=pfzw->target_value[index_guess];
      Omega_M = ba.Omega0_cdm+ba.Omega0_idm+Omega0_dcdmdr+ba.Omega0_b;
      gamma = ba.Gamma_dcdm/ba.H0;
      if (gamma < 1)
        a_decay = 1.0;
      else
        a_decay = pow(1+(gamma*gamma-1.)/Omega_M,-1./3.);
      xguess[index_guess] = pfzw->target_value[index_guess]*a_decay;
      dxdy[index_guess] = a_decay;
      if (gamma > 100)
        dxdy[index_guess] *= gamma/100;
      break;

    case sigma8:
      /* Assume linear relationship between A_s and sigma8 and fix coefficient
         according to vanilla LambdaCDM. Should be good enough... */
      xguess[index_guess] = 2.43e-9/0.87659*pfzw->target_value[index_guess];
      dxdy[index_guess] = 2.43e-9/0.87659;
      break;
    case S8:
      /* Assume linear relationship between A_s and S8 and fix coefficient
         according to vanilla LambdaCDM. Should be good enough... */
      xguess[index_guess] = 2.43e-9/0.891*pfzw->target_value[index_guess];
      dxdy[index_guess] = 2.43e-9/0.891;
      break;
    }
  }

  for (i=0; i<pfzw->fc.size; i++) {
    pfzw->fc.read[i] = _FALSE_;
  }

  /** - Deallocate everything allocated by input_read_parameters */
  background_free_input(&ba);
  thermodynamics_free_input(&th);
  perturbations_free_input(&pt);

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x11be8, %rsp          # imm = 0x11BE8
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x40(%rdx), %eax
leaq 0x8(%rdx), %r13
subl %eax, 0x10(%rdx)
movw $0x0, 0x3a8(%rsp)
subq $0x40, %rsp
movq %rcx, 0x30(%rsp)
leaq 0x2d68(%rsp), %rsi
movq %r13, %rdi
callq 0x323ea
addq $0x40, %rsp
cmpl $0x1, %eax
jne 0x3bcb6
leaq 0xa3771(%rip), %rsi     # 0xdf3f0
leaq 0xa8d90(%rip), %rdx     # 0xe4a16
leaq 0xa7f0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xa3392(%rip), %rsi     # 0xdf034
leaq 0xa8dc4(%rip), %rdx     # 0xe4a6d
movq %r12, %rdi
movl $0x493, %ecx            # imm = 0x493
jmp 0x3bd68
movq %r14, 0x18(%rsp)
subq $0x8, %rsp
leaq 0x53f8(%rsp), %rax
leaq 0x89f0(%rsp), %r10
leaq 0x1bb8(%rsp), %r11
leaq 0x3f60(%rsp), %rbp
leaq 0x2448(%rsp), %r14
leaq 0x2d30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x6018(%rsp), %rcx
leaq 0xa7f8(%rsp), %r8
leaq 0x7880(%rsp), %r9
movq %r13, %rdi
pushq %r12
pushq %rax
pushq %r10
pushq %r11
pushq %rbp
pushq %r14
leaq 0x48f8(%rsp), %rax
pushq %rax
callq 0x3a3b3
addq $0x40, %rsp
testl %eax, %eax
je 0x3bd89
leaq 0xa36ba(%rip), %rsi     # 0xdf3f0
leaq 0xa8d40(%rip), %rdx     # 0xe4a7d
leaq 0x13b0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xa32db(%rip), %rsi     # 0xdf034
leaq 0xa8d0d(%rip), %rdx     # 0xe4a6d
movq %r12, %rdi
movl $0x497, %ecx            # imm = 0x497
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x11be8, %rsp          # imm = 0x11BE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x40(%rbx), %eax
movl 0x10(%rbx), %edx
addl %eax, %edx
movl %edx, 0x10(%rbx)
testl %eax, %eax
jle 0x3c225
movsd 0xa34bc(%rip), %xmm3    # 0xdf260
xorl %r12d, %r12d
leaq 0xa7e62(%rip), %r13     # 0xe3c10
movsd 0xa7d22(%rip), %xmm4    # 0xe3ad8
movabsq $0x3ff0000000000000, %rbp # imm = 0x3FF0000000000000
movsd 0xa3f58(%rip), %xmm5    # 0xdfd20
xorpd %xmm6, %xmm6
movapd %xmm3, %xmm7
movq 0x18(%rsp), %r14
movq 0x30(%rbx), %rax
movl (%rax,%r12,4), %eax
cmpq $0x9, %rax
ja 0x3c188
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0xa7cdd(%rip), %xmm2    # 0xe3ae8
mulsd %xmm2, %xmm0
mulsd 0xa7cd9(%rip), %xmm1    # 0xe3af0
addsd %xmm0, %xmm1
addsd 0xa7cd5(%rip), %xmm1    # 0xe3af8
movsd %xmm1, (%r15,%r12,8)
movsd (%rax,%r12,8), %xmm0
mulsd 0xa7cc9(%rip), %xmm0    # 0xe3b00
addsd %xmm2, %xmm0
movsd %xmm0, (%r14,%r12,8)
movsd (%r15,%r12,8), %xmm0
movsd %xmm0, 0x30(%rsp)
mulsd 0xa7cb3(%rip), %xmm0    # 0xe3b08
divsd 0xa7cb3(%rip), %xmm0    # 0xe3b10
movsd %xmm0, 0x28(%rsp)
jmp 0x3c188
movsd 0x88(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x3beee
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd 0x78(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0xa3943(%rip), %xmm0    # 0xdf7e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa7c13(%rip), %xmm1    # 0xe3ac8
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
callq 0x8620
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa3e46(%rip), %xmm5    # 0xdfd20
movsd 0xa7bf6(%rip), %xmm4    # 0xe3ad8
movsd 0xa3376(%rip), %xmm3    # 0xdf260
movapd %xmm0, %xmm1
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movsd 0x30(%rsp), %xmm2
divsd %xmm2, %xmm0
divsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r15,%r12,8)
movapd %xmm3, %xmm0
divsd %xmm1, %xmm0
divsd %xmm2, %xmm0
divsd %xmm2, %xmm0
jmp 0x3c04d
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa7b81(%rip), %xmm0    # 0xe3ab8
movsd %xmm0, (%r15,%r12,8)
movabsq $0x3e276d560e066a6e, %rax # imm = 0x3E276D560E066A6E
jmp 0x3c184
movslq 0x98(%rsp), %rax
testq %rax, %rax
jle 0x3bf78
movq 0xf8(%rsp), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm0, %xmm6
incq %rdx
cmpq %rdx, %rax
jne 0x3bf63
movsd 0x68(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
divsd 0xa338c(%rip), %xmm0    # 0xdf318
mulsd 0xa7b4c(%rip), %xmm0    # 0xe3ae0
addsd %xmm0, %xmm6
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm6, %xmm0
jmp 0x3c156
movsd 0x88(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x3c031
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd 0x78(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0xa3800(%rip), %xmm0    # 0xdf7e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa7ad0(%rip), %xmm1    # 0xe3ac8
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
callq 0x8620
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa3d03(%rip), %xmm5    # 0xdfd20
movsd 0xa7ab3(%rip), %xmm4    # 0xe3ad8
movsd 0xa3233(%rip), %xmm3    # 0xdf260
movapd %xmm0, %xmm1
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r15,%r12,8)
movapd %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r14,%r12,8)
jmp 0x3c188
movsd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm0
movapd %xmm3, %xmm7
divsd %xmm0, %xmm7
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
movsd 0x88(%rsp), %xmm2
divsd 0x28(%rsp), %xmm2
mulsd %xmm1, %xmm7
ucomisd %xmm2, %xmm3
movapd %xmm3, %xmm0
ja 0x3c116
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd %xmm7, %xmm1
addsd 0x48(%rsp), %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd 0xa372d(%rip), %xmm0    # 0xdf7e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa79fd(%rip), %xmm1    # 0xe3ac8
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
movsd %xmm2, 0x20(%rsp)
callq 0x8620
movsd 0x20(%rsp), %xmm2
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa3c24(%rip), %xmm5    # 0xdfd20
movsd 0xa79d4(%rip), %xmm4    # 0xe3ad8
movsd 0xa3154(%rip), %xmm3    # 0xdf260
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r15,%r12,8)
movsd %xmm0, (%r14,%r12,8)
ucomisd %xmm5, %xmm2
jbe 0x3c188
divsd %xmm5, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, (%r14,%r12,8)
jmp 0x3c188
movslq 0x17c(%rsp), %rax
testq %rax, %rax
je 0x3c19d
movq 0x170(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r15,%r12,8)
movq %rbp, (%r14,%r12,8)
jmp 0x3c188
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa794c(%rip), %xmm0    # 0xe3ac0
movsd %xmm0, (%r15,%r12,8)
movabsq $0x3e27cfecb008d58c, %rax # imm = 0x3E27CFECB008D58C
movq %rax, (%r14,%r12,8)
incq %r12
movslq 0x40(%rbx), %rax
cmpq %rax, %r12
jl 0x3bdd5
jmp 0x3c222
movsd %xmm7, 0x8(%rsp)
movsd %xmm6, 0x10(%rsp)
movsd 0xa44cf(%rip), %xmm0    # 0xe0680
divsd 0x130(%rsp), %xmm0
ucomisd 0xa3096(%rip), %xmm0    # 0xdf258
jb 0x3c1ca
sqrtsd %xmm0, %xmm0
jmp 0x3c1cf
callq 0x82b0
movsd %xmm0, (%r15,%r12,8)
movsd 0x130(%rsp), %xmm0
movsd 0xa666a(%rip), %xmm1    # 0xe2850
callq 0x8620
mulsd 0xa78dd(%rip), %xmm0    # 0xe3ad0
movsd %xmm0, (%r14,%r12,8)
movsd 0xa305f(%rip), %xmm3    # 0xdf260
movsd 0xa78cf(%rip), %xmm4    # 0xe3ad8
movsd 0xa3b0f(%rip), %xmm5    # 0xdfd20
movsd 0x10(%rsp), %xmm6
movsd 0x8(%rsp), %xmm7
jmp 0x3c188
movl 0x10(%rbx), %edx
testl %edx, %edx
jle 0x3c236
movq 0x28(%rbx), %rdi
addl %edx, %edx
xorl %esi, %esi
callq 0x8200
leaq 0x28(%rsp), %rdi
callq 0x58a2f
leaq 0x6010(%rsp), %rdi
callq 0x6120e
leaq 0xa7f0(%rsp), %rdi
callq 0x6d24a
xorl %eax, %eax
jmp 0x3bd77