// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hydrogen.c
// Function: allocate_and_read_atomic
void allocate_and_read_atomic(HYREC_ATOMIC *atomic, int *error, char *path_to_hyrec, char error_message[SIZE_ErrorM]){

  /*********** Effective rates *************/

  char *alpha_file, *rr_file, *twog_file;
  char sub_message[128];
  alpha_file = malloc(SIZE_InputFile);
  alpha_file[0] = 0;
  strcat(alpha_file, path_to_hyrec);
  strcat(alpha_file, ALPHA_FILE);

  FILE *fA = fopen(alpha_file, "r");
  if (fA == NULL) {
    sprintf(sub_message, "in allocate_and_read_atomic: could not open file %s \n", alpha_file);
    strcat(error_message, sub_message);
    *error = 1;
    return;
  }

  rr_file = malloc(SIZE_InputFile);
  rr_file[0] = 0;
  strcat(rr_file, path_to_hyrec);
  strcat(rr_file, RR_FILE);

  FILE *fR = fopen(rr_file, "r");
  if (fR == NULL) {
    sprintf(sub_message, "in allocate_and_read_atomic: could not open file %s \n", rr_file);
    strcat(error_message, sub_message);
    *error = 1;
    return;
  }

  unsigned i, j, l;

  /* Allocate memory */
  atomic->logAlpha_tab[0] = create_2D_array(NTM, NTR, error, error_message);
  atomic->logAlpha_tab[1] = create_2D_array(NTM, NTR, error, error_message);
  atomic->logAlpha_tab[2] = create_2D_array(NTM, NTR, error, error_message);
  atomic->logAlpha_tab[3] = create_2D_array(NTM, NTR, error, error_message);

  maketab(log(TR_MIN), log(TR_MAX), NTR, atomic->logTR_tab);
  maketab(T_RATIO_MIN, T_RATIO_MAX, NTM, atomic->T_RATIO_tab);
  atomic->DlogTR = atomic->logTR_tab[1] - atomic->logTR_tab[0];
  atomic->DT_RATIO = atomic->T_RATIO_tab[1] - atomic->T_RATIO_tab[0];

  for (i = 0; i < NTR; i++) {
    for (j = 0; j < NTM; j++) for (l = 0; l <= 3; l++) {
      if( fscanf(fA, "%le", &(atomic->logAlpha_tab[l][j][i])) != 1){
        sprintf(sub_message, "in allocate_and_read_atomic: could not read file %s completely -- The file might be corrupted\n", alpha_file);
        strcat(error_message, sub_message);
        *error = 1;
        return;
      }
      atomic->logAlpha_tab[l][j][i] = log(atomic->logAlpha_tab[l][j][i]);
    }
    if ( fscanf(fR, "%le", &(atomic->logR2p2s_tab[i])) != 1){
        sprintf(sub_message, "in allocate_and_read_atomic: could not read file %s completely -- The file might be corrupted\n", rr_file);
        strcat(error_message, sub_message);
        *error = 1;
        return;
    }
    atomic->logR2p2s_tab[i] = log(atomic->logR2p2s_tab[i]);
  }
  fclose(fA);
  fclose(fR);

  /************ Two-photon rates ************/

  FILE *f2g;
  unsigned b;
  double L2s1s_current;
  int fscanf_counter;

  twog_file = malloc(SIZE_InputFile);
  twog_file[0] = 0;
  strcat(twog_file, path_to_hyrec);
  strcat(twog_file, TWOG_FILE);

  f2g = fopen(twog_file, "r");
  if (f2g == NULL) {
    sprintf(sub_message, "in allocate_and_read_atomic: could not open file %s \n", twog_file);
    strcat(error_message, sub_message);
    *error = 1;
    return;
  }

  for (b = 0; b < NVIRT; b++) {
    fscanf_counter = 0;
    fscanf_counter+= fscanf(f2g, "%le", &(atomic->Eb_tab[b]));
    fscanf_counter+= fscanf(f2g, "%le", &(atomic->A1s_tab[b]));
    fscanf_counter+= fscanf(f2g, "%le", &(atomic->A2s_tab[b]));
    fscanf_counter+= fscanf(f2g, "%le", &(atomic->A3s3d_tab[b]));
    fscanf_counter+= fscanf(f2g, "%le", &(atomic->A4s4d_tab[b]));
    if(fscanf_counter!=5){
      sprintf(sub_message, "in allocate_and_read_atomic: could not read file %s completely -- The file might be corrupted\n", twog_file);
      strcat(error_message, sub_message);
      *error = 1;
      return;
    }
  }
  fclose(f2g);

  /* Normalize 2s--1s differential decay rate to L2s1s (can be set by user in hydrogen.h) */
  L2s1s_current = 0.;
  for (b = 0; b < NSUBLYA; b++) L2s1s_current += atomic->A2s_tab[b];
  for (b = 0; b < NSUBLYA; b++) atomic->A2s_tab[b] *= L2s1s/L2s1s_current;

  /* Switches for the various effects considered in Hirata (2008) and diffusion:
      Effect A: correct 2s-->1s rate, with stimulated decays and absorptions of non-thermal photons
      Effect B: Sub-Lyman-alpha two-photon decays
      Effect C: Super-Lyman-alpha two-photon decays
      Effect D: Raman scattering */

  #if (EFFECT_A == 0)
    for (b = 0; b < NSUBLYA; b++) atomic->A2s_tab[b] = 0;
  #endif
  #if (EFFECT_B == 0)
    for (b = 0; b < NSUBLYA; b++) atomic->A3s3d_tab[b] = atomic->A4s4d_tab[b] = 0;
  #endif
  #if (EFFECT_C == 0)
    for (b = NSUBLYA; b < NVIRT; b++) atomic->A3s3d_tab[b] = atomic->A4s4d_tab[b] = 0;
  #endif
  #if (EFFECT_D == 0)
    for (b = NSUBLYA; b < NVIRT; b++) atomic->A2s_tab[b] = 0;
    for (b = NSUBLYB; b < NVIRT; b++) atomic->A3s3d_tab[b] = 0;
  #endif
  #if (DIFFUSION == 0)
    for (b = 0; b < NVIRT; b++) atomic->A1s_tab[b] = 0;
  #endif

  free(alpha_file);
  free(rr_file);
  free(twog_file);

}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movq %rcx, 0xe8(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x8460
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movb $0x0, (%rax)
movq 0xe0(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x8660
movq 0xe0(%rsp), %rdi
leaq 0x66bd0(%rip), %rsi     # 0x20e988
callq 0x8660
movq 0xe0(%rsp), %rdi
leaq 0x48e6b(%rip), %rsi     # 0x1f0c37
callq 0x8410
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x1a7e1e
leaq 0x50(%rsp), %rdi
movq 0xe0(%rsp), %rdx
leaq 0x66ba4(%rip), %rsi     # 0x20e996
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
movl $0x200, %edi            # imm = 0x200
callq 0x8460
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movb $0x0, (%rax)
movq 0xd8(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x8660
movq 0xd8(%rsp), %rdi
leaq 0x66b6d(%rip), %rsi     # 0x20e9cc
callq 0x8660
movq 0xd8(%rsp), %rdi
leaq 0x48dc4(%rip), %rsi     # 0x1f0c37
callq 0x8410
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x1a7ec5
leaq 0x50(%rsp), %rdi
movq 0xd8(%rsp), %rdx
leaq 0x66afd(%rip), %rsi     # 0x20e996
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
movq 0xf8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movl $0x28, %edi
movl $0x64, %esi
callq 0x1a5750
movq %rax, %rcx
movq 0x100(%rsp), %rax
movq %rcx, 0x460(%rax)
movq 0xf8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movl $0x28, %edi
movl $0x64, %esi
callq 0x1a5750
movq %rax, %rcx
movq 0x100(%rsp), %rax
movq %rcx, 0x468(%rax)
movq 0xf8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movl $0x28, %edi
movl $0x64, %esi
callq 0x1a5750
movq %rax, %rcx
movq 0x100(%rsp), %rax
movq %rcx, 0x470(%rax)
movq 0xf8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movl $0x28, %edi
movl $0x64, %esi
callq 0x1a5750
movq %rax, %rcx
movq 0x100(%rsp), %rax
movq %rcx, 0x478(%rax)
movsd 0x6697f(%rip), %xmm0    # 0x20e910
callq 0x82f0
movsd %xmm0, 0x8(%rsp)
movsd 0x2d58c(%rip), %xmm0    # 0x1d5530
callq 0x82f0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
movq 0x100(%rsp), %rsi
movl $0x64, %edi
callq 0x1a5a50
movq 0x100(%rsp), %rsi
addq $0x320, %rsi            # imm = 0x320
movsd 0x2a285(%rip), %xmm0    # 0x1d2260
movsd 0x2a265(%rip), %xmm1    # 0x1d2248
movl $0x28, %edi
callq 0x1a5a50
movq 0x100(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x100(%rsp), %rax
subsd (%rax), %xmm0
movq 0x100(%rsp), %rax
movsd %xmm0, 0x7a0(%rax)
movq 0x100(%rsp), %rax
movsd 0x328(%rax), %xmm0
movq 0x100(%rsp), %rax
subsd 0x320(%rax), %xmm0
movq 0x100(%rsp), %rax
movsd %xmm0, 0x7a8(%rax)
movl $0x0, 0x3c(%rsp)
cmpl $0x64, 0x3c(%rsp)
jae 0x1a8220
movl $0x0, 0x38(%rsp)
cmpl $0x28, 0x38(%rsp)
jae 0x1a816f
movl $0x0, 0x34(%rsp)
cmpl $0x3, 0x34(%rsp)
ja 0x1a815d
movq 0x48(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x34(%rsp), %ecx
movq 0x460(%rax,%rcx,8), %rax
movl 0x38(%rsp), %ecx
movq (%rax,%rcx,8), %rdx
movl 0x3c(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x6313c(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
cmpl $0x1, %eax
je 0x1a80fe
leaq 0x50(%rsp), %rdi
movq 0xe0(%rsp), %rdx
leaq 0x66904(%rip), %rsi     # 0x20e9d6
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
movq 0x100(%rsp), %rax
movl 0x34(%rsp), %ecx
movq 0x460(%rax,%rcx,8), %rax
movl 0x38(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x3c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
callq 0x82f0
movq 0x100(%rsp), %rax
movl 0x34(%rsp), %ecx
movq 0x460(%rax,%rcx,8), %rax
movl 0x38(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x3c(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x1a8074
jmp 0x1a815f
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1a8061
movq 0x40(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x480, %rdx            # imm = 0x480
movl 0x3c(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x63059(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
cmpl $0x1, %eax
je 0x1a81e1
leaq 0x50(%rsp), %rdi
movq 0xd8(%rsp), %rdx
leaq 0x66821(%rip), %rsi     # 0x20e9d6
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
movq 0x100(%rsp), %rax
movl 0x3c(%rsp), %ecx
movsd 0x480(%rax,%rcx,8), %xmm0
callq 0x82f0
movq 0x100(%rsp), %rax
movl 0x3c(%rsp), %ecx
movsd %xmm0, 0x480(%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x1a804e
movq 0x48(%rsp), %rdi
callq 0x83c0
movq 0x40(%rsp), %rdi
callq 0x83c0
movl $0x200, %edi            # imm = 0x200
callq 0x8460
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movb $0x0, (%rax)
movq 0xd0(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x8660
movq 0xd0(%rsp), %rdi
leaq 0x667c0(%rip), %rsi     # 0x20ea35
callq 0x8660
movq 0xd0(%rsp), %rdi
leaq 0x489ae(%rip), %rsi     # 0x1f0c37
callq 0x8410
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x1a82db
leaq 0x50(%rsp), %rdi
movq 0xd0(%rsp), %rdx
leaq 0x666e7(%rip), %rsi     # 0x20e996
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
movl $0x0, 0x24(%rsp)
cmpl $0x137, 0x24(%rsp)      # imm = 0x137
jae 0x1a845b
movl $0x0, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x7b0, %rdx            # imm = 0x7B0
movl 0x24(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x62ecf(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x1168, %rdx           # imm = 0x1168
movl 0x24(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x62e9a(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x1b20, %rdx           # imm = 0x1B20
movl 0x24(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x62e65(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x24d8, %rdx           # imm = 0x24D8
movl 0x24(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x62e30(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movq 0x100(%rsp), %rdx
addq $0x2e90, %rdx           # imm = 0x2E90
movl 0x24(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x62dfb(%rip), %rsi     # 0x20b1ee
movb $0x0, %al
callq 0x8690
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x5, 0x14(%rsp)
je 0x1a8449
leaq 0x50(%rsp), %rdi
movq 0xd0(%rsp), %rdx
leaq 0x665b9(%rip), %rsi     # 0x20e9d6
movb $0x0, %al
callq 0x8090
movq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8660
movq 0xf8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1a8520
jmp 0x1a844b
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a82e3
movq 0x28(%rsp), %rdi
callq 0x83c0
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x0, 0x24(%rsp)
cmpl $0x8c, 0x24(%rsp)
jae 0x1a84ae
movq 0x100(%rsp), %rax
movl 0x24(%rsp), %ecx
movsd 0x1b20(%rax,%rcx,8), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a8476
movl $0x0, 0x24(%rsp)
cmpl $0x8c, 0x24(%rsp)
jae 0x1a84f9
movsd 0x66420(%rip), %xmm0    # 0x20e8e8
divsd 0x18(%rsp), %xmm0
movq 0x100(%rsp), %rax
movl 0x24(%rsp), %ecx
mulsd 0x1b20(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x1b20(%rax,%rcx,8)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1a84b6
movq 0xe0(%rsp), %rdi
callq 0x8420
movq 0xd8(%rsp), %rdi
callq 0x8420
movq 0xd0(%rsp), %rdi
callq 0x8420
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax,%rax)