// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %r9, %rbp
movsd %xmm3, 0x10(%rsp)
movsd %xmm2, 0x8(%rsp)
movq %rsi, 0x78(%rsp)
movsd 0x17673(%rip), %xmm2    # 0xe5290
ucomisd %xmm1, %xmm2
jbe 0xcdc3b
leaq 0x537c2(%rip), %rsi     # 0x1213ec
leaq 0xa0(%rsp), %rdi
movapd %xmm1, %xmm0
jmp 0xcded7
movsd 0x535f5(%rip), %xmm2    # 0x121238
ucomisd %xmm0, %xmm2
ja 0xcdec8
ucomisd 0x1a853(%rip), %xmm0    # 0xe84a8
ja 0xcdec8
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r13
movq %rdi, %r15
movsd 0x175f1(%rip), %xmm2    # 0xe5260
movapd %xmm2, %xmm3
divsd %xmm1, %xmm3
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm3
movapd %xmm1, 0x80(%rsp)
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movapd %xmm2, 0x50(%rsp)
movsd %xmm0, 0x18(%rsp)
callq 0x82e0
addsd 0x53596(%rip), %xmm0    # 0x121240
divsd 0x7a0(%rbx), %xmm0
movsd %xmm0, (%rsp)
callq 0x8610
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
pushq $0x1
popq %rcx
cmovlq %rcx, %rax
cmpq $0x61, %rax
pushq $0x61
popq %rbp
cmovlq %rax, %rbp
cvtsi2sd %ebp, %xmm0
movsd (%rsp), %xmm6
subsd %xmm0, %xmm6
movsd 0x17afc(%rip), %xmm0    # 0xe57e8
addsd %xmm6, %xmm0
movapd %xmm6, %xmm2
mulsd %xmm0, %xmm2
movsd 0x17fe0(%rip), %xmm3    # 0xe5ce0
subsd %xmm6, %xmm3
mulsd %xmm3, %xmm2
movsd 0x18940(%rip), %xmm5    # 0xe6650
divsd %xmm5, %xmm2
movapd %xmm6, %xmm4
movsd 0x17540(%rip), %xmm1    # 0xe5260
addsd %xmm1, %xmm4
subsd %xmm6, %xmm1
movapd %xmm6, %xmm7
mulsd %xmm4, %xmm1
mulsd %xmm3, %xmm1
movsd 0x17f74(%rip), %xmm6    # 0xe5cb0
mulsd %xmm6, %xmm1
mulsd %xmm7, %xmm4
mulsd %xmm4, %xmm3
mulsd %xmm6, %xmm3
mulsd %xmm0, %xmm4
divsd %xmm5, %xmm4
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x534aa(%rip), %xmm0    # 0x121218
movsd 0x18(%rsp), %xmm5
divsd %xmm5, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
sqrtsd %xmm5, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd %xmm2, 0x40(%rsp)
movsd %xmm3, 0x38(%rsp)
movsd %xmm4, 0x30(%rsp)
movsd %xmm1, 0x28(%rsp)
cmpq $0x2, %r12
je 0xcdf0c
movsd 0x48(%rsp), %xmm0
callq 0xcbe48
movsd %xmm0, (%rsp)
movq 0x460(%rbx,%r12,8), %rax
movq 0x138(%rax), %rax
movsd (%rax,%rbp,8), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd -0x8(%rax,%rbp,8), %xmm1
mulsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x8(%rax,%rbp,8), %xmm2
mulsd 0x38(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x10(%rax,%rbp,8), %xmm0
mulsd 0x30(%rsp), %xmm0
addsd %xmm2, %xmm0
callq 0x86a0
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x90(%rsp,%r12,8)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xcd0fc
movapd %xmm0, %xmm2
movsd 0x18(%rsp), %xmm1
ucomisd 0x17415(%rip), %xmm1    # 0xe5258
movsd 0x70(%rsp), %xmm0
jae 0xcde66
movapd %xmm1, %xmm0
movsd %xmm2, 0x68(%rsp)
callq 0x82d0
movsd 0x68(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd (%rsp), %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movsd %xmm3, (%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x86a0
mulsd (%rsp), %xmm0
cvtsi2sd %r12d, %xmm1
addsd %xmm1, %xmm1
addsd 0x173c3(%rip), %xmm1    # 0xe5260
divsd %xmm1, %xmm0
movsd %xmm0, (%r13,%r12,8)
incq %r12
movsd 0x40(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm1
jmp 0xcdda3
leaq 0x53550(%rip), %rsi     # 0x12141f
leaq 0xa0(%rsp), %rdi
movb $0x1, %al
callq 0x8090
movq 0x160(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x8690
movl $0x1, (%rbp)
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movsd 0x17349(%rip), %xmm5    # 0xe5260
movapd 0x80(%rsp), %xmm0
ucomisd %xmm5, %xmm0
seta %r13b
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd 0x10(%rsp), %xmm5
movsd %xmm5, (%rsp)
movsd 0x480(%rbx,%rbp,8), %xmm0
mulsd %xmm1, %xmm0
movsd 0x478(%rbx,%rbp,8), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x488(%rbx,%rbp,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x490(%rbx,%rbp,8), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm2, %xmm0
callq 0x86a0
mulsd (%rsp), %xmm0
movsd %xmm0, (%r14)
movapd 0x50(%rsp), %xmm0
addsd 0x5329e(%rip), %xmm0    # 0x121248
divsd 0x7a8(%rbx), %xmm0
movapd %xmm0, 0x50(%rsp)
callq 0x8610
cvttsd2si %xmm0, %rax
cmpq $0x2, %rax
pushq $0x1
popq %rcx
cmovgeq %rax, %rcx
cmpq $0x25, %rcx
pushq $0x25
popq %r12
cmovlq %rcx, %r12
cvtsi2sd %r12d, %xmm0
movapd 0x50(%rsp), %xmm6
subsd %xmm0, %xmm6
movsd 0x177f8(%rip), %xmm0    # 0xe57e8
addsd %xmm6, %xmm0
movapd %xmm6, %xmm3
mulsd %xmm0, %xmm3
movsd 0x17cdc(%rip), %xmm1    # 0xe5ce0
subsd %xmm6, %xmm1
mulsd %xmm1, %xmm3
movsd 0x1863c(%rip), %xmm2    # 0xe6650
divsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rsp)
movapd %xmm6, %xmm4
movsd 0x17236(%rip), %xmm5    # 0xe5260
addsd %xmm5, %xmm4
subsd %xmm6, %xmm5
mulsd %xmm4, %xmm5
mulsd %xmm1, %xmm5
movsd 0x17c6e(%rip), %xmm3    # 0xe5cb0
mulsd %xmm3, %xmm5
movsd %xmm5, 0x18(%rsp)
mulsd %xmm6, %xmm4
mulsd %xmm4, %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, 0x10(%rsp)
mulsd %xmm0, %xmm4
divsd %xmm2, %xmm4
movsd %xmm4, 0x20(%rsp)
addl %r13d, %r13d
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xcdefa
movq %r14, %rax
orq %r13, %rax
movq 0x460(%rbx,%rax,8), %rax
leaq (%rax,%r12,8), %rax
addq $-0x8, %rax
xorl %ecx, %ecx
movsd 0x40(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm5
cmpq $0x4, %rcx
je 0xce0f7
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, 0xa0(%rsp,%rcx,8)
incq %rcx
jmp 0xce0ac
movsd 0x48(%rsp), %xmm0
callq 0xcbe48
movsd %xmm0, (%rsp)
movsd 0xa8(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
mulsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0xb0(%rsp), %xmm2
mulsd 0x10(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0xb8(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
addsd %xmm2, %xmm0
callq 0x86a0
mulsd (%rsp), %xmm0
movsd %xmm0, (%r15,%r14,8)
subsd 0x90(%rsp,%r14,8), %xmm0
movq 0x78(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
jmp 0xce072