// File: /workspace/github_cpp_makefile_star2_O2/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 $0x898, %rsp            # imm = 0x898
movl %edx, 0x4(%rsp)
movq %rdi, %rbx
movb $0x0, (%rdi)
andq $0x0, 0x828(%rdi)
movq %rsi, %r14
leaq 0x808(%rdi), %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x808(%rdi)
andw $0x0, 0x818(%rdi)
pushq $0x1
popq %rax
cmpq $0x101, %rax            # imm = 0x101
je 0x4ba8
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0x4b96
leaq 0x188e9(%rip), %rdx     # 0x1d498
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8410
movq (%r15), %rsi
leaq 0x288(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3430
movq 0x288(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2a8(%rsp,%rax)
je 0x4c08
movq 0x18401(%rip), %rdi     # 0x1cff0
leaq 0xe732(%rip), %rsi      # 0x13328
callq 0x3200
movq %rax, %rdi
callq 0x3100
jmp 0x4e7e
leaq 0x288(%rsp), %rdi
leaq 0x490(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x3290
movl $0x1010, %edi           # imm = 0x1010
callq 0x3220
movq %rax, %r15
leaq 0x490(%rsp), %rsi
movq %rax, %rdi
callq 0xb32c
movq %r15, 0x808(%rbx)
movl 0x800(%r15), %eax
movl %eax, 0x4(%rbx)
leaq 0x18(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x18867(%rip), %rdx     # 0x1d4d8
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x8410
movq %r14, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x105bc
leaq 0x80(%rsp), %rdi
callq 0x3478
pushq $0x1
popq %r14
pushq $0x48
popq %r15
leaq 0x288(%rsp), %r12
cmpq $0x101, %r14            # imm = 0x101
je 0x4cf1
movq (%rbp), %rax
movq -0x8(%rax,%r14,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
cmpl %ecx, %eax
ja 0x4cec
movq %r15, %rdi
callq 0x3220
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0xfce0
movq %r13, (%rbx,%r14,8)
incq %r14
jmp 0x4cb5
pushq $0x48
popq %rdi
callq 0x3220
movq 0x8(%rsp), %r14
movq %rax, %r15
leaq 0x288(%rsp), %rsi
movq %rax, %rdi
callq 0xf8b4
movq %r15, 0x828(%rbx)
movl 0x4(%r15), %eax
movl %eax, 0x820(%rbx)
leaq 0x81c(%rbx), %r15
leaq 0x288(%rsp), %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x3290
leaq 0x288(%rsp), %rdi
callq 0x3090
leaq 0x18858(%rip), %rsi     # 0x1d5a8
leaq 0x10(%rsp), %rdi
callq 0x10362
testl %eax, %eax
jne 0x4d77
leaq 0x1886b(%rip), %rsi     # 0x1d5d0
leaq 0x10(%rsp), %rdi
callq 0x10362
testl %eax, %eax
je 0x4e60
leaq 0x1873a(%rip), %rdx     # 0x1d4b8
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x8410
movq 0x40(%rsp), %rsi
leaq 0x80(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3430
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
movl 0xa0(%rsp,%rax), %ebp
testb $0x5, %bpl
je 0x4dd6
movq 0x18230(%rip), %rdi     # 0x1cff0
leaq 0xe586(%rip), %rsi      # 0x1334d
callq 0x3200
movq %rax, %rdi
callq 0x3100
jmp 0x4e43
leaq 0x1881b(%rip), %rsi     # 0x1d5f8
leaq 0x10(%rsp), %rdi
callq 0x10362
movl %eax, %r12d
pushq $0x30
popq %rdi
callq 0x3220
movq %rax, %r14
xorl %ecx, %ecx
testl %r12d, %r12d
setne %cl
movl (%r15), %edx
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x9ae4
movq %r14, 0x810(%rbx)
leaq 0x80(%rsp), %rdi
callq 0x3090
movq 0x810(%rbx), %rax
cmpq $0x0, 0x18(%rax)
setne 0x818(%rbx)
cmpq $0x0, 0x28(%rax)
setne 0x819(%rbx)
leaq 0x80(%rsp), %rdi
callq 0x30a0
leaq 0x40(%rsp), %rdi
callq 0x3478
testb $0x5, %bpl
jne 0x4e74
cmpb $0x0, 0x4(%rsp)
je 0x4e71
leaq 0x10(%rsp), %rdi
callq 0x1066a
movb $0x1, (%rbx)
leaq 0x10(%rsp), %rdi
callq 0x4a5a
leaq 0x288(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rdi
callq 0x3478
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x30
popq %rsi
movq %r14, %rdi
callq 0x3230
jmp 0x4eef
movq %rax, %rbx
jmp 0x4efc
jmp 0x4f16
jmp 0x4eec
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r15, %rdi
jmp 0x4f24
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x4f01
jmp 0x4f16
movq %rax, %rbx
movl $0x1010, %esi           # imm = 0x1010
movq %r15, %rdi
callq 0x3230
jmp 0x4f33
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x30a0
leaq 0x40(%rsp), %rdi
callq 0x3478
jmp 0x4f29
jmp 0x4f0f
movq %rax, %rbx
jmp 0x4f40
movq %rax, %rbx
jmp 0x4f33
jmp 0x4f16
movq %rax, %rbx
jmp 0x4f29
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r13, %rdi
callq 0x3230
leaq 0x10(%rsp), %rdi
callq 0x4a5a
leaq 0x288(%rsp), %rdi
callq 0x30a0
leaq 0x60(%rsp), %rdi
callq 0x3478
movq %rbx, %rdi
callq 0x3410