// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::RLCSA(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
RLCSA::RLCSA(const std::string& base_name, bool print) :
  ok(false),
  alphabet(0),
  sa_samples(0), support_locate(false), support_display(false),
  end_points(0)
{
  for(usint c = 0; c < CHARS; c++) { this->array[c] = 0; }

  std::string array_name = base_name + ARRAY_EXTENSION;
  std::ifstream array_file(array_name.c_str(), std::ios_base::binary);
  if(!array_file)
  {
    std::cerr << "RLCSA: Error opening Psi array file!" << std::endl;
    return;
  }

  usint distribution[CHARS];
  array_file.read((char*)distribution, CHARS * sizeof(usint));
  this->alphabet = new Alphabet(distribution); this->data_size = this->alphabet->getDataSize();

  Parameters parameters;
  parameters.read(base_name + PARAMETERS_EXTENSION);
  for(usint c = 0; c < CHARS; c++)
  {
    if(this->alphabet->hasChar(c)) { this->array[c] = new PsiVector(array_file); }
  }

  this->end_points = new DeltaVector(array_file);
  this->number_of_sequences = this->end_points->getNumberOfItems();

  array_file.read((char*)&(this->sample_rate), sizeof(this->sample_rate));
  array_file.close();

  if(parameters.get(SUPPORT_LOCATE) || parameters.get(SUPPORT_DISPLAY))
  {
    std::string sa_sample_name = base_name + SA_SAMPLES_EXTENSION;
    std::ifstream sa_sample_file(sa_sample_name.c_str(), std::ios_base::binary);
    if(!sa_sample_file)
    {
      std::cerr << "RLCSA: Error opening suffix array sample file!" << std::endl;
      return;
    }
    bool weighted = parameters.get(WEIGHTED_SAMPLES);
    this->sa_samples = new SASamples(sa_sample_file, this->sample_rate, weighted);
    sa_sample_file.close();

    this->support_locate = this->sa_samples->supportsLocate();
    this->support_display = this->sa_samples->supportsDisplay();
  }

  if(print) { parameters.print(); }

  this->ok = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x888, %rsp            # imm = 0x888
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movb $0x0, (%rdi)
movq $0x0, 0x828(%rdi)
addq $0x8, %rdi
movl $0x812, %edx            # imm = 0x812
xorl %esi, %esi
callq 0x3150
leaq 0x19cde(%rip), %rdx     # 0x1f4b8
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x9f63
movq (%r15), %rsi
leaq 0x278(%rsp), %rdi
movl $0x4, %edx
callq 0x3480
movq 0x278(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x298(%rsp,%rax)
je 0x5860
movq 0x197d4(%rip), %rbx     # 0x1eff0
leaq 0x11b00(%rip), %rsi     # 0x17323
movl $0x24, %edx
movq %rbx, %rdi
callq 0x32b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x197a2(%rip), %rdi     # 0x1eff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x5b0c
leaq 0x278(%rsp), %rdi
leaq 0x480(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x32e0
movl $0x1010, %edi           # imm = 0x1010
callq 0x3260
movq %rax, %r15
leaq 0x480(%rsp), %rsi
movq %rax, %rdi
callq 0xcca8
movq %r15, 0x808(%rbx)
movl 0x800(%r15), %eax
movl %eax, 0x4(%rbx)
leaq 0x28(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x19c2c(%rip), %rdx     # 0x1f4f8
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x9f63
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x14622
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5909
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3270
xorl %r13d, %r13d
leaq 0x278(%rsp), %r15
movq 0x808(%rbx), %rax
movq (%rax,%r13,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
cmpl %ecx, %eax
ja 0x5947
movl $0x48, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x13370
movq %r12, 0x8(%rbx,%r13,8)
incq %r13
cmpq $0x100, %r13            # imm = 0x100
jne 0x5914
movl $0x48, %edi
callq 0x3260
movq %rax, %r15
leaq 0x278(%rsp), %rsi
movq %rax, %rdi
callq 0x12720
movq %r15, 0x828(%rbx)
movl 0x4(%r15), %eax
movl %eax, 0x820(%rbx)
leaq 0x81c(%rbx), %r15
leaq 0x278(%rsp), %rdi
movl $0x4, %edx
movq %r15, %rsi
callq 0x32e0
leaq 0x278(%rsp), %rdi
callq 0x3090
leaq 0x19c17(%rip), %rsi     # 0x1f5c8
leaq 0x20(%rsp), %rdi
callq 0x142de
testl %eax, %eax
jne 0x59d8
leaq 0x19c2a(%rip), %rsi     # 0x1f5f0
leaq 0x20(%rsp), %rdi
callq 0x142de
testl %eax, %eax
je 0x5af0
leaq 0x19af9(%rip), %rdx     # 0x1f4d8
movq %rsp, %rdi
movq %r14, %rsi
callq 0x9f63
movq (%rsp), %rsi
leaq 0x70(%rsp), %rdi
movl $0x4, %edx
callq 0x3480
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x90(%rsp,%rax), %r13d
testb $0x5, %r13b
je 0x5a5c
movq 0x195d5(%rip), %r14     # 0x1eff0
leaq 0x11926(%rip), %rsi     # 0x17348
movl $0x2e, %edx
movq %r14, %rdi
callq 0x32b0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x195a3(%rip), %rdi     # 0x1eff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x5ac5
leaq 0x19bb5(%rip), %rsi     # 0x1f618
leaq 0x20(%rsp), %rdi
callq 0x142de
movl %eax, %r12d
movl $0x30, %edi
callq 0x3260
movq %rax, %r14
xorl %ecx, %ecx
testl %r12d, %r12d
setne %cl
movl (%r15), %edx
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0xaf00
movq %r14, 0x810(%rbx)
leaq 0x70(%rsp), %rdi
callq 0x3090
movq 0x810(%rbx), %rax
cmpq $0x0, 0x18(%rax)
setne 0x818(%rbx)
cmpq $0x0, 0x28(%rax)
setne 0x819(%rbx)
leaq 0x70(%rsp), %rdi
callq 0x30a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5aea
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
testb $0x5, %r13b
jne 0x5b02
testb %bpl, %bpl
je 0x5aff
leaq 0x20(%rsp), %rdi
callq 0x14706
movb $0x1, (%rbx)
leaq 0x20(%rsp), %rdi
callq 0x5694
leaq 0x278(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5b34
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3270
addq $0x888, %rsp            # imm = 0x888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x30, %esi
movq %r14, %rdi
callq 0x3270
jmp 0x5ba5
movq %rax, %rbx
jmp 0x5baf
jmp 0x5bd3
jmp 0x5ba2
movq %rax, %rbx
movl $0x48, %esi
movq %r15, %rdi
jmp 0x5be3
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5be8
movq 0x80(%rsp), %rsi
jmp 0x5bc2
jmp 0x5bd3
movq %rax, %rbx
movl $0x1010, %esi           # imm = 0x1010
movq %r15, %rdi
callq 0x3270
jmp 0x5bf2
jmp 0x5bce
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x30a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5be8
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x5be3
movq %rax, %rbx
jmp 0x5bff
jmp 0x5bd3
movq %rax, %rbx
jmp 0x5bf2
movq %rax, %rbx
jmp 0x5be8
movq %rax, %rbx
movl $0x48, %esi
movq %r12, %rdi
callq 0x3270
leaq 0x20(%rsp), %rdi
callq 0x5694
leaq 0x278(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5c1a
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460