// File: 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
movq %rsp, %rbp
subq $0x950, %rsp            # imm = 0x950
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x8e0(%rbp)
movb $0x0, (%rax)
movq $0x0, 0x808(%rax)
movq $0x0, 0x810(%rax)
movb $0x0, 0x818(%rax)
movb $0x0, 0x819(%rax)
movq $0x0, 0x828(%rax)
movl $0x0, -0x18(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jae 0x6c65
movq -0x8e0(%rbp), %rax
movl -0x18(%rbp), %ecx
movq $0x0, 0x8(%rax,%rcx,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x6c3e
movq -0x10(%rbp), %rsi
leaq 0x318d8(%rip), %rdx     # 0x38548
leaq -0x38(%rbp), %rdi
movq %rdi, -0x8e8(%rbp)
callq 0xd3c0
movq -0x8e8(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
movl $0x4, %edx
callq 0x3560
jmp 0x6ca2
movq -0x240(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x240(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x8e9(%rbp)
jmp 0x6cc2
movb -0x8e9(%rbp), %al
testb $0x1, %al
jne 0x6cce
jmp 0x6d3c
movq 0x3131b(%rip), %rdi     # 0x37ff0
leaq 0x226d4(%rip), %rsi     # 0x293b0
callq 0x32a0
movq %rax, -0x8f8(%rbp)
jmp 0x6cea
movq -0x8f8(%rbp), %rdi
movq 0x312b8(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x6cff
movl $0x1, -0x250(%rbp)
jmp 0x7295
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x72cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x72bf
leaq -0x240(%rbp), %rdi
leaq -0x650(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x33c0
jmp 0x6d56
movl $0x1010, %edi           # imm = 0x1010
callq 0x32c0
movq %rax, -0x900(%rbp)
jmp 0x6d69
movq -0x900(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x16dc0
jmp 0x6d7e
movq -0x8e0(%rbp), %rax
movq -0x900(%rbp), %rcx
movq %rcx, 0x808(%rax)
movq 0x808(%rax), %rdi
callq 0xd440
movl %eax, -0x904(%rbp)
jmp 0x6da7
movq -0x8e0(%rbp), %rax
movl -0x904(%rbp), %ecx
movl %ecx, 0x4(%rax)
leaq -0x680(%rbp), %rdi
callq 0x6430
jmp 0x6dc5
movq -0x10(%rbp), %rsi
leaq 0x317b8(%rip), %rdx     # 0x38588
leaq -0x6a0(%rbp), %rdi
callq 0xd3c0
jmp 0x6dde
leaq -0x680(%rbp), %rdi
leaq -0x6a0(%rbp), %rsi
callq 0x21b70
jmp 0x6df3
leaq -0x6a0(%rbp), %rdi
callq 0x35d8
movl $0x0, -0x6a4(%rbp)
cmpl $0x100, -0x6a4(%rbp)    # imm = 0x100
jae 0x6f2f
movq -0x8e0(%rbp), %rax
movq 0x808(%rax), %rdi
movl -0x6a4(%rbp), %esi
callq 0xd460
movb %al, -0x905(%rbp)
jmp 0x6e3a
movb -0x905(%rbp), %al
testb $0x1, %al
jne 0x6e49
jmp 0x6f19
movl $0x48, %edi
callq 0x32c0
movq %rax, -0x910(%rbp)
jmp 0x6e5c
movq -0x910(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x209b0
jmp 0x6e71
movq -0x8e0(%rbp), %rax
movq -0x910(%rbp), %rdx
movl -0x6a4(%rbp), %ecx
movq %rdx, 0x8(%rax,%rcx,8)
jmp 0x6f19
movq -0x900(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
movl $0x1010, %esi           # imm = 0x1010
callq 0x32d0
jmp 0x72bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x72b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x6a0(%rbp), %rdi
callq 0x35d8
jmp 0x72b3
movq -0x910(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
movl $0x48, %esi
callq 0x32d0
jmp 0x72b3
jmp 0x6f1b
movl -0x6a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6a4(%rbp)
jmp 0x6e09
movl $0x48, %edi
callq 0x32c0
movq %rax, -0x918(%rbp)
jmp 0x6f42
movq -0x918(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x1ffc0
jmp 0x6f57
movq -0x8e0(%rbp), %rax
movq -0x918(%rbp), %rcx
movq %rcx, 0x828(%rax)
movq 0x828(%rax), %rdi
callq 0xd4a0
movl %eax, -0x91c(%rbp)
jmp 0x6f80
movq -0x8e0(%rbp), %rsi
movl -0x91c(%rbp), %eax
movl %eax, 0x820(%rsi)
addq $0x81c, %rsi            # imm = 0x81C
leaq -0x240(%rbp), %rdi
movl $0x4, %edx
callq 0x33c0
jmp 0x6fad
leaq -0x240(%rbp), %rdi
callq 0x30c0
jmp 0x6fbb
leaq 0x31696(%rip), %rsi     # 0x38658
leaq -0x680(%rbp), %rdi
callq 0x217c0
movl %eax, -0x920(%rbp)
jmp 0x6fd6
movl -0x920(%rbp), %eax
cmpl $0x0, %eax
jne 0x700b
leaq 0x31698(%rip), %rsi     # 0x38680
leaq -0x680(%rbp), %rdi
callq 0x217c0
movl %eax, -0x924(%rbp)
jmp 0x6ffc
movl -0x924(%rbp), %eax
cmpl $0x0, %eax
je 0x725f
movq -0x10(%rbp), %rsi
leaq 0x31552(%rip), %rdx     # 0x38568
leaq -0x6c8(%rbp), %rdi
callq 0xd3c0
jmp 0x7024
leaq -0x6c8(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x8d0(%rbp), %rdi
movl $0x4, %edx
callq 0x3560
jmp 0x7046
movq -0x8d0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x8d0(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x925(%rbp)
jmp 0x7066
movb -0x925(%rbp), %al
testb $0x1, %al
jne 0x7075
jmp 0x710b
movq 0x30f74(%rip), %rdi     # 0x37ff0
leaq 0x22352(%rip), %rsi     # 0x293d5
callq 0x32a0
movq %rax, -0x930(%rbp)
jmp 0x7091
movq -0x930(%rbp), %rdi
movq 0x30f11(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x70a6
movl $0x1, -0x250(%rbp)
jmp 0x71fc
movq -0x918(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
movl $0x48, %esi
callq 0x32d0
jmp 0x72b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x7251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x7245
leaq 0x31596(%rip), %rsi     # 0x386a8
leaq -0x680(%rbp), %rdi
callq 0x217c0
movl %eax, -0x934(%rbp)
jmp 0x7126
movl -0x934(%rbp), %eax
testl %eax, %eax
setne -0x8d1(%rbp)
movl $0x30, %edi
callq 0x32c0
movq %rax, -0x940(%rbp)
jmp 0x7148
movq -0x940(%rbp), %rdi
movq -0x8e0(%rbp), %rax
movl 0x81c(%rax), %edx
movzbl -0x8d1(%rbp), %ecx
andl $0x1, %ecx
leaq -0x8d0(%rbp), %rsi
callq 0x12ee0
jmp 0x7174
movq -0x8e0(%rbp), %rax
movq -0x940(%rbp), %rcx
movq %rcx, 0x810(%rax)
leaq -0x8d0(%rbp), %rdi
callq 0x30c0
jmp 0x7197
movq -0x8e0(%rbp), %rax
movq 0x810(%rax), %rdi
callq 0xd4c0
movb %al, -0x941(%rbp)
jmp 0x71b2
movq -0x8e0(%rbp), %rax
movb -0x941(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x818(%rax)
movq 0x810(%rax), %rdi
callq 0xd4e0
movb %al, -0x942(%rbp)
jmp 0x71dc
movq -0x8e0(%rbp), %rax
movb -0x942(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x819(%rax)
movl $0x0, -0x250(%rbp)
leaq -0x8d0(%rbp), %rdi
callq 0x30e0
leaq -0x6c8(%rbp), %rdi
callq 0x35d8
movl -0x250(%rbp), %eax
testl %eax, %eax
jne 0x7289
jmp 0x7220
jmp 0x725f
movq -0x940(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
movl $0x30, %esi
callq 0x32d0
leaq -0x8d0(%rbp), %rdi
callq 0x30e0
leaq -0x6c8(%rbp), %rdi
callq 0x35d8
jmp 0x72b3
testb $0x1, -0x11(%rbp)
je 0x7275
leaq -0x680(%rbp), %rdi
callq 0x21cc0
jmp 0x7273
jmp 0x7275
movq -0x8e0(%rbp), %rax
movb $0x1, (%rax)
movl $0x0, -0x250(%rbp)
leaq -0x680(%rbp), %rdi
callq 0x6470
leaq -0x240(%rbp), %rdi
callq 0x30e0
leaq -0x38(%rbp), %rdi
callq 0x35d8
addq $0x950, %rsp            # imm = 0x950
popq %rbp
retq
leaq -0x680(%rbp), %rdi
callq 0x6470
leaq -0x240(%rbp), %rdi
callq 0x30e0
leaq -0x38(%rbp), %rdi
callq 0x35d8
movq -0x248(%rbp), %rdi
callq 0x3530