// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hydrogen.c
// Function: interpolate_rates
void interpolate_rates(double Alpha[2], double DAlpha[2], double Beta[2], double *R2p2s, double TR, double TM_TR,
                       HYREC_ATOMIC *atomic, double fsR, double meR, int *error, char error_message[SIZE_ErrorM]) {
  unsigned l, k, i;
  long iTM, iTR;
  double frac1, frac2;
  double logTR, T_RATIO;
  double coeff1[4], coeff2[4], temp[4];
  double Alpha_eq[2];
  char sub_message[128];

  /* Check that TM/TR is in range */
  if (TM_TR < T_RATIO_MIN) {
    sprintf(sub_message, "in interpolate_rates: TM/TR = %f is out of range.\n", TM_TR);
    strcat(error_message, sub_message);
    *error = 1;
    return;
  }
  
  /* T_RATIO is defined to be min(TM_TR, TR_TM) */
  if (TM_TR > 1.) {
    T_RATIO = 1./TM_TR; i = 2;
  }
  else {
    T_RATIO = TM_TR; i = 0;
  }

  /* Check if log(TR) is in the range tabulated */
  if (TR < TR_MIN || TR > TR_MAX) {
    sprintf(sub_message, "in interpolate_rates: TR = %f is out of range.\n", TR);
    strcat(error_message, sub_message);
    *error = 1;
    return;
  }

  /**** TR-only-dependent functions ****/

  /* Identify location to interpolate in log(TR) */
  logTR = log(TR);

  iTR = (long)floor((logTR - log(TR_MIN))/atomic->DlogTR);
  if (iTR < 1) iTR = 1;
  if (iTR > NTR-3) iTR = NTR-3;
  frac2 = (logTR - log(TR_MIN))/atomic->DlogTR - iTR;
  coeff2[0] = frac2*(frac2-1.)*(2.-frac2)/6.;
  coeff2[1] = (1.+frac2)*(1.-frac2)*(2.-frac2)/2.;
  coeff2[2] = (1.+frac2)*frac2*(2.-frac2)/2.;
  coeff2[3] = (1.+frac2)*frac2*(frac2-1.)/6.;

  for (l = 0; l <= 1; l++) {
    /* Alpha evaluated at Tm = Tr */
    Alpha_eq[l] = square(fsR/meR)* exp(atomic->logAlpha_tab[l][NTM-1][iTR-1]*coeff2[0]
                                +atomic->logAlpha_tab[l][NTM-1][iTR]*coeff2[1]
                                +atomic->logAlpha_tab[l][NTM-1][iTR+1]*coeff2[2]
                                +atomic->logAlpha_tab[l][NTM-1][iTR+2]*coeff2[3]);

    /* Beta obtained by detailed balance from Alpha(Tr, Tr) */
    /* prefactor = pow(2.0 * M_PI * mue *TR / hPc / hPc, 1.5)) * exp(-0.25*EI/TR) */
    Beta[l] = Alpha_eq[l] * SAHA_FACT(fsR, meR) * TR*sqrt(TR) *exp(-0.25*EI/TR)/(2.*l+1.);
  }

  /* Effective 2p->2s rate */
  *R2p2s = fsR*fsR*fsR*fsR*fsR*meR *
          exp(atomic->logR2p2s_tab[iTR-1]*coeff2[0]
          +atomic->logR2p2s_tab[iTR]*coeff2[1]
          +atomic->logR2p2s_tab[iTR+1]*coeff2[2]
          +atomic->logR2p2s_tab[iTR+2]*coeff2[3]);

  /**** Effective recombination coefficients Alpha(Tm, Tr) ****/

  /* Identify location to interpolate in T_RATIO */
  iTM = (long)floor((T_RATIO - T_RATIO_MIN)/atomic->DT_RATIO);
  if (iTM < 1) iTM = 1;
  if (iTM > NTM-3) iTM = NTM-3;
  frac1 = (T_RATIO - T_RATIO_MIN)/atomic->DT_RATIO - iTM;
  coeff1[0] = frac1*(frac1-1.)*(2.-frac1)/6.;
  coeff1[1] = (1.+frac1)*(1.-frac1)*(2.-frac1)/2.;
  coeff1[2] = (1.+frac1)*frac1*(2.-frac1)/2.;
  coeff1[3] = (1.+frac1)*frac1*(frac1-1.)/6.;

  for (l = 0; l <= 1; l++) {
    /* effective recombination coefficient to each level */
    for (k = 0; k < 4; k++) {
      temp[k] = atomic->logAlpha_tab[l+i][iTM-1+k][iTR-1]*coeff2[0]
                + atomic->logAlpha_tab[l+i][iTM-1+k][iTR]*coeff2[1]
                + atomic->logAlpha_tab[l+i][iTM-1+k][iTR+1]*coeff2[2]
                + atomic->logAlpha_tab[l+i][iTM-1+k][iTR+2]*coeff2[3];
    }

    Alpha[l] = square(fsR/meR)* exp(temp[0]*coeff1[0]+temp[1]*coeff1[1]
                                    +temp[2]*coeff1[2]+temp[3]*coeff1[3]);

    DAlpha[l] = Alpha[l] - Alpha_eq[l];
  }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movq 0x1d0(%rsp), %rax
movq %rdi, 0x1c0(%rsp)
movq %rsi, 0x1b8(%rsp)
movq %rdx, 0x1b0(%rsp)
movq %rcx, 0x1a8(%rsp)
movsd %xmm0, 0x1a0(%rsp)
movsd %xmm1, 0x198(%rsp)
movq %r8, 0x190(%rsp)
movsd %xmm2, 0x188(%rsp)
movsd %xmm3, 0x180(%rsp)
movq %r9, 0x178(%rsp)
movsd 0x299c5(%rip), %xmm0    # 0x1d2260
ucomisd 0x198(%rsp), %xmm0
jbe 0x1a88e7
leaq 0x40(%rsp), %rdi
movsd 0x198(%rsp), %xmm0
leaq 0x661d1(%rip), %rsi     # 0x20ea8c
movb $0x1, %al
callq 0x8090
movq 0x1d0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8660
movq 0x178(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a92cd
movsd 0x198(%rsp), %xmm0
movsd 0x29950(%rip), %xmm1    # 0x1d2248
ucomisd %xmm1, %xmm0
jbe 0x1a8925
movsd 0x29942(%rip), %xmm0    # 0x1d2248
divsd 0x198(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
movl $0x2, 0x16c(%rsp)
jmp 0x1a8942
movsd 0x198(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
movl $0x0, 0x16c(%rsp)
movsd 0x65fc6(%rip), %xmm0    # 0x20e910
ucomisd 0x1a0(%rsp), %xmm0
ja 0x1a896c
movsd 0x1a0(%rsp), %xmm0
movsd 0x2cbca(%rip), %xmm1    # 0x1d5530
ucomisd %xmm1, %xmm0
jbe 0x1a89ad
leaq 0x40(%rsp), %rdi
movsd 0x1a0(%rsp), %xmm0
leaq 0x6613e(%rip), %rsi     # 0x20eabf
movb $0x1, %al
callq 0x8090
movq 0x1d0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8660
movq 0x178(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a92cd
movsd 0x1a0(%rsp), %xmm0
callq 0x82f0
movsd %xmm0, 0x140(%rsp)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x65f35(%rip), %xmm0    # 0x20e910
callq 0x82f0
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
divsd 0x7a0(%rax), %xmm0
callq 0x85d0
cvttsd2si %xmm0, %rax
movq %rax, 0x158(%rsp)
cmpq $0x1, 0x158(%rsp)
jge 0x1a8a26
movq $0x1, 0x158(%rsp)
cmpq $0x61, 0x158(%rsp)
jle 0x1a8a3d
movq $0x61, 0x158(%rsp)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x65ebc(%rip), %xmm0    # 0x20e910
callq 0x82f0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
divsd 0x7a0(%rax), %xmm0
cvtsi2sdq 0x158(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x148(%rsp)
movsd 0x148(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movsd 0x297a1(%rip), %xmm2    # 0x1d2248
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a1c9(%rip), %xmm1    # 0x1d2c80
subsd 0x148(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2abbc(%rip), %xmm1    # 0x1d3688
divsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x29767(%rip), %xmm0    # 0x1d2248
addsd 0x148(%rsp), %xmm0
movsd 0x29756(%rip), %xmm1    # 0x1d2248
subsd 0x148(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a179(%rip), %xmm1    # 0x1d2c80
subsd 0x148(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a164(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0x29717(%rip), %xmm0    # 0x1d2248
addsd 0x148(%rsp), %xmm0
mulsd 0x148(%rsp), %xmm0
movsd 0x2a135(%rip), %xmm1    # 0x1d2c80
subsd 0x148(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a120(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x296d3(%rip), %xmm0    # 0x1d2248
addsd 0x148(%rsp), %xmm0
mulsd 0x148(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movsd 0x296b0(%rip), %xmm2    # 0x1d2248
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x2aae0(%rip), %xmm1    # 0x1d3688
divsd %xmm1, %xmm0
movsd %xmm0, 0x108(%rsp)
movl $0x0, 0x174(%rsp)
cmpl $0x1, 0x174(%rsp)
ja 0x1a8d61
movsd 0x188(%rsp), %xmm0
movsd 0x180(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x1a5650
movsd %xmm0, 0x10(%rsp)
movq 0x190(%rsp), %rax
movl 0x174(%rsp), %ecx
movq 0x460(%rax,%rcx,8), %rax
movq 0x138(%rax), %rax
movq 0x158(%rsp), %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
movsd (%rax,%rcx,8), %xmm1
movsd 0xf0(%rsp), %xmm2
movsd 0xf8(%rsp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x8(%rax,%rcx,8), %xmm1
movsd 0x100(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rax,%rcx,8), %xmm0
movsd 0x108(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x8670
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movl 0x174(%rsp), %eax
movsd %xmm0, 0xc0(%rsp,%rax,8)
movl 0x174(%rsp), %eax
movsd 0xc0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x188(%rsp), %xmm0
movsd 0x180(%rsp), %xmm1
callq 0x1a7770
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x1a0(%rsp), %xmm0
mulsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
callq 0x82e0
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x1a0(%rsp), %xmm1
movsd 0x65c07(%rip), %xmm0    # 0x20e908
divsd %xmm1, %xmm0
callq 0x8670
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movl 0x174(%rsp), %eax
cvtsi2sd %rax, %xmm1
addsd %xmm1, %xmm1
movsd 0x29519(%rip), %xmm2    # 0x1d2248
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq 0x1b0(%rsp), %rax
movl 0x174(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x1a8bc0
movsd 0x188(%rsp), %xmm0
mulsd 0x188(%rsp), %xmm0
mulsd 0x188(%rsp), %xmm0
mulsd 0x188(%rsp), %xmm0
mulsd 0x188(%rsp), %xmm0
mulsd 0x180(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x190(%rsp), %rax
movq 0x158(%rsp), %rcx
subq $0x1, %rcx
movsd 0x480(%rax,%rcx,8), %xmm0
movsd 0xf0(%rsp), %xmm2
movq 0x190(%rsp), %rax
movq 0x158(%rsp), %rcx
movsd 0x480(%rax,%rcx,8), %xmm1
mulsd 0xf8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
movq 0x158(%rsp), %rcx
movsd 0x488(%rax,%rcx,8), %xmm1
movsd 0x100(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x190(%rsp), %rax
movq 0x158(%rsp), %rcx
movsd 0x490(%rax,%rcx,8), %xmm0
movsd 0x108(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x8670
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x1a8(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x138(%rsp), %xmm0
movsd 0x293f0(%rip), %xmm1    # 0x1d2260
subsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
divsd 0x7a8(%rax), %xmm0
callq 0x85d0
cvttsd2si %xmm0, %rax
movq %rax, 0x160(%rsp)
cmpq $0x1, 0x160(%rsp)
jge 0x1a8ead
movq $0x1, 0x160(%rsp)
cmpq $0x25, 0x160(%rsp)
jle 0x1a8ec4
movq $0x25, 0x160(%rsp)
movsd 0x138(%rsp), %xmm0
movsd 0x2938b(%rip), %xmm1    # 0x1d2260
subsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
divsd 0x7a8(%rax), %xmm0
cvtsi2sdq 0x160(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x150(%rsp)
movsd 0x150(%rsp), %xmm0
movsd 0x150(%rsp), %xmm1
movsd 0x2932e(%rip), %xmm2    # 0x1d2248
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x29d56(%rip), %xmm1    # 0x1d2c80
subsd 0x150(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a749(%rip), %xmm1    # 0x1d3688
divsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
movsd 0x292f4(%rip), %xmm0    # 0x1d2248
addsd 0x150(%rsp), %xmm0
movsd 0x292e3(%rip), %xmm1    # 0x1d2248
subsd 0x150(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x29d06(%rip), %xmm1    # 0x1d2c80
subsd 0x150(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x29cf1(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x292a4(%rip), %xmm0    # 0x1d2248
addsd 0x150(%rsp), %xmm0
mulsd 0x150(%rsp), %xmm0
movsd 0x29cc2(%rip), %xmm1    # 0x1d2c80
subsd 0x150(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x29cad(%rip), %xmm1    # 0x1d2c80
divsd %xmm1, %xmm0
movsd %xmm0, 0x120(%rsp)
movsd 0x29260(%rip), %xmm0    # 0x1d2248
addsd 0x150(%rsp), %xmm0
mulsd 0x150(%rsp), %xmm0
movsd 0x150(%rsp), %xmm1
movsd 0x2923d(%rip), %xmm2    # 0x1d2248
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x2a66d(%rip), %xmm1    # 0x1d3688
divsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
movl $0x0, 0x174(%rsp)
cmpl $0x1, 0x174(%rsp)
ja 0x1a92cd
movl $0x0, 0x170(%rsp)
cmpl $0x4, 0x170(%rsp)
jae 0x1a91de
movq 0x190(%rsp), %rax
movl 0x174(%rsp), %ecx
addl 0x16c(%rsp), %ecx
movl %ecx, %ecx
movq 0x460(%rax,%rcx,8), %rax
movq 0x160(%rsp), %rcx
subq $0x1, %rcx
movl 0x170(%rsp), %edx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x158(%rsp), %rcx
subq $0x1, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0xf0(%rsp), %xmm2
movq 0x190(%rsp), %rax
movl 0x174(%rsp), %ecx
addl 0x16c(%rsp), %ecx
movl %ecx, %ecx
movq 0x460(%rax,%rcx,8), %rax
movq 0x160(%rsp), %rcx
subq $0x1, %rcx
movl 0x170(%rsp), %edx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x158(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd 0xf8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x190(%rsp), %rax
movl 0x174(%rsp), %ecx
addl 0x16c(%rsp), %ecx
movl %ecx, %ecx
movq 0x460(%rax,%rcx,8), %rax
movq 0x160(%rsp), %rcx
subq $0x1, %rcx
movl 0x170(%rsp), %edx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x158(%rsp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm1
movsd 0x100(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x190(%rsp), %rax
movl 0x174(%rsp), %ecx
addl 0x16c(%rsp), %ecx
movl %ecx, %ecx
movq 0x460(%rax,%rcx,8), %rax
movq 0x160(%rsp), %rcx
subq $0x1, %rcx
movl 0x170(%rsp), %edx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x158(%rsp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
movsd 0x108(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movl 0x170(%rsp), %eax
movsd %xmm0, 0xd0(%rsp,%rax,8)
movl 0x170(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x170(%rsp)
jmp 0x1a904c
movsd 0x188(%rsp), %xmm0
divsd 0x180(%rsp), %xmm0
callq 0x1a5650
movsd %xmm0, (%rsp)
movsd 0xd0(%rsp), %xmm0
movsd 0x110(%rsp), %xmm2
movsd 0xd8(%rsp), %xmm1
mulsd 0x118(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0xe0(%rsp), %xmm1
movsd 0x120(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xe8(%rsp), %xmm0
movsd 0x128(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x8670
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x1c0(%rsp), %rax
movl 0x174(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movq 0x1c0(%rsp), %rax
movl 0x174(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movl 0x174(%rsp), %eax
subsd 0xc0(%rsp,%rax,8), %xmm0
movq 0x1b8(%rsp), %rax
movl 0x174(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x1a9033
addq $0x1c8, %rsp            # imm = 0x1C8
retq
nopw %cs:(%rax,%rax)