// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/primordial.c
// Function: primordial_inflation_one_k
int primordial_inflation_one_k(
                               struct primordial * ppm,
                               struct precision * ppr,
                               double k,
                               double * y,
                               double * dy,
                               double * curvature,
                               double * tensor
                               ) {

  /** Summary: */

  /** - define local variables */
  double tau_start,tau_end,dtau;
  double z,ksi2,ah2;
  double aH;
  double curvature_old;
  double curvature_new;
  double dlnPdN;

  struct primordial_inflation_parameters_and_workspace pipaw;
  struct generic_integrator_workspace gi;

  /** - initialize the generic integrator (same integrator already used
      in background, thermodynamics and perturbation modules) */

  pipaw.ppm = ppm;
  pipaw.N = ppm->in_size;
  pipaw.integrate = forward;
  pipaw.time = conformal;
  pipaw.k = k;

  class_call(initialize_generic_integrator(pipaw.N,&gi),
             gi.error_message,
             ppm->error_message);

  /* initial conditions for the perturbations, Bunch-Davies vacuum */
  y[ppm->index_in_ksi_re]=1./sqrt(2.*k);
  y[ppm->index_in_ksi_im]=0.;
  y[ppm->index_in_dksi_re]=0.;
  y[ppm->index_in_dksi_im]=-k*y[ppm->index_in_ksi_re];

  y[ppm->index_in_ah_re]=1./sqrt(2.*k);
  y[ppm->index_in_ah_im]=0.;
  y[ppm->index_in_dah_re]=0.;
  y[ppm->index_in_dah_im]=-k*y[ppm->index_in_ah_re];

  /** - initialize variable used for deciding when to stop the calculation (= when the curvature remains stable) */
  curvature_new = _HUGE_;

  /** - initialize conformal time to arbitrary value (here, only variations
      of tau matter: the equations that we integrate do not depend
      explicitly on time) */
  tau_end = 0;

  /** - compute derivative of initial vector and infer first value of adaptive time-step */
  class_call(primordial_inflation_derivs(tau_end,
                                         y,
                                         dy,
                                         &pipaw,
                                         ppm->error_message),
             ppm->error_message,
             ppm->error_message);

  dtau = ppr->primordial_inflation_pt_stepsize*2.*_PI_
    /MAX(sqrt(fabs(dy[ppm->index_in_dksi_re]/y[ppm->index_in_ksi_re])),k);

  /** - loop over time */
  do {

    /*  new time interval [tau_start, tau_end] over which equations will be integrated */
    tau_start = tau_end;

    tau_end = tau_start + dtau;

    class_test(dtau/tau_start < ppr->smallest_allowed_variation,
               ppm->error_message,
               "integration step: relative change in time =%e < machine precision : leads either to numerical error or infinite loop",dtau/tau_start);

    /* evolve the system */
    class_call(generic_integrator(primordial_inflation_derivs,
                                  tau_start,
                                  tau_end,
                                  y,
                                  &pipaw,
                                  ppr->primordial_inflation_tol_integration,
                                  ppr->smallest_allowed_variation,
                                  &gi),
               gi.error_message,
               ppm->error_message);

    /* compute derivatives at tau_end, useful to infer new time step and spectra */
    class_call(primordial_inflation_derivs(tau_end,
                                           y,
                                           dy,
                                           &pipaw,
                                           ppm->error_message),
               ppm->error_message,
               ppm->error_message);

    /* new time step */
    dtau = ppr->primordial_inflation_pt_stepsize*2.*_PI_
      /MAX(sqrt(fabs(dy[ppm->index_in_dksi_re]/y[ppm->index_in_ksi_re])),k);

    /* new aH */
    aH = dy[ppm->index_in_a]/y[ppm->index_in_a];

    /* store previous value of curvature (at tau_start) */
    curvature_old =  curvature_new;

    /* new curvature */
    z = y[ppm->index_in_a]*dy[ppm->index_in_phi]/aH;
    ksi2 = y[ppm->index_in_ksi_re]*y[ppm->index_in_ksi_re]+y[ppm->index_in_ksi_im]*y[ppm->index_in_ksi_im];
    curvature_new = k*k*k/2./_PI_/_PI_*ksi2/z/z;

    /* variation of curvature with time (dimensionless) */
    dlnPdN = (curvature_new-curvature_old)/dtau*y[ppm->index_in_a]/dy[ppm->index_in_a]/curvature_new;

    /* stop when (k >> aH) AND curvature is stable */
  } while ((k/aH >= ppr->primordial_inflation_ratio_max) || (fabs(dlnPdN) > ppr->primordial_inflation_tol_curvature));

  /** - clean the generic integrator */
  class_call(cleanup_generic_integrator(&gi),
             gi.error_message,
             ppm->error_message);

  /** - store final value of curvature for this wavenumber */
  *curvature = curvature_new;

  /** - store final value of tensor perturbation for this wavenumber */
  ah2 = y[ppm->index_in_ah_re]*y[ppm->index_in_ah_re]+y[ppm->index_in_ah_im]*y[ppm->index_in_ah_im];
  *tensor = 32.*k*k*k/_PI_*ah2/y[ppm->index_in_a]/y[ppm->index_in_a];

  //fprintf(stdout,"%g %g %g %g %g\n",k,*curvature,*tensor,*tensor/(*curvature),dlnPdN);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1948, %rsp           # imm = 0x1948
movq %r9, %r13
movq %r8, %r12
movq %rcx, %rbp
movq %rdx, %r15
movq %rdi, %rbx
movq %rdi, 0x58(%rsp)
movl 0x300(%rdi), %edi
cvtsi2sd %edi, %xmm1
movq %rsi, %r14
movsd %xmm1, 0x60(%rsp)
movq $0x1, 0xc8(%rsp)
movapd %xmm0, 0x10(%rsp)
movsd %xmm0, 0xc0(%rsp)
leaq 0x8d8(%rsp), %rsi
callq 0xa140
cmpl $0x1, %eax
jne 0x9b96b
leaq 0x940(%rsp), %rcx
leaq 0x52ac3(%rip), %rsi     # 0xee3f0
leaq 0x7e372(%rip), %rdx     # 0x119ca6
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x32a, %rbx            # imm = 0x32A
leaq 0x526e0(%rip), %rsi     # 0xee034
leaq 0x7e376(%rip), %rdx     # 0x119cd1
movq %rbx, %rdi
movl $0x712, %ecx            # imm = 0x712
movq %r14, %r8
jmp 0x9bacd
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
sqrtsd %xmm4, %xmm3
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm4
movapd %xmm3, %xmm0
jae 0x9b9b4
movapd %xmm4, %xmm0
movsd %xmm3, (%rsp)
movapd %xmm4, 0x20(%rsp)
callq 0x82b0
xorpd %xmm6, %xmm6
movapd 0x20(%rsp), %xmm4
movsd (%rsp), %xmm3
movapd 0x10(%rsp), %xmm2
movq %r12, 0x38(%rsp)
movsd 0x5289f(%rip), %xmm5    # 0xee260
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
movslq 0x2dc(%rbx), %rax
movsd %xmm1, (%r15,%rax,8)
movslq 0x2e0(%rbx), %rcx
xorl %edx, %edx
movq %rdx, (%r15,%rcx,8)
movslq 0x2e4(%rbx), %rcx
movq %rdx, (%r15,%rcx,8)
movapd 0x5283a(%rip), %xmm1    # 0xee230
xorpd %xmm2, %xmm1
movapd %xmm1, %xmm0
mulsd (%r15,%rax,8), %xmm0
movslq 0x2e8(%rbx), %rax
movsd %xmm0, (%r15,%rax,8)
ucomisd %xmm6, %xmm4
jae 0x9ba36
movapd %xmm4, %xmm0
movapd %xmm1, (%rsp)
callq 0x82b0
movapd (%rsp), %xmm1
movsd 0x5282e(%rip), %xmm5    # 0xee260
movapd %xmm0, %xmm3
divsd %xmm3, %xmm5
movslq 0x2ec(%rbx), %rax
movsd %xmm5, (%r15,%rax,8)
movslq 0x2f0(%rbx), %rcx
xorl %edx, %edx
movq %rdx, (%r15,%rcx,8)
movslq 0x2f4(%rbx), %rcx
movq %rdx, (%r15,%rcx,8)
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movslq 0x2f8(%rbx), %rax
movsd %xmm0, (%r15,%rax,8)
leaq 0x32a(%rbx), %r12
leaq 0x58(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x9beb7
testl %eax, %eax
je 0x9baeb
leaq 0x52958(%rip), %rsi     # 0xee3f0
leaq 0x7e24d(%rip), %rdx     # 0x119cec
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x52579(%rip), %rsi     # 0xee034
leaq 0x7e20f(%rip), %rdx     # 0x119cd1
movq %r12, %rdi
movl $0x72e, %ecx            # imm = 0x72E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x1948, %rsp           # imm = 0x1948
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x30(%rsp)
movsd 0x6a0(%r14), %xmm1
addsd %xmm1, %xmm1
mulsd 0x554d3(%rip), %xmm1    # 0xf0fd8
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
andpd 0x52719(%rip), %xmm0    # 0xee240
sqrtsd %xmm0, %xmm0
movapd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm2
maxsd %xmm0, %xmm2
divsd %xmm2, %xmm1
xorpd %xmm2, %xmm2
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd 0xa28(%r14), %xmm3
ucomisd %xmm0, %xmm3
ja 0x9bd05
addsd %xmm2, %xmm1
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
mulsd 0x5315c(%rip), %xmm0    # 0xeecd0
movsd 0x5545c(%rip), %xmm4    # 0xf0fd8
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd 0x71b1e(%rip), %xmm4    # 0x10d6b0
leaq 0x58(%rsp), %r13
movsd %xmm4, 0x20(%rsp)
movapd %xmm2, %xmm0
movsd 0x6b0(%r14), %xmm2
leaq 0x306(%rip), %rdi       # 0x9beb7
movsd %xmm1, (%rsp)
movq %r15, %rsi
movq %r13, %rdx
leaq 0x8d8(%rsp), %rcx
callq 0xa55f
cmpl $0x1, %eax
je 0x9bd5c
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x9beb7
testl %eax, %eax
jne 0x9bd9f
movsd 0x6a0(%r14), %xmm0
addsd %xmm0, %xmm0
mulsd 0x553db(%rip), %xmm0    # 0xf0fd8
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm1
movslq 0x2dc(%rbx), %rax
movsd (%r15,%rax,8), %xmm8
divsd %xmm8, %xmm1
movapd 0x5261c(%rip), %xmm7    # 0xee240
andpd %xmm7, %xmm1
sqrtsd %xmm1, %xmm1
movapd 0x10(%rsp), %xmm6
movapd %xmm6, %xmm2
maxsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movslq 0x2d0(%rbx), %rax
movsd (%rbp,%rax,8), %xmm2
movsd (%r15,%rax,8), %xmm1
movapd %xmm2, %xmm3
divsd %xmm1, %xmm3
movslq 0x2d4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm4
mulsd %xmm1, %xmm4
divsd %xmm3, %xmm4
movslq 0x2e0(%rbx), %rax
movsd (%r15,%rax,8), %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm8, %xmm8
addsd %xmm5, %xmm8
mulsd 0x40(%rsp), %xmm8
divsd %xmm4, %xmm8
divsd %xmm4, %xmm8
movapd %xmm6, %xmm4
divsd %xmm3, %xmm4
ucomisd 0x690(%r14), %xmm4
jae 0x9bcdc
movapd %xmm8, %xmm3
subsd 0x20(%rsp), %xmm3
divsd %xmm0, %xmm3
mulsd %xmm3, %xmm1
divsd %xmm2, %xmm1
divsd %xmm8, %xmm1
andpd %xmm7, %xmm1
ucomisd 0x6d0(%r14), %xmm1
jbe 0x9bddd
movapd %xmm0, %xmm1
movsd (%rsp), %xmm2
addsd %xmm2, %xmm1
divsd %xmm2, %xmm0
movsd 0xa28(%r14), %xmm3
ucomisd %xmm0, %xmm3
movapd %xmm8, %xmm4
jbe 0x9bb97
leaq 0x7e028(%rip), %rsi     # 0x119d34
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x30af0
leaq 0x5235d(%rip), %rsi     # 0xee082
leaq 0x7e07d(%rip), %rdx     # 0x119da9
leaq 0x1140(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x522ec(%rip), %rsi     # 0xee034
leaq 0x7df82(%rip), %rdx     # 0x119cd1
movq %r12, %rdi
movl $0x73d, %ecx            # imm = 0x73D
jmp 0x9b963
leaq 0x940(%rsp), %rcx
leaq 0x52685(%rip), %rsi     # 0xee3f0
leaq 0x7e068(%rip), %rdx     # 0x119dda
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x522a9(%rip), %rsi     # 0xee034
leaq 0x7df3f(%rip), %rdx     # 0x119cd1
movq %r12, %rdi
movl $0x749, %ecx            # imm = 0x749
jmp 0x9baca
leaq 0x5264a(%rip), %rsi     # 0xee3f0
leaq 0x7df3f(%rip), %rdx     # 0x119cec
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x5226b(%rip), %rsi     # 0xee034
leaq 0x7df01(%rip), %rdx     # 0x119cd1
movq %r12, %rdi
movl $0x752, %ecx            # imm = 0x752
jmp 0x9baca
movsd %xmm8, (%rsp)
leaq 0x8d8(%rsp), %rdi
callq 0xa4f4
cmpl $0x1, %eax
jne 0x9be38
leaq 0x940(%rsp), %rcx
leaq 0x525ec(%rip), %rsi     # 0xee3f0
leaq 0x52dee(%rip), %rdx     # 0xeebf9
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x52210(%rip), %rsi     # 0xee034
leaq 0x7dea6(%rip), %rdx     # 0x119cd1
movq %r12, %rdi
movl $0x76c, %ecx            # imm = 0x76C
jmp 0x9baca
movq 0x38(%rsp), %rax
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movslq 0x2ec(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movslq 0x2f0(%rbx), %rax
movsd 0x7675e(%rip), %xmm1    # 0x1125c0
movapd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movsd (%r15,%rax,8), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
divsd 0x5514e(%rip), %xmm1    # 0xf0fd8
addsd %xmm2, %xmm0
mulsd %xmm0, %xmm1
movslq 0x2d0(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
divsd %xmm0, %xmm1
divsd %xmm0, %xmm1
movq 0x30(%rsp), %rax
movsd %xmm1, (%rax)
xorl %eax, %eax
jmp 0x9bad9