// File: /workspace/github_c_makefile_star2_O2/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 $0x1958, %rsp           # imm = 0x1958
movq %r9, %r12
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rdi, %rbx
movq %rdi, 0x68(%rsp)
movl 0x300(%rdi), %edi
cvtsi2sd %edi, %xmm1
movq %rsi, %r14
movsd %xmm1, 0x70(%rsp)
movq $0x1, 0xd8(%rsp)
movapd %xmm0, 0x20(%rsp)
movsd %xmm0, 0xd0(%rsp)
leaq 0x8e8(%rsp), %rsi
callq 0x8cb0
cmpl $0x1, %eax
jne 0x96bbd
leaq 0x950(%rsp), %rcx
leaq 0x4e871(%rip), %rsi     # 0xe53f0
leaq 0x79fc0(%rip), %rdx     # 0x110b46
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x32a, %rbx            # imm = 0x32A
leaq 0x4e48e(%rip), %rsi     # 0xe5034
leaq 0x79fc4(%rip), %rdx     # 0x110b71
movq %rbx, %rdi
movl $0x712, %ecx            # imm = 0x712
movq %r14, %r8
jmp 0x96d23
movapd 0x20(%rsp), %xmm2
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
sqrtsd %xmm4, %xmm3
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm4
movapd %xmm3, %xmm0
jae 0x96c08
movapd %xmm4, %xmm0
movsd %xmm3, 0x10(%rsp)
movapd %xmm4, 0x30(%rsp)
callq 0x82d0
xorpd %xmm6, %xmm6
movapd 0x30(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movq %r13, 0x48(%rsp)
movsd 0x4e64b(%rip), %xmm5    # 0xe5260
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
movslq 0x2dc(%rbx), %rax
movsd %xmm1, (%r15,%rax,8)
movslq 0x2e0(%rbx), %rcx
andq $0x0, (%r15,%rcx,8)
movslq 0x2e4(%rbx), %rcx
andq $0x0, (%r15,%rcx,8)
movapd 0x4e5e6(%rip), %xmm1    # 0xe5230
xorpd %xmm2, %xmm1
movapd %xmm1, %xmm0
mulsd (%r15,%rax,8), %xmm0
movslq 0x2e8(%rbx), %rax
movsd %xmm0, (%r15,%rax,8)
ucomisd %xmm6, %xmm4
jae 0x96c8c
movapd %xmm4, %xmm0
movapd %xmm1, 0x10(%rsp)
callq 0x82d0
movapd 0x10(%rsp), %xmm1
movsd 0x4e5d8(%rip), %xmm5    # 0xe5260
movapd %xmm0, %xmm3
divsd %xmm3, %xmm5
movslq 0x2ec(%rbx), %rax
movsd %xmm5, (%r15,%rax,8)
movslq 0x2f0(%rbx), %rcx
andq $0x0, (%r15,%rcx,8)
movslq 0x2f4(%rbx), %rcx
andq $0x0, (%r15,%rcx,8)
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movslq 0x2f8(%rbx), %rax
movsd %xmm0, (%r15,%rax,8)
leaq 0x32a(%rbx), %r13
leaq 0x68(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x97105
testl %eax, %eax
je 0x96d3f
leaq 0x4e702(%rip), %rsi     # 0xe53f0
leaq 0x79e97(%rip), %rdx     # 0x110b8c
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4e323(%rip), %rsi     # 0xe5034
leaq 0x79e59(%rip), %rdx     # 0x110b71
movq %r13, %rdi
movl $0x72e, %ecx            # imm = 0x72E
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x1958, %rsp           # imm = 0x1958
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x8(%rsp)
movq %r12, 0x40(%rsp)
movsd 0x6a0(%r14), %xmm2
addsd %xmm2, %xmm2
movsd 0x5123a(%rip), %xmm4    # 0xe7f98
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
mulsd %xmm4, %xmm2
andpd 0x4e4bc(%rip), %xmm0    # 0xe5240
sqrtsd %xmm0, %xmm0
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm1
maxsd %xmm0, %xmm1
divsd %xmm1, %xmm2
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd 0x4ef02(%rip), %xmm0    # 0xe5cb0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movapd %xmm0, 0x50(%rsp)
movsd 0x6d7ac(%rip), %xmm7    # 0x104570
xorpd %xmm0, %xmm0
leaq 0x68(%rsp), %r12
leaq 0x8e8(%rsp), %r13
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movsd 0xa28(%r14), %xmm3
ucomisd %xmm1, %xmm3
ja 0x96fa0
movsd %xmm7, 0x30(%rsp)
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x6b0(%r14), %xmm2
leaq 0x2f7(%rip), %rdi       # 0x97105
movsd %xmm1, 0x10(%rsp)
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x908f
cmpl $0x1, %eax
je 0x96ffd
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x97105
testl %eax, %eax
jne 0x97042
movsd 0x6a0(%r14), %xmm2
addsd %xmm2, %xmm2
mulsd 0x51142(%rip), %xmm2    # 0xe7f98
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
movsd (%r15,%rax,8), %xmm7
divsd %xmm7, %xmm0
andpd 0x4e3c4(%rip), %xmm0    # 0xe5240
sqrtsd %xmm0, %xmm0
movapd 0x20(%rsp), %xmm6
movapd %xmm6, %xmm1
maxsd %xmm0, %xmm1
divsd %xmm1, %xmm2
movslq 0x2d0(%rbx), %rax
movsd (%rbp,%rax,8), %xmm3
movsd (%r15,%rax,8), %xmm1
movapd %xmm3, %xmm0
divsd %xmm1, %xmm0
movslq 0x2d4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm4
mulsd %xmm1, %xmm4
divsd %xmm0, %xmm4
movslq 0x2e0(%rbx), %rax
movsd (%r15,%rax,8), %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm7, %xmm7
addsd %xmm5, %xmm7
mulsd 0x50(%rsp), %xmm7
divsd %xmm4, %xmm7
divsd %xmm4, %xmm7
movapd %xmm6, %xmm4
divsd %xmm0, %xmm4
ucomisd 0x690(%r14), %xmm4
movsd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm0
jae 0x96dd5
movapd %xmm7, %xmm0
subsd 0x30(%rsp), %xmm0
divsd %xmm2, %xmm0
mulsd %xmm0, %xmm1
divsd %xmm3, %xmm1
divsd %xmm7, %xmm1
andpd 0x4e314(%rip), %xmm1    # 0xe5240
ucomisd 0x6d0(%r14), %xmm1
movapd %xmm4, %xmm0
ja 0x96dd5
movsd %xmm7, 0x10(%rsp)
leaq 0x8e8(%rsp), %rdi
callq 0x9024
cmpl $0x1, %eax
jne 0x97085
leaq 0x950(%rsp), %rcx
leaq 0x4e486(%rip), %rsi     # 0xe53f0
leaq 0x4ec88(%rip), %rdx     # 0xe5bf9
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x4e0aa(%rip), %rsi     # 0xe5034
leaq 0x79be0(%rip), %rdx     # 0x110b71
movq 0x8(%rsp), %rdi
movl $0x76c, %ecx            # imm = 0x76C
jmp 0x96d20
leaq 0x79c2d(%rip), %rsi     # 0x110bd4
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x2e014
leaq 0x4e0be(%rip), %rsi     # 0xe5082
leaq 0x79c7e(%rip), %rdx     # 0x110c49
leaq 0x1150(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4e04d(%rip), %rsi     # 0xe5034
leaq 0x79b83(%rip), %rdx     # 0x110b71
movq 0x8(%rsp), %rdi
movl $0x73d, %ecx            # imm = 0x73D
jmp 0x96bb5
leaq 0x950(%rsp), %rcx
leaq 0x4e3e4(%rip), %rsi     # 0xe53f0
leaq 0x79c67(%rip), %rdx     # 0x110c7a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0x4e008(%rip), %rsi     # 0xe5034
leaq 0x79b3e(%rip), %rdx     # 0x110b71
movq 0x8(%rsp), %rdi
movl $0x749, %ecx            # imm = 0x749
jmp 0x96d20
leaq 0x4e3a7(%rip), %rsi     # 0xe53f0
leaq 0x79b3c(%rip), %rdx     # 0x110b8c
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4dfc3(%rip), %rsi     # 0xe5034
leaq 0x79af9(%rip), %rdx     # 0x110b71
movq %r14, %rdi
movl $0x752, %ecx            # imm = 0x752
jmp 0x96d20
movq 0x48(%rsp), %rax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movslq 0x2ec(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movslq 0x2f0(%rbx), %rax
movsd 0x723b0(%rip), %xmm1    # 0x109460
movapd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movsd (%r15,%rax,8), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
divsd 0x50ec0(%rip), %xmm1    # 0xe7f98
addsd %xmm2, %xmm0
mulsd %xmm0, %xmm1
movslq 0x2d0(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
divsd %xmm0, %xmm1
divsd %xmm0, %xmm1
movq 0x40(%rsp), %rax
movsd %xmm1, (%rax)
xorl %eax, %eax
jmp 0x96d2d