// File: /workspace/github_cpp_makefile_star2_O3/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 0x1ada2(%rip), %rdx     # 0x204b8
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xa0a5
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 0x579c
movq 0x1a898(%rip), %rbx     # 0x1fff0
leaq 0x12c11(%rip), %rsi     # 0x18370
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 0x1a866(%rip), %rdi     # 0x1fff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x5a48
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 0xcdd0
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 0x1acf0(%rip), %rdx     # 0x204f8
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0xa0a5
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x14bb2
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5845
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 0x5883
movl $0x48, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x13738
movq %r12, 0x8(%rbx,%r13,8)
incq %r13
cmpq $0x100, %r13            # imm = 0x100
jne 0x5850
movl $0x48, %edi
callq 0x3260
movq %rax, %r15
leaq 0x278(%rsp), %rsi
movq %rax, %rdi
callq 0x12a9c
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 0x1acdb(%rip), %rsi     # 0x205c8
leaq 0x20(%rsp), %rdi
callq 0x14882
testl %eax, %eax
jne 0x5914
leaq 0x1acee(%rip), %rsi     # 0x205f0
leaq 0x20(%rsp), %rdi
callq 0x14882
testl %eax, %eax
je 0x5a2c
leaq 0x1abbd(%rip), %rdx     # 0x204d8
movq %rsp, %rdi
movq %r14, %rsi
callq 0xa0a5
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 0x5998
movq 0x1a699(%rip), %r14     # 0x1fff0
leaq 0x12a37(%rip), %rsi     # 0x18395
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 0x1a667(%rip), %rdi     # 0x1fff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x5a01
leaq 0x1ac79(%rip), %rsi     # 0x20618
leaq 0x20(%rsp), %rdi
callq 0x14882
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 0xafd8
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 0x5a26
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
testb $0x5, %r13b
jne 0x5a3e
testb %bpl, %bpl
je 0x5a3b
leaq 0x20(%rsp), %rdi
callq 0x14c96
movb $0x1, (%rbx)
leaq 0x20(%rsp), %rdi
callq 0x55c8
leaq 0x278(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5a70
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 0x5ae1
movq %rax, %rbx
jmp 0x5aeb
jmp 0x5b0f
jmp 0x5ade
movq %rax, %rbx
movl $0x48, %esi
movq %r15, %rdi
jmp 0x5b1f
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5b24
movq 0x80(%rsp), %rsi
jmp 0x5afe
jmp 0x5b0f
movq %rax, %rbx
movl $0x1010, %esi           # imm = 0x1010
movq %r15, %rdi
callq 0x3270
jmp 0x5b2e
jmp 0x5b0a
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x30a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5b24
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x5b1f
movq %rax, %rbx
jmp 0x5b3b
jmp 0x5b0f
movq %rax, %rbx
jmp 0x5b2e
movq %rax, %rbx
jmp 0x5b24
movq %rax, %rbx
movl $0x48, %esi
movq %r12, %rdi
callq 0x3270
leaq 0x20(%rsp), %rdi
callq 0x55c8
leaq 0x278(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5b56
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460