// File: /workspace/github_c_makefile_star2_O1/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 0x32551
addq $0x40, %rsp
cmpl $0x1, %eax
jne 0x3d0c6
leaq 0xa4361(%rip), %rsi     # 0xe13f0
leaq 0xa9950(%rip), %rdx     # 0xe69e6
leaq 0xa7f0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xa3f82(%rip), %rsi     # 0xe1034
leaq 0xa9984(%rip), %rdx     # 0xe6a3d
movq %r12, %rdi
movl $0x493, %ecx            # imm = 0x493
jmp 0x3d178
movq %r14, 0x20(%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 0x3b7ac
addq $0x40, %rsp
testl %eax, %eax
je 0x3d199
leaq 0xa42aa(%rip), %rsi     # 0xe13f0
leaq 0xa9900(%rip), %rdx     # 0xe6a4d
leaq 0x13b0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xa3ecb(%rip), %rsi     # 0xe1034
leaq 0xa98cd(%rip), %rdx     # 0xe6a3d
movq %r12, %rdi
movl $0x497, %ecx            # imm = 0x497
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
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
addl %eax, 0x10(%rbx)
testl %eax, %eax
movq 0x20(%rsp), %r14
jle 0x3d625
movsd 0xa40ac(%rip), %xmm3    # 0xe1260
xorl %r12d, %r12d
leaq 0xa8a22(%rip), %r13     # 0xe5be0
movsd 0xa88e2(%rip), %xmm4    # 0xe5aa8
movabsq $0x3ff0000000000000, %rbp # imm = 0x3FF0000000000000
movsd 0xa4b48(%rip), %xmm5    # 0xe1d20
xorpd %xmm6, %xmm6
movapd %xmm3, %xmm7
movq 0x30(%rbx), %rax
movl (%rax,%r12,4), %eax
cmpq $0x9, %rax
ja 0x3d58b
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 0xa88a2(%rip), %xmm2    # 0xe5ab8
mulsd %xmm2, %xmm0
mulsd 0xa889e(%rip), %xmm1    # 0xe5ac0
addsd %xmm0, %xmm1
addsd 0xa889a(%rip), %xmm1    # 0xe5ac8
movsd %xmm1, (%r15,%r12,8)
movsd (%rax,%r12,8), %xmm0
mulsd 0xa888e(%rip), %xmm0    # 0xe5ad0
addsd %xmm2, %xmm0
movsd %xmm0, (%r14,%r12,8)
movsd (%r15,%r12,8), %xmm0
movsd %xmm0, 0x30(%rsp)
mulsd 0xa8878(%rip), %xmm0    # 0xe5ad8
divsd 0xa8878(%rip), %xmm0    # 0xe5ae0
movsd %xmm0, 0x28(%rsp)
jmp 0x3d58b
movsd 0x88(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x3d2f9
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd 0x78(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0xa4538(%rip), %xmm0    # 0xe17e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa87d8(%rip), %xmm1    # 0xe5a98
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
callq 0x8620
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa4a3b(%rip), %xmm5    # 0xe1d20
movsd 0xa87bb(%rip), %xmm4    # 0xe5aa8
movsd 0xa3f6b(%rip), %xmm3    # 0xe1260
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 0x3d458
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa8746(%rip), %xmm0    # 0xe5a88
movsd %xmm0, (%r15,%r12,8)
movabsq $0x3e276d560e066a6e, %rax # imm = 0x3E276D560E066A6E
jmp 0x3d587
movslq 0x98(%rsp), %rax
testq %rax, %rax
jle 0x3d383
movq 0xf8(%rsp), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm0, %xmm6
incq %rdx
cmpq %rdx, %rax
jne 0x3d36e
movsd 0x68(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
divsd 0xa3f81(%rip), %xmm0    # 0xe1318
mulsd 0xa8711(%rip), %xmm0    # 0xe5ab0
addsd %xmm0, %xmm6
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm6, %xmm0
jmp 0x3d559
movsd 0x88(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x3d43c
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd 0x78(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0xa43f5(%rip), %xmm0    # 0xe17e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa8695(%rip), %xmm1    # 0xe5a98
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
callq 0x8620
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa48f8(%rip), %xmm5    # 0xe1d20
movsd 0xa8678(%rip), %xmm4    # 0xe5aa8
movsd 0xa3e28(%rip), %xmm3    # 0xe1260
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 0x3d58b
movsd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm0
movapd %xmm3, %xmm7
divsd %xmm0, %xmm7
movq 0x38(%rbx), %rax
mulsd (%rax,%r12,8), %xmm7
movsd 0x88(%rsp), %xmm2
divsd 0x28(%rsp), %xmm2
ucomisd %xmm2, %xmm3
movapd %xmm3, %xmm0
ja 0x3d50f
movsd 0x58(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
addsd %xmm7, %xmm1
addsd 0x48(%rsp), %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd 0xa432a(%rip), %xmm0    # 0xe17e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa85ca(%rip), %xmm1    # 0xe5a98
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x8(%rsp)
movsd %xmm2, 0x18(%rsp)
callq 0x8620
movsd 0x18(%rsp), %xmm2
movsd 0x8(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movsd 0xa4821(%rip), %xmm5    # 0xe1d20
movsd 0xa85a1(%rip), %xmm4    # 0xe5aa8
movsd 0xa3d51(%rip), %xmm3    # 0xe1260
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 0x3d58b
divsd %xmm5, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, (%r14,%r12,8)
jmp 0x3d58b
movslq 0x17c(%rsp), %rax
testq %rax, %rax
je 0x3d5a0
movq 0x170(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r15,%r12,8)
movq %rbp, (%r14,%r12,8)
jmp 0x3d58b
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa8519(%rip), %xmm0    # 0xe5a90
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 0x3d1e0
jmp 0x3d625
movsd %xmm7, 0x8(%rsp)
movsd %xmm6, 0x10(%rsp)
movsd 0xa50cc(%rip), %xmm0    # 0xe2680
divsd 0x130(%rsp), %xmm0
ucomisd 0xa3c93(%rip), %xmm0    # 0xe1258
jb 0x3d5cd
sqrtsd %xmm0, %xmm0
jmp 0x3d5d2
callq 0x82b0
movsd %xmm0, (%r15,%r12,8)
movsd 0x130(%rsp), %xmm0
movsd 0xa7257(%rip), %xmm1    # 0xe4840
callq 0x8620
mulsd 0xa84aa(%rip), %xmm0    # 0xe5aa0
movsd %xmm0, (%r14,%r12,8)
movsd 0xa3c5c(%rip), %xmm3    # 0xe1260
movsd 0xa849c(%rip), %xmm4    # 0xe5aa8
movsd 0xa470c(%rip), %xmm5    # 0xe1d20
movsd 0x10(%rsp), %xmm6
movsd 0x8(%rsp), %xmm7
jmp 0x3d58b
movl 0x10(%rbx), %edx
testl %edx, %edx
jle 0x3d63a
movq 0x28(%rbx), %rdi
addq %rdx, %rdx
xorl %esi, %esi
callq 0x8200
leaq 0x28(%rsp), %rdi
callq 0x5ac77
leaq 0x6010(%rsp), %rdi
callq 0x635f6
leaq 0xa7f0(%rsp), %rdi
callq 0x6f792
xorl %eax, %eax
jmp 0x3d187