// File: /workspace/github_c_makefile_star2_O2/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 $0x11bd8, %rsp          # imm = 0x11BD8
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x40(%rdx), %eax
subl %eax, 0x10(%rdx)
leaq 0x8(%rdx), %r13
andw $0x0, 0x398(%rsp)
subq $0x40, %rsp
movq %rcx, 0x30(%rsp)
leaq 0x2d58(%rsp), %rsi
movq %r13, %rdi
callq 0x2f8db
addq $0x40, %rsp
cmpl $0x1, %eax
jne 0x387b1
leaq 0x9dc76(%rip), %rsi     # 0xd63f0
leaq 0xa3155(%rip), %rdx     # 0xdb8d6
leaq 0xa7e0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x9d897(%rip), %rsi     # 0xd6034
leaq 0xa3189(%rip), %rdx     # 0xdb92d
movq %r12, %rdi
movl $0x493, %ecx            # imm = 0x493
jmp 0x3885d
subq $0x8, %rsp
leaq 0x53e8(%rsp), %rax
leaq 0x89e0(%rsp), %r10
leaq 0x1ba8(%rsp), %r11
leaq 0x3f50(%rsp), %rbp
leaq 0x2d20(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x6008(%rsp), %rcx
leaq 0xa7e8(%rsp), %r8
leaq 0x7870(%rsp), %r9
movq %r13, %rdi
pushq %r12
pushq %rax
pushq %r10
pushq %r11
pushq %rbp
leaq 0x2460(%rsp), %rax
pushq %rax
leaq 0x48e8(%rsp), %rax
pushq %rax
callq 0x36f7a
addq $0x40, %rsp
testl %eax, %eax
je 0x3887c
leaq 0x9dbc5(%rip), %rsi     # 0xd63f0
leaq 0xa310b(%rip), %rdx     # 0xdb93d
leaq 0x13a0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x9d7e6(%rip), %rsi     # 0xd6034
leaq 0xa30d8(%rip), %rdx     # 0xdb92d
movq %r12, %rdi
movl $0x497, %ecx            # imm = 0x497
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x11bd8, %rsp          # imm = 0x11BD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x40(%rbx), %eax
addl %eax, 0x10(%rbx)
movsd 0x9d9d6(%rip), %xmm3    # 0xd6260
leaq 0xa223f(%rip), %r13     # 0xdaad0
movabsq $0x3ff0000000000000, %rbp # imm = 0x3FF0000000000000
movsd 0xa20f5(%rip), %xmm4    # 0xda998
xorl %r12d, %r12d
movsd 0x9e452(%rip), %xmm5    # 0xd6d00
movapd %xmm3, %xmm7
xorpd %xmm6, %xmm6
cltq
cmpq %rax, %r12
jge 0x38cf5
movq 0x30(%rbx), %rax
movl (%rax,%r12,4), %eax
cmpq $0x9, %rax
ja 0x38c67
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 0xa20b1(%rip), %xmm2    # 0xda9a8
mulsd %xmm2, %xmm0
mulsd 0xa20ad(%rip), %xmm1    # 0xda9b0
addsd %xmm0, %xmm1
addsd 0xa20a9(%rip), %xmm1    # 0xda9b8
movsd %xmm1, (%r15,%r12,8)
movsd (%rax,%r12,8), %xmm0
mulsd 0xa209d(%rip), %xmm0    # 0xda9c0
addsd %xmm2, %xmm0
movsd %xmm0, (%r14,%r12,8)
movsd (%r15,%r12,8), %xmm0
movsd %xmm0, 0x20(%rsp)
mulsd 0xa2087(%rip), %xmm0    # 0xda9c8
divsd 0xa2087(%rip), %xmm0    # 0xda9d0
movsd %xmm0, 0x18(%rsp)
jmp 0x38c67
movsd 0x78(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x389d5
movsd 0x48(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
addsd 0x68(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0x9de5a(%rip), %xmm0    # 0xd67e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa1fea(%rip), %xmm1    # 0xda988
movsd %xmm6, 0x8(%rsp)
movsd %xmm7, (%rsp)
callq 0x8650
movsd (%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x9e33f(%rip), %xmm5    # 0xd6d00
movsd 0xa1fcf(%rip), %xmm4    # 0xda998
movsd 0x9d88f(%rip), %xmm3    # 0xd6260
movapd %xmm0, %xmm1
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movsd 0x20(%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 0x38b35
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa1f5a(%rip), %xmm0    # 0xda978
movsd %xmm0, (%r15,%r12,8)
movabsq $0x3e276d560e066a6e, %rax # imm = 0x3E276D560E066A6E
jmp 0x38c63
movl 0x88(%rsp), %eax
movq 0xe8(%rsp), %rcx
testl %eax, %eax
movl $0x0, %edx
cmovlel %edx, %eax
xorl %edx, %edx
cmpq %rdx, %rax
je 0x38a65
movsd (%rcx,%rdx,8), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm0, %xmm6
incq %rdx
jmp 0x38a4e
movsd 0x58(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
divsd 0x9d89f(%rip), %xmm0    # 0xd6318
mulsd 0xa1f1f(%rip), %xmm0    # 0xda9a0
addsd %xmm0, %xmm6
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm6, %xmm0
jmp 0x38c35
movsd 0x78(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
ucomisd %xmm0, %xmm3
movapd %xmm3, %xmm1
ja 0x38b19
movsd 0x48(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
addsd 0x68(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
mulsd %xmm0, %xmm0
addsd 0x9dd16(%rip), %xmm0    # 0xd67e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa1ea6(%rip), %xmm1    # 0xda988
movsd %xmm6, 0x8(%rsp)
movsd %xmm7, (%rsp)
callq 0x8650
movsd (%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x9e1fb(%rip), %xmm5    # 0xd6d00
movsd 0xa1e8b(%rip), %xmm4    # 0xda998
movsd 0x9d74b(%rip), %xmm3    # 0xd6260
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 0x38c67
movsd 0x20(%rsp), %xmm0
mulsd %xmm0, %xmm0
movapd %xmm3, %xmm7
divsd %xmm0, %xmm7
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
movsd 0x78(%rsp), %xmm2
divsd 0x18(%rsp), %xmm2
mulsd %xmm1, %xmm7
ucomisd %xmm2, %xmm3
movapd %xmm3, %xmm0
ja 0x38bf5
movsd 0x48(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
addsd %xmm7, %xmm1
addsd 0x38(%rsp), %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd 0x9dc4c(%rip), %xmm0    # 0xd67e8
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd 0xa1ddc(%rip), %xmm1    # 0xda988
movsd %xmm6, 0x8(%rsp)
movsd %xmm7, (%rsp)
movsd %xmm2, 0x10(%rsp)
callq 0x8650
movsd 0x10(%rsp), %xmm2
movsd (%rsp), %xmm7
movsd 0x8(%rsp), %xmm6
movsd 0x9e125(%rip), %xmm5    # 0xd6d00
movsd 0xa1db5(%rip), %xmm4    # 0xda998
movsd 0x9d675(%rip), %xmm3    # 0xd6260
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 0x38c67
divsd %xmm5, %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, (%r14,%r12,8)
jmp 0x38c67
movslq 0x16c(%rsp), %rax
testq %rax, %rax
je 0x38c72
movq 0x160(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r15,%r12,8)
movq %rbp, (%r14,%r12,8)
jmp 0x38c67
movq 0x38(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0xa1d2d(%rip), %xmm0    # 0xda980
movsd %xmm0, (%r15,%r12,8)
movabsq $0x3e27cfecb008d58c, %rax # imm = 0x3E27CFECB008D58C
movq %rax, (%r14,%r12,8)
incq %r12
movl 0x40(%rbx), %eax
jmp 0x388b6
movsd %xmm7, (%rsp)
movsd %xmm6, 0x8(%rsp)
movsd 0x9eac3(%rip), %xmm0    # 0xd7748
divsd 0x120(%rsp), %xmm0
ucomisd 0x9d5c2(%rip), %xmm0    # 0xd6258
jb 0x38c9e
sqrtsd %xmm0, %xmm0
jmp 0x38ca3
callq 0x82d0
movsd %xmm0, (%r15,%r12,8)
movsd 0x120(%rsp), %xmm0
movsd 0xa0b16(%rip), %xmm1    # 0xd97d0
callq 0x8650
mulsd 0xa1cc9(%rip), %xmm0    # 0xda990
movsd %xmm0, (%r14,%r12,8)
movsd 0x9d58b(%rip), %xmm3    # 0xd6260
movsd 0xa1cbb(%rip), %xmm4    # 0xda998
movsd 0x9e01b(%rip), %xmm5    # 0xd6d00
movsd 0x8(%rsp), %xmm6
movsd (%rsp), %xmm7
jmp 0x38c67
movl 0x10(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x38d12
movq 0x28(%rbx), %rdx
andw $0x0, (%rdx,%rcx,2)
incq %rcx
jmp 0x38cff
leaq 0x18(%rsp), %rdi
callq 0x5491b
leaq 0x6000(%rsp), %rdi
callq 0x5ccfd
leaq 0xa7e0(%rsp), %rdi
callq 0x689cd
xorl %eax, %eax
jmp 0x3886a