// File: /workspace/github_cpp_makefile_star2_O1/akdess[P]BAFExtract/src/main.cpp
// Function: dump_nucleotide_pileup_per_SAM_file(char*, std::vector<char*, std::allocator<char*>>*, std::vector<int, std::allocator<int>>*, char*, int, int, int&)
void dump_nucleotide_pileup_per_SAM_file(char* sam_fp, vector<char*>* chr_ids, vector<int>* chr_lengths, char* op_dir, int min_mapp_qual, int min_phred_qual, int& n_processed_reads)
{
  fprintf(stderr, "Generating pileup from SAM file with min mapp qual %d, min base qual %d\n", min_mapp_qual, min_phred_qual);

  //// Init the file.
  //char summary_fp[1000];
  //sprintf(summary_fp, "%s/%s", op_dir, t_config_params::OP_filenames[OP_PILEUP_SUMMARY_FN]);
  //FILE* f_summary = open_f(summary_fp, "w");
  //fclose(f_summary);

  // Initialize the number of processed readss.
  n_processed_reads = 0;

  //// Make sure we do not overwrite on an existing set of pileup file, since they are time consuming to generate.
  //bool allele_counts_are_there = true;
  //for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
  //{
  //  char cur_allele_fp[1000];
  //  sprintf(cur_allele_fp, "%s/%s_allele_counts.bin", op_dir, chr_ids->at(i_chr));
  //  if(!check_file(cur_allele_fp))
  //  {
  //    // This file does not exist, not all the allele counts are there.
  //    allele_counts_are_there = false;
  //    break;
  //  }
  //} // i_chr loop.

  //if(allele_counts_are_there)
  //{
  //  fprintf(stderr, "All the chromosome pileups exist, will not process data.\n");
  //  return;
  //}

  fprintf(stderr, "Dumping the pileups per SAM file %s\n", sam_fp);

  fprintf(stderr, "Allocating pileup memory.\n");
  unsigned short*** per_chrom_nuc_count_per_allele = new unsigned short**[(int)chr_ids->size()];
  //int** per_chrom_coverage = new int*[(int)chr_ids->size()];
  for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
  {
    int l_sig = chr_lengths->at(i_chr);

    // Check the existing pileup file, if it is there, add to it.
    char cur_allele_fp[1000];
    sprintf(cur_allele_fp, "%s/%s_allele_counts.bin", op_dir, chr_ids->at(i_chr));
    if(check_file(cur_allele_fp))
    {
      int l_loaded_pileup = 0;
      per_chrom_nuc_count_per_allele[i_chr] = load_compressed_pileups(cur_allele_fp, l_loaded_pileup);
      if(l_loaded_pileup != chr_lengths->at(i_chr))
      {
        fprintf(stderr, "Loaded pileup is not the same length as the chromosome info: %s: %d, %d\n", chr_ids->at(i_chr), chr_lengths->at(i_chr));
        exit(0);
      }
      else
      {
        fprintf(stderr, "Loaded existing pileup from %s.\n", cur_allele_fp);
      }
    }
    else
    {
      per_chrom_nuc_count_per_allele[i_chr] = allocate_pileup(l_sig);
    }
  } // i_chr loop.
  fprintf(stderr, "Done.\n");

  int max_n_alleles_per_posn = 1<<16;
  fprintf(stderr, "Maximum # of alleles at each position: %d\n", max_n_alleles_per_posn);

  // Start reading the file.
  FILE* f_sam = NULL;
  if(strcmp(sam_fp, "stdin") == 0)
  {
    f_sam = stdin;
  }
  else
  {
    f_sam = fopen(sam_fp, "r");
  }

  int* per_nuc_val = get_per_char_as_nuc_2_num_coding_array();
  //for(int i = 0; i < 256; i++)
  //{
  //  per_nuc_val[i] = 4;
  //} // i loop.
  //per_nuc_val[(int)'A'] = 0;
  //per_nuc_val[(int)'C'] = 1;
  //per_nuc_val[(int)'G'] = 2;
  //per_nuc_val[(int)'T'] = 3;
  //per_nuc_val[(int)'U'] = 3;
  //per_nuc_val[(int)'a'] = 0;
  //per_nuc_val[(int)'c'] = 1;
  //per_nuc_val[(int)'g'] = 2;
  //per_nuc_val[(int)'t'] = 3;
  //per_nuc_val[(int)'u'] = 3;

  // Enter file reading loop.
  char read_id[1000];
  //int flag;
  char chrom[100];
  int chr_index;
  char mapping_map_str[10000];
  char cur_fragment[1000];
  char flag_str[100];
  char _chr_index_str[100];
  char phred_quality_str[100000];
  char mapp_quality_str[100];

  int n_unmapped_reads = 0;
  int n_low_quality_reads = 0;

  int phred_score_base = -123;

  while(1)
  {
    char* cur_line = getline(f_sam);

    if(cur_line == NULL)
    {
      break;
    }

    // If this is a comment line, skip it.
    if(cur_line[0] == '@')
    {
      delete [] cur_line;
      continue;
    }

    if(sscanf(cur_line, "%[^\t] %[^\t] %[^\t] %[^\t] %[^\t] %[^\t] %*[^\t] %*[^\t] %*[^\t] %[^\t] %[^\t]", read_id, flag_str, chrom, _chr_index_str, mapp_quality_str ,mapping_map_str, cur_fragment, phred_quality_str) == 8)
    {
      if(phred_score_base == -123)
      {
        int l_read = strlen(phred_quality_str);
        for(int i = 0; i < l_read; i++)
        {
          if(phred_quality_str[i] > 'J')
          {
            fprintf(stderr, "Phred+64 encoding @ %d. read (%c):\n%s\n%s\n", n_processed_reads, phred_quality_str[i],
              cur_fragment, phred_quality_str);
            phred_score_base = ';';
            break;
          }
          else if(phred_quality_str[i] < ';')
          {
            fprintf(stderr, "Phred+33 encoding @ %d. read (%c):\n%s\n%s\n", n_processed_reads, phred_quality_str[i],
              cur_fragment, phred_quality_str);
            phred_score_base = '!';
            break;
          }
        } // i loop.
      }

      //fprintf(stderr, "Processing read @ %d parsed with %s:\n%s\n", chr_index, mapping_map_str, cur_fragment);
      // If the quality is not adequate, do not use this read.
      if(atoi(mapp_quality_str) < min_mapp_qual)
      {
        n_low_quality_reads++;
        delete [] cur_line;
        continue;
      }

      // Make sure the normalized chromosome ids match.
      normalize_chr_id(chrom);

      int flag = atoi(flag_str);

      int i_chr = t_string::get_i_str(chr_ids, chrom);

      // If we do not have the chromosome, do not process.
      if(i_chr == (int)chr_ids->size())
      {
        n_unmapped_reads++;
        delete [] cur_line;
        continue;
      }

      int _chr_index = atoi(_chr_index_str);

      // Translate the 0 based index in SAM file to codebase's indexing, which is 1 based inclusive.
      chr_index = translate_coord(_chr_index, SAM_COORDS::start_base, CODEBASE_COORDS::start_base);

      // Sanity check. Is this fragment mapped?
      if(flag & 0x04)
      {
        // The read is not mapping.
      }
      else
      {
        n_processed_reads++;
          
        if(n_processed_reads % 1000000 == 0)
        {
          fprintf(stderr, "Processing %d. read             \r", n_processed_reads);
        }

if(__DUMP_MAPPED_READ_TOOLS_MSGS__)
{
        fprintf(stderr, "Processing:\n%s\n%s\n", cur_fragment, phred_quality_str);
}

        int i_mapp_map = 0;
        //t_string* cur_entry_length_str = new t_string();
        bool is_matching = false;
        char entry_type_char;

        // Parse the cigar string to get the fragments.
        bool is_read_spliced = false;
        bool mapping_map_str_valid = validate_mapping_map_str(mapping_map_str, is_read_spliced);

        int read_nuc_index = 0;

        // Check if the mapping map string has splicing information, if it does and there extension length is not 0, 
        while(mapping_map_str_valid && 
          mapping_map_str[i_mapp_map] != 0)
        {
          int l_cur_entry;
          get_next_entry_per_mapp_map_string(mapping_map_str,
                            i_mapp_map, 
                            is_matching,
                            l_cur_entry,
                            entry_type_char);

          // If this block is matching, update the pileup.
          if(is_matching)
          {
            // Update the counts for the nucleotides.
            int cur_read_nuc_i = read_nuc_index;
            for(int cur_genome_i = chr_index; cur_genome_i <= chr_index+l_cur_entry-1; cur_genome_i++)
            {
              int cur_nuc_num = per_nuc_val[(int)cur_fragment[cur_read_nuc_i]];

              //if(numerized_sequence_signal[cur_genome_i] > 0 &&
              //  nuc_2_num(cur_fragment[cur_read_nuc_i]) != (numerized_sequence_signal[cur_genome_i]))
              //{
              //  fprintf(stderr, "Found %c->%c @ %d\n", num_2_nuc(numerized_sequence_signal[cur_genome_i]), cur_fragment[cur_read_nuc_i], cur_genome_i);
              //}

              if(cur_nuc_num < 4)
              {
                // Update the count: The allelic counts must be checked for bounds.
                if(per_chrom_nuc_count_per_allele[i_chr][cur_nuc_num][cur_genome_i] < max_n_alleles_per_posn-5)
                {
                  if(phred_quality_str[cur_read_nuc_i] - phred_score_base > min_phred_qual)
                  {
if(__DUMP_MAPPED_READ_TOOLS_MSGS__)
{
                    fprintf(stderr, "Adding %d: %c, %c (%d)\n", 
                        cur_read_nuc_i, 
                        cur_fragment[cur_read_nuc_i], phred_quality_str[cur_read_nuc_i], 
                        (int)(phred_quality_str[cur_read_nuc_i]-phred_score_base));
}

                    // Phred quality holds, update the pileup position.
                    per_chrom_nuc_count_per_allele[i_chr][cur_nuc_num][cur_genome_i]++;
                  } // phred qual pass check.
                  else
                  {
if(__DUMP_MAPPED_READ_TOOLS_MSGS__)
{
                    fprintf(stderr, "Skipping %d: %c, %c (%d)\n", 
                      cur_read_nuc_i, 
                      cur_fragment[cur_read_nuc_i], phred_quality_str[cur_read_nuc_i], 
                      (int)(phred_quality_str[cur_read_nuc_i]-phred_score_base));
}
                  } // phred qual nopass check.
                } // max_n_alleles_per_posn check.
              } // char < 4 check.

              // Update the read's nucleotide index.
              cur_read_nuc_i++;
            } // i_cur loop.
          } // genomic match check.
          else if(entry_type_char == 'D')
          {
            // Deletion from the reference: Update the 4th entry: Add all of these entries as deletions.
            for(int cur_genome_i = chr_index; cur_genome_i <= chr_index+l_cur_entry-1; cur_genome_i++)
            {
              per_chrom_nuc_count_per_allele[i_chr][4][cur_genome_i]++;
            } // cur_genome_i loop.
          }
          else if(entry_type_char == 'I')
          {
            // Insertion to the reference: This is included to one position.
            per_chrom_nuc_count_per_allele[i_chr][4][chr_index]++;
          }
          // Update the base for the current entry.
          if(check_genome_index_update_per_CIGAR_entry(entry_type_char))
          {
            chr_index += l_cur_entry;
          }

          // Update the base for the current read if requested.
          if(check_read_nuc_index_update_per_CIGAR_entry(entry_type_char))
          {
            read_nuc_index += l_cur_entry;
          }
        } // mapping map string processing loop.

        //delete(cur_entry_length_str);
      } // mapping check for the current read.
    } // SAM read line parse check.
    else
    {
      fprintf(stderr, "Could not parse %s\n", cur_line);
      exit(0);
    }

    delete [] cur_line;
  } // file reading loop.

  fprintf(stderr, "Finished reading.\n");

  fclose(f_sam);

  // Dump the counts per position.
  for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
  {
    char cur_allele_fp[1000];
    sprintf(cur_allele_fp, "%s/%s_allele_counts.bin", op_dir, chr_ids->at(i_chr));

    // compress and dump the current file.
    compress_nucleotide_pileup_track(per_chrom_nuc_count_per_allele[i_chr], chr_lengths->at(i_chr), cur_allele_fp);
  } // i_chr loop.

  //char analysis_summary_str[1000];
  //sprintf(analysis_summary_str, "Processed %d reads, %d low quality reads, %d unmapped reads.\n", n_processed_reads, n_low_quality, n_unmapped_reads);
  //t_config_params::copy_analysis_summary_string(analysis_summary_str);

  //// Write the summary file.
  //f_summary = open_f(summary_fp, "w");
  //fprintf(f_summary, "Processed %d reads, %d low quality reads, %d unmapped reads.\n", n_processed_reads, n_low_quality_reads, n_unmapped_reads);
  //fclose(f_summary);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1bbc8, %rsp          # imm = 0x1BBC8
movq %rcx, 0x50(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movq 0x1bc00(%rsp), %r15
movq 0xccb0(%rip), %rbx      # 0xefe0
movq (%rbx), %rdi
leaq 0x7e9e(%rip), %rsi      # 0xa1d8
movl %r8d, 0x2c(%rsp)
movl %r8d, %edx
movl %r9d, 0x14(%rsp)
movl %r9d, %ecx
xorl %eax, %eax
callq 0x2230
andl $0x0, (%r15)
movq (%rbx), %rdi
leaq 0x7ec2(%rip), %rsi      # 0xa221
movq %r13, 0x8(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x2230
movq (%rbx), %rcx
leaq 0x7ece(%rip), %rdi      # 0xa246
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
movq 0x8(%r12), %rax
subq (%r12), %rax
shlq $0x1d, %rax
movq %rax, %rcx
sarq $0x1d, %rcx
testq %rax, %rax
pushq $-0x1
popq %rdi
cmovnsq %rcx, %rdi
callq 0x2040
movq %rax, 0x18(%rsp)
movq (%r12), %rcx
movq 0x8(%r12), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x24c7
leaq 0x7e97(%rip), %r13      # 0xa261
leaq 0x3520(%rsp), %rbp
leaq 0xa20(%rsp), %r14
xorl %r15d, %r15d
movq 0x38(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq $0x2, %rax
cmpq %r15, %rax
jbe 0x2b08
cmpq %r15, %rdx
jbe 0x2afc
movl (%rsi,%r15,4), %ebx
movq (%rcx,%r15,8), %rcx
movq %rbp, %rdi
movq %r13, %rsi
movq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x2060
movq %rbp, %rdi
callq 0x4a5e
testb %al, %al
jne 0x245b
movl %ebx, %edi
callq 0x2fbc
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movq (%r12), %rcx
movq 0x8(%r12), %rax
subq %rcx, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
cmpq %rax, %r15
jl 0x23dd
jmp 0x24c7
andl $0x0, 0xa20(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x31c6
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
jbe 0x2afc
movl 0xa20(%rsp), %ecx
movq 0xcb3f(%rip), %rdx      # 0xefe0
movq (%rdx), %rbx
cmpl (%rax,%r15,4), %ecx
jne 0x2b1c
movq %rbx, %rdi
leaq 0x7e0a(%rip), %rsi      # 0xa2c2
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2230
jmp 0x2438
movq 0xcb12(%rip), %rbx      # 0xefe0
movq (%rbx), %rcx
leaq 0x7e0b(%rip), %rdi      # 0xa2e3
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
movq (%rbx), %rdi
leaq 0x7dfd(%rip), %rsi      # 0xa2ea
movl $0x10000, %edx          # imm = 0x10000
xorl %eax, %eax
callq 0x2230
leaq 0x7e15(%rip), %rsi      # 0xa315
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2210
testl %eax, %eax
jne 0x251d
movq 0xcac0(%rip), %rax      # 0xefd8
movq (%rax), %r15
jmp 0x252f
leaq 0x7b12(%rip), %rsi      # 0xa036
movq %rbx, %rdi
callq 0x2190
movq %rax, %r15
callq 0x301d
movq %rax, 0x40(%rsp)
pushq $-0x7b
popq %rax
leaq 0x80(%rsp), %r14
movl %eax, 0x4(%rsp)
movl 0x2c(%rsp), %r13d
movq %r12, 0x68(%rsp)
movq %r15, 0x58(%rsp)
movq %r15, %rdi
callq 0x4954
movq %rax, %rbx
testq %rax, %rax
je 0x2960
cmpb $0x40, (%rbx)
je 0x2958
movq %rbx, %rdi
leaq 0x7d9d(%rip), %rsi      # 0xa31b
leaq 0x3130(%rsp), %rdx
leaq 0x160(%rsp), %rcx
leaq 0x1d0(%rsp), %r8
leaq 0xf0(%rsp), %r9
xorl %eax, %eax
leaq 0x3520(%rsp), %r10
pushq %r10
leaq 0x248(%rsp), %r10
pushq %r10
leaq 0xa30(%rsp), %r10
pushq %r10
pushq %r14
callq 0x2140
addq $0x20, %rsp
cmpl $0x8, %eax
jne 0x2b4f
movl 0x4(%rsp), %ecx
cmpl $-0x7b, %ecx
jne 0x261b
leaq 0x3520(%rsp), %rdi
callq 0x20a0
pushq $-0x7b
popq %rcx
testl %eax, %eax
jle 0x261b
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %edx, %edx
movsbl 0x3520(%rsp,%rdx), %ecx
cmpl $0x4b, %ecx
jge 0x296e
cmpb $0x3a, %cl
jle 0x29a7
incq %rdx
cmpq %rdx, %rax
jne 0x25f6
pushq $-0x7b
popq %rcx
movl %ecx, 0x4(%rsp)
movq %r14, %rdi
callq 0x2270
cmpl %r13d, %eax
jl 0x2958
movq %rbx, 0x48(%rsp)
leaq 0x1d0(%rsp), %rbx
movq %rbx, %rdi
callq 0x308c
leaq 0x160(%rsp), %rdi
callq 0x2270
movl %eax, 0x8(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5b9e
movq 0x8(%r12), %rcx
movq %r12, %rbp
subq (%r12), %rcx
shrq $0x3, %rcx
movl %eax, 0x30(%rsp)
movq %rcx, 0x70(%rsp)
cmpl %ecx, %eax
jne 0x2693
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x21f0
movq %rbp, %r12
jmp 0x294d
leaq 0xf0(%rsp), %rdi
callq 0x2270
movq %rax, 0x20(%rsp)
testb $0x4, 0x8(%rsp)
movq 0x48(%rsp), %rbx
movq %rbp, %r12
jne 0x294d
movq 0x1bc00(%rsp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movl %ecx, %eax
cltd
movl $0xf4240, %esi          # imm = 0xF4240
idivl %esi
testl %edx, %edx
je 0x29e0
cmpb $0x1, 0xcab2(%rip)      # 0xf191
je 0x29ff
movb $0x0, 0x630(%rsp)
leaq 0xa20(%rsp), %rdi
leaq 0x630(%rsp), %rsi
callq 0x3406
movb %al, 0x3(%rsp)
testb %al, %al
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edi
movq 0x40(%rsp), %r10
movl 0x4(%rsp), %r11d
je 0x2943
movslq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x34(%rsp)
xorl %r15d, %r15d
movslq %r15d, %rax
cmpb $0x0, 0xa20(%rsp,%rax)
je 0x2943
movb 0xa20(%rsp,%rax), %cl
leal -0x3a(%rcx), %edx
xorl %r14d, %r14d
cmpb $-0xa, %dl
jb 0x2782
movslq %r15d, %rax
xorl %r14d, %r14d
imull $0xa, %r14d, %edx
addb $-0x30, %cl
movzbl %cl, %r14d
addl %edx, %r14d
movb 0xa21(%rsp,%rax), %cl
incq %rax
leal -0x3a(%rcx), %edx
incl %r15d
cmpb $-0xb, %dl
ja 0x275f
cmpb $0x4d, 0xa20(%rsp,%rax)
movslq %r15d, %rax
movzbl 0xa20(%rsp,%rax), %eax
movq %rax, 0x78(%rsp)
jne 0x2894
testl %r14d, %r14d
jle 0x28e3
movq 0x20(%rsp), %rcx
leal (%r14,%rcx), %eax
movslq %ecx, %r12
movslq %eax, %rdx
movslq 0x34(%rsp), %r13
movsbq 0x240(%rsp,%r13), %rcx
movslq (%r10,%rcx,4), %rbx
cmpq $0x3, %rbx
jg 0x2814
movq 0x8(%rsp), %rax
movq (%rsi,%rax,8), %rbp
movq (%rbp,%rbx,8), %rax
cmpw $-0x6, (%rax,%r12,2)
ja 0x2814
movsbl 0x3520(%rsp,%r13), %r8d
movl %r8d, %r9d
subl %r11d, %r9d
movb 0xc996(%rip), %al       # 0xf191
cmpl %edi, %r9d
jle 0x2810
testb %al, %al
jne 0x2824
movq (%rbp,%rbx,8), %rax
incw (%rax,%r12,2)
jmp 0x2814
testb %al, %al
jne 0x285e
incq %r13
incq %r12
cmpq %rdx, %r12
jl 0x27bd
jmp 0x28e3
movq 0xc7b5(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x7bb4(%rip), %rsi      # 0xa3e9
movq %rdx, 0x60(%rsp)
movl %r13d, %edx
xorl %eax, %eax
callq 0x2230
movq 0x60(%rsp), %rdx
movl 0x4(%rsp), %r11d
movq 0x40(%rsp), %r10
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %rsi
jmp 0x2804
movq 0xc77b(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x7b92(%rip), %rsi      # 0xa401
movq %rdx, %rbx
movl %r13d, %edx
xorl %eax, %eax
callq 0x2230
movq %rbx, %rdx
movl 0x4(%rsp), %r11d
movq 0x40(%rsp), %r10
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %rsi
jmp 0x2814
cmpl $0x49, %eax
je 0x28cd
cmpl $0x44, %eax
jne 0x28e3
testl %r14d, %r14d
jle 0x28e3
movq 0x20(%rsp), %rcx
movslq %ecx, %rax
leal (%r14,%rcx), %edx
movq 0x8(%rsp), %rcx
movq (%rsi,%rcx,8), %rcx
movq 0x20(%rcx), %rcx
movslq %edx, %rdx
incw (%rcx,%rax,2)
incq %rax
cmpq %rdx, %rax
jl 0x28bf
jmp 0x28e3
movq 0x8(%rsp), %rax
movq (%rsi,%rax,8), %rax
movq 0x20(%rax), %rax
movslq 0x20(%rsp), %rcx
incw (%rax,%rcx,2)
incl %r15d
movq 0x78(%rsp), %rdx
leal -0x4d(%rdx), %eax
cmpb $0x2, %al
movl $0x0, %eax
cmovbl %r14d, %eax
cmpl $0x44, %edx
cmovel %r14d, %eax
movq 0x20(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x20(%rsp)
movl %edx, %eax
andb $-0x5, %al
cmpb $0x49, %al
movl $0x0, %eax
cmovel %r14d, %eax
cmpl $0x53, %edx
cmovel %r14d, %eax
addl %eax, 0x34(%rsp)
cmpb $0x0, 0x3(%rsp)
movq 0x68(%rsp), %r12
leaq 0x80(%rsp), %r14
movq 0x48(%rsp), %rbx
jne 0x2736
movl 0x2c(%rsp), %r13d
movq 0x58(%rsp), %r15
movq 0x70(%rsp), %rax
cmpl %eax, 0x30(%rsp)
je 0x2960
movq %rbx, %rdi
callq 0x21f0
testq %rbx, %rbx
jne 0x2557
jmp 0x2a2c
movq 0xc66b(%rip), %rax      # 0xefe0
movq (%rax), %rdi
movq 0x1bc00(%rsp), %rax
movl (%rax), %edx
leaq 0x79d7(%rip), %rsi      # 0xa360
leaq 0x240(%rsp), %r8
leaq 0x3520(%rsp), %r9
xorl %eax, %eax
callq 0x2230
pushq $0x3b
jmp 0x261a
movq 0xc632(%rip), %rax      # 0xefe0
movq (%rax), %rdi
movq 0x1bc00(%rsp), %rax
movl (%rax), %edx
leaq 0x79c8(%rip), %rsi      # 0xa38a
leaq 0x240(%rsp), %r8
leaq 0x3520(%rsp), %r9
xorl %eax, %eax
callq 0x2230
pushq $0x21
jmp 0x261a
movq 0xc5f9(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x79c3(%rip), %rsi      # 0xa3b4
movl %ecx, %edx
xorl %eax, %eax
callq 0x2230
jmp 0x26d8
movq 0xc5da(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x79c6(%rip), %rsi      # 0xa3d6
leaq 0x240(%rsp), %rdx
leaq 0x3520(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
jmp 0x26e5
movq 0xc5ad(%rip), %rax      # 0xefe0
movq (%rax), %rcx
leaq 0x79f2(%rip), %rdi      # 0xa42f
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x22e0
movq %r15, %rdi
callq 0x2150
movq (%r12), %rax
movq 0x8(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x2aea
leaq 0x77f2(%rip), %r15      # 0xa261
leaq 0x630(%rsp), %r13
xorl %ebx, %ebx
cmpq %rbx, %rdx
jbe 0x2b71
movq (%rax,%rbx,8), %rcx
movq %r13, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x2060
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x2b71
movq 0x18(%rsp), %rcx
movq (%rcx,%rbx,8), %rdi
movl (%rax,%rbx,4), %esi
movq %r13, %rdx
callq 0x34c3
incq %rbx
movq (%r12), %rax
movq 0x8(%r12), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jl 0x2a79
addq $0x1bbc8, %rsp          # imm = 0x1BBC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7e61(%rip), %rdi      # 0xa964
movq %r15, %rsi
jmp 0x2b15
leaq 0x7e55(%rip), %rdi      # 0xa964
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2250
movq %r12, %rdi
movq %r15, %rsi
callq 0x3fc6
movq (%rax), %r14
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x3f9e
movl (%rax), %ecx
leaq 0x7739(%rip), %rsi      # 0xa279
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2230
jmp 0x2b6a
movq 0xc48a(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x78bb(%rip), %rsi      # 0xa41b
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2230
xorl %edi, %edi
callq 0x21b0
leaq 0x7dec(%rip), %rdi      # 0xa964
movq %rbx, %rsi
jmp 0x2b15