// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, %rbp
movsd %xmm0, 0x10(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdi, 0x98(%rsp)
movsd 0x18b33(%rip), %xmm0    # 0xee290
ucomisd %xmm1, %xmm0
jbe 0xd577b
leaq 0x54e0a(%rip), %rsi     # 0x12a574
leaq 0xc0(%rsp), %rdi
movapd %xmm1, %xmm0
jmp 0xd5d0d
movsd 0x54c15(%rip), %xmm0    # 0x12a398
ucomisd 0x10(%rsp), %xmm0
ja 0xd5cf8
movsd 0x10(%rsp), %xmm0
ucomisd 0x1bd4b(%rip), %xmm0    # 0xf14e8
ja 0xd5cf8
movq %r8, %rbx
movq %rdx, %r13
movq %rcx, 0x90(%rsp)
movsd 0x18aa7(%rip), %xmm4    # 0xee260
movapd %xmm4, %xmm0
divsd %xmm1, %xmm0
cmpltsd %xmm1, %xmm4
andpd %xmm4, %xmm0
movapd %xmm1, 0xb0(%rsp)
andnpd %xmm1, %xmm4
orpd %xmm0, %xmm4
movapd %xmm4, 0x70(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm3, 0x60(%rsp)
movsd %xmm2, 0x58(%rsp)
callq 0x82c0
addsd 0x54ba0(%rip), %xmm0    # 0x12a3a0
divsd 0x7a0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x85e0
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
movl $0x1, %ecx
cmovgeq %rax, %rcx
cmpq $0x61, %rcx
movl $0x61, %ebp
cmovlq %rcx, %rbp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x8(%rsp), %xmm5
subsd %xmm0, %xmm5
movsd 0x18f9d(%rip), %xmm0    # 0xee7e8
addsd %xmm5, %xmm0
movapd %xmm5, %xmm1
mulsd %xmm0, %xmm1
movsd 0x194a1(%rip), %xmm2    # 0xeed00
subsd %xmm5, %xmm2
mulsd %xmm2, %xmm1
movsd 0x19e01(%rip), %xmm4    # 0xef670
divsd %xmm4, %xmm1
movsd %xmm1, 0x50(%rsp)
movapd %xmm5, %xmm1
movsd 0x189db(%rip), %xmm3    # 0xee260
addsd %xmm3, %xmm1
subsd %xmm5, %xmm3
movapd %xmm5, %xmm6
mulsd %xmm1, %xmm3
mulsd %xmm2, %xmm3
movsd 0x1942f(%rip), %xmm5    # 0xeecd0
mulsd %xmm5, %xmm3
movsd %xmm3, 0x38(%rsp)
mulsd %xmm6, %xmm1
mulsd %xmm1, %xmm2
mulsd %xmm5, %xmm2
movsd %xmm2, 0x48(%rsp)
mulsd %xmm0, %xmm1
divsd %xmm4, %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x58(%rsp), %xmm2
movapd %xmm2, %xmm0
movsd 0x60(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x54a7d(%rip), %xmm0    # 0x12a378
movsd 0x10(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x80(%rsp), %r15
movb $0x1, %r12b
xorl %r14d, %r14d
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0xd3754
movsd %xmm0, 0x8(%rsp)
movq 0x460(%rbx,%r14,8), %rax
movq 0x138(%rax), %rax
movsd (%rax,%rbp,8), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd -0x8(%rax,%rbp,8), %xmm1
mulsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x8(%rax,%rbp,8), %xmm2
mulsd 0x48(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x10(%rax,%rbp,8), %xmm0
mulsd 0x40(%rsp), %xmm0
addsd %xmm2, %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%r15)
movsd 0x30(%rsp), %xmm0
callq 0xd3759
movapd %xmm0, %xmm1
mulsd 0x549a2(%rip), %xmm1    # 0x12a350
movsd 0x10(%rsp), %xmm0
ucomisd 0x1889c(%rip), %xmm0    # 0xee258
movsd 0x20(%rsp), %xmm0
jae 0xd59db
movsd 0x10(%rsp), %xmm0
movsd %xmm1, 0x18(%rsp)
callq 0x82b0
movsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
addsd %xmm1, %xmm1
addsd 0x18846(%rip), %xmm1    # 0xee260
divsd %xmm1, %xmm0
movsd %xmm0, (%r13,%r14,8)
movl $0x1, %r14d
leaq 0xa8(%rsp), %r15
testb $0x1, %r12b
movl $0x0, %r12d
jne 0xd5926
xorl %r14d, %r14d
movsd 0x18812(%rip), %xmm1    # 0xee260
movapd 0xb0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
seta %r14b
movsd 0x58(%rsp), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x60(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x480(%rbx,%rbp,8), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd 0x478(%rbx,%rbp,8), %xmm1
mulsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x488(%rbx,%rbp,8), %xmm2
mulsd 0x48(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x490(%rbx,%rbp,8), %xmm0
mulsd 0x40(%rsp), %xmm0
addsd %xmm2, %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
movq 0x90(%rsp), %rax
movsd %xmm0, (%rax)
movapd 0x70(%rsp), %xmm0
addsd 0x548b6(%rip), %xmm0    # 0x12a3a8
movq %rbx, 0x28(%rsp)
divsd 0x7a8(%rbx), %xmm0
movapd %xmm0, 0x70(%rsp)
callq 0x85e0
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
movl $0x1, %ecx
cmovgeq %rax, %rcx
cmpq $0x25, %rcx
movl $0x25, %r12d
cmovlq %rcx, %r12
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd 0x70(%rsp), %xmm6
subsd %xmm0, %xmm6
movsd 0x18ca4(%rip), %xmm0    # 0xee7e8
addsd %xmm6, %xmm0
movapd %xmm6, %xmm3
mulsd %xmm0, %xmm3
movsd 0x191a8(%rip), %xmm1    # 0xeed00
subsd %xmm6, %xmm1
mulsd %xmm1, %xmm3
movsd 0x19b08(%rip), %xmm2    # 0xef670
divsd %xmm2, %xmm3
movsd %xmm3, 0x20(%rsp)
movapd %xmm6, %xmm4
movsd 0x186e2(%rip), %xmm5    # 0xee260
addsd %xmm5, %xmm4
subsd %xmm6, %xmm5
mulsd %xmm4, %xmm5
mulsd %xmm1, %xmm5
movsd 0x1913a(%rip), %xmm3    # 0xeecd0
mulsd %xmm3, %xmm5
movsd %xmm5, 0x10(%rsp)
mulsd %xmm6, %xmm4
mulsd %xmm4, %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x30(%rsp)
mulsd %xmm0, %xmm4
divsd %xmm2, %xmm4
movsd %xmm4, 0x18(%rsp)
addl %r14d, %r14d
movq %r14, %rbx
leaq 0x80(%rsp), %r13
movb $0x1, %r14b
xorl %r15d, %r15d
movq %r15, %rax
orq %rbx, %rax
movq 0x28(%rsp), %rcx
movq 0x460(%rcx,%rax,8), %rax
leaq (%rax,%r12,8), %rax
addq $-0x8, %rax
xorl %ecx, %ecx
movsd 0x50(%rsp), %xmm2
movsd 0x48(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movq (%rax,%rcx,8), %rdx
movsd (%rdx,%rbp,8), %xmm0
mulsd %xmm5, %xmm0
movsd -0x8(%rdx,%rbp,8), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x8(%rdx,%rbp,8), %xmm0
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd 0x10(%rdx,%rbp,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0xc0(%rsp,%rcx,8)
incq %rcx
cmpq $0x4, %rcx
jne 0xd5c09
movsd 0x68(%rsp), %xmm0
callq 0xd3754
movsd %xmm0, 0x8(%rsp)
movsd 0xc8(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
mulsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0xd0(%rsp), %xmm2
mulsd 0x30(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0xd8(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
addsd %xmm2, %xmm0
callq 0x8670
mulsd 0x8(%rsp), %xmm0
movq 0x98(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
subsd (%r13), %xmm0
movq 0xa0(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
movl $0x1, %r15d
leaq 0xa8(%rsp), %r13
testb $0x1, %r14b
movl $0x0, %r14d
jne 0xd5bd4
jmp 0xd5d30
leaq 0x548a8(%rip), %rsi     # 0x12a5a7
leaq 0xc0(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x8090
movq 0x180(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x8660
movl $0x1, (%rbp)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq