// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %r8, %r12
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, 0x10(%rsp)
movsd %xmm0, 0xd0(%rsp)
leaq 0x8e8(%rsp), %rsi
callq 0xa15c
cmpl $0x1, %eax
jne 0x9e7be
leaq 0x950(%rsp), %rcx
leaq 0x52c70(%rip), %rsi     # 0xf13f0
leaq 0x7e4df(%rip), %rdx     # 0x11cc66
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x32a, %rbx            # imm = 0x32A
leaq 0x5288d(%rip), %rsi     # 0xf1034
leaq 0x7e4e3(%rip), %rdx     # 0x11cc91
movq %rbx, %rdi
movl $0x712, %ecx            # imm = 0x712
movq %r14, %r8
jmp 0x9e920
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
sqrtsd %xmm4, %xmm3
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm4
movapd %xmm3, %xmm0
jae 0x9e807
movapd %xmm4, %xmm0
movsd %xmm3, (%rsp)
movapd %xmm4, 0x30(%rsp)
callq 0x82b0
xorpd %xmm6, %xmm6
movapd 0x30(%rsp), %xmm4
movsd (%rsp), %xmm3
movapd 0x10(%rsp), %xmm2
movq %r12, 0x48(%rsp)
movsd 0x52a4c(%rip), %xmm5    # 0xf1260
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 0x529e7(%rip), %xmm1    # 0xf1230
xorpd %xmm2, %xmm1
movapd %xmm1, %xmm0
mulsd (%r15,%rax,8), %xmm0
movslq 0x2e8(%rbx), %rax
movsd %xmm0, (%r15,%rax,8)
ucomisd %xmm6, %xmm4
jae 0x9e889
movapd %xmm4, %xmm0
movapd %xmm1, (%rsp)
callq 0x82b0
movapd (%rsp), %xmm1
movsd 0x529db(%rip), %xmm5    # 0xf1260
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 0x68(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x9ede1
testl %eax, %eax
je 0x9e93e
leaq 0x52b05(%rip), %rsi     # 0xf13f0
leaq 0x7e3ba(%rip), %rdx     # 0x11ccac
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x52726(%rip), %rsi     # 0xf1034
leaq 0x7e37c(%rip), %rdx     # 0x11cc91
movq %r12, %rdi
movl $0x72e, %ecx            # imm = 0x72E
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1958, %rsp           # imm = 0x1958
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x6a0(%r14), %xmm4
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
andpd 0x528d7(%rip), %xmm0    # 0xf1240
addsd %xmm4, %xmm4
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x9e97d
sqrtsd %xmm0, %xmm0
jmp 0x9e98c
movsd %xmm4, (%rsp)
callq 0x82b0
movsd (%rsp), %xmm4
movapd 0x10(%rsp), %xmm2
mulsd 0x5562e(%rip), %xmm4    # 0xf3fc8
ucomisd %xmm0, %xmm2
movapd %xmm2, %xmm0
ja 0x9e9eb
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
andpd 0x5287a(%rip), %xmm0    # 0xf1240
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x9e9d6
sqrtsd %xmm0, %xmm0
jmp 0x9e9eb
movsd %xmm4, (%rsp)
callq 0x82b0
movsd (%rsp), %xmm4
movapd 0x10(%rsp), %xmm2
movq %r13, 0x40(%rsp)
divsd %xmm0, %xmm4
xorpd %xmm0, %xmm0
movapd %xmm4, %xmm6
divsd %xmm0, %xmm6
movsd 0xa28(%r14), %xmm3
ucomisd %xmm6, %xmm3
ja 0x9ec2c
addsd 0x5283d(%rip), %xmm4    # 0xf1258
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd 0x532a1(%rip), %xmm0    # 0xf1cd0
movsd 0x55591(%rip), %xmm1    # 0xf3fc8
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movapd %xmm0, 0x50(%rsp)
movsd 0x71c43(%rip), %xmm1    # 0x110690
leaq 0x68(%rsp), %r13
xorpd %xmm0, %xmm0
movsd %xmm1, 0x30(%rsp)
movapd %xmm4, %xmm1
movsd 0x6b0(%r14), %xmm2
leaq 0x371(%rip), %rdi       # 0x9ede1
movsd %xmm4, (%rsp)
movq %r15, %rsi
movq %r13, %rdx
leaq 0x8e8(%rsp), %rcx
callq 0xa57b
cmpl $0x1, %eax
je 0x9ec87
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x9ede1
testl %eax, %eax
jne 0x9ecca
movsd 0x6a0(%r14), %xmm6
addsd %xmm6, %xmm6
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
mulsd 0x554f2(%rip), %xmm6    # 0xf3fc8
andpd 0x52762(%rip), %xmm0    # 0xf1240
ucomisd 0x52772(%rip), %xmm0    # 0xf1258
jb 0x9eaee
sqrtsd %xmm0, %xmm0
jmp 0x9eaff
movsd %xmm6, 0x28(%rsp)
callq 0x82b0
movsd 0x28(%rsp), %xmm6
movapd 0x10(%rsp), %xmm5
ucomisd %xmm0, %xmm5
movapd %xmm5, %xmm0
ja 0x9eb58
movslq 0x2e4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm0
movslq 0x2dc(%rbx), %rax
divsd (%r15,%rax,8), %xmm0
andpd 0x5270f(%rip), %xmm0    # 0xf1240
ucomisd 0x5271f(%rip), %xmm0    # 0xf1258
jb 0x9eb41
sqrtsd %xmm0, %xmm0
jmp 0x9eb58
movsd %xmm6, 0x28(%rsp)
callq 0x82b0
movsd 0x28(%rsp), %xmm6
movapd 0x10(%rsp), %xmm5
divsd %xmm0, %xmm6
movslq 0x2d0(%rbx), %rax
movsd (%rbp,%rax,8), %xmm1
movsd (%r15,%rax,8), %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movslq 0x2d4(%rbx), %rax
movsd (%rbp,%rax,8), %xmm3
mulsd %xmm0, %xmm3
divsd %xmm2, %xmm3
movslq 0x2dc(%rbx), %rax
movsd (%r15,%rax,8), %xmm7
movslq 0x2e0(%rbx), %rax
movsd (%r15,%rax,8), %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm7, %xmm7
addsd %xmm4, %xmm7
mulsd 0x50(%rsp), %xmm7
divsd %xmm3, %xmm7
divsd %xmm3, %xmm7
movapd %xmm5, %xmm3
divsd %xmm2, %xmm3
ucomisd 0x690(%r14), %xmm3
jae 0x9ec04
movapd %xmm7, %xmm2
subsd 0x30(%rsp), %xmm2
divsd %xmm6, %xmm2
mulsd %xmm2, %xmm0
divsd %xmm1, %xmm0
divsd %xmm7, %xmm0
andpd 0x5264b(%rip), %xmm0    # 0xf1240
ucomisd 0x6d0(%r14), %xmm0
jbe 0x9ed08
movapd %xmm6, %xmm4
movsd (%rsp), %xmm0
addsd %xmm0, %xmm4
divsd %xmm0, %xmm6
movsd 0xa28(%r14), %xmm3
ucomisd %xmm6, %xmm3
movapd %xmm7, %xmm1
jbe 0x9ea56
leaq 0x7e0c1(%rip), %rsi     # 0x11ccf4
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movapd %xmm6, %xmm0
movb $0x1, %al
callq 0x30c2c
leaq 0x52432(%rip), %rsi     # 0xf1082
leaq 0x7e112(%rip), %rdx     # 0x11cd69
leaq 0x1150(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x523c1(%rip), %rsi     # 0xf1034
leaq 0x7e017(%rip), %rdx     # 0x11cc91
movq %r12, %rdi
movl $0x73d, %ecx            # imm = 0x73D
jmp 0x9e7b6
leaq 0x950(%rsp), %rcx
leaq 0x5275a(%rip), %rsi     # 0xf13f0
leaq 0x7e0fd(%rip), %rdx     # 0x11cd9a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x5237e(%rip), %rsi     # 0xf1034
leaq 0x7dfd4(%rip), %rdx     # 0x11cc91
movq %r12, %rdi
movl $0x749, %ecx            # imm = 0x749
jmp 0x9e91d
leaq 0x5271f(%rip), %rsi     # 0xf13f0
leaq 0x7dfd4(%rip), %rdx     # 0x11ccac
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x52340(%rip), %rsi     # 0xf1034
leaq 0x7df96(%rip), %rdx     # 0x11cc91
movq %r12, %rdi
movl $0x752, %ecx            # imm = 0x752
jmp 0x9e91d
movsd %xmm7, (%rsp)
leaq 0x8e8(%rsp), %rdi
callq 0xa510
cmpl $0x1, %eax
jne 0x9ed62
leaq 0x950(%rsp), %rcx
leaq 0x526c2(%rip), %rsi     # 0xf13f0
leaq 0x52ec4(%rip), %rdx     # 0xf1bf9
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x522e6(%rip), %rsi     # 0xf1034
leaq 0x7df3c(%rip), %rdx     # 0x11cc91
movq %r12, %rdi
movl $0x76c, %ecx            # imm = 0x76C
jmp 0x9e91d
movq 0x48(%rsp), %rax
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movslq 0x2ec(%rbx), %rax
movsd (%r15,%rax,8), %xmm0
movslq 0x2f0(%rbx), %rax
movsd 0x767f4(%rip), %xmm1    # 0x115580
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 0x55214(%rip), %xmm1    # 0xf3fc8
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 0x9e92c