// File: adamnovak[P]rlcsa/suffixarray.cpp
// Function: CSA::SuffixArray::SuffixArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
SuffixArray::SuffixArray(const std::string& base_name, bool print) :
  ok(false),
  data(0), sa(0), original_sa(0), ranks(0), data_size(0),
  sequences(0)
{
  std::ifstream data_file(base_name.c_str(), std::ios_base::binary);
  if(!data_file)
  {
    std::cerr << "Error: Cannot open data file " << base_name << "!" << std::endl;
    return;
  }
  this->data_size = fileSize(data_file);
  this->data = new uchar[this->data_size];
  data_file.read((char*)(this->data), data_size);
  data_file.close();

  std::string sa_name = base_name + SA_EXTENSION;
  std::ifstream sa_file(sa_name.c_str(), std::ios_base::binary);
  if(!sa_file)
  {
    std::cerr << "Error: Cannot open suffix array file " << sa_name << "!" << std::endl;
    return;
  }
  sa_file.read((char*)&(this->sequences), sizeof(uint));
  this->sa = new uint[this->data_size];
  sa_file.read((char*)(this->sa), this->data_size * sizeof(uint));
  sa_file.close();

  this->original_sa = this->sa; this->sa += this->sequences;
  this->ok = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x468(%rbp)
movb $0x0, (%rax)
movq $0x0, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x20(%rax)
movl $0x0, 0x28(%rax)
movl $0x0, 0x2c(%rax)
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
movl $0x4, %edx
callq 0x3560
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x459(%rbp)
jmp 0x1af93
movb -0x459(%rbp), %al
testb $0x1, %al
jne 0x1afa2
jmp 0x1b02e
movq 0x1d047(%rip), %rdi     # 0x37ff0
leaq 0xe874(%rip), %rsi      # 0x29824
callq 0x32a0
movq %rax, -0x470(%rbp)
jmp 0x1afbe
movq -0x470(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3280
movq %rax, -0x478(%rbp)
jmp 0x1afd7
movq -0x478(%rbp), %rdi
leaq 0xe8df(%rip), %rsi      # 0x298c4
callq 0x32a0
movq %rax, -0x480(%rbp)
jmp 0x1aff3
movq -0x480(%rbp), %rdi
movq 0x1cfaf(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x1b008
movl $0x1, -0x230(%rbp)
jmp 0x1b279
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x1b29a
leaq -0x220(%rbp), %rdi
callq 0x23550
movq %rax, -0x488(%rbp)
jmp 0x1b043
movq -0x468(%rbp), %rax
movq -0x488(%rbp), %rcx
movl %ecx, 0x28(%rax)
movl 0x28(%rax), %eax
movl %eax, %edi
callq 0x3030
movq %rax, -0x490(%rbp)
jmp 0x1b067
movq -0x468(%rbp), %rax
movq -0x490(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq 0x8(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x220(%rbp), %rdi
callq 0x33c0
jmp 0x1b090
leaq -0x220(%rbp), %rdi
callq 0x30c0
jmp 0x1b09e
movq -0x10(%rbp), %rsi
leaq 0x1d807(%rip), %rdx     # 0x388b0
leaq -0x250(%rbp), %rdi
callq 0xd3c0
jmp 0x1b0b7
leaq -0x250(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x458(%rbp), %rdi
movl $0x4, %edx
callq 0x3560
jmp 0x1b0d9
movq -0x458(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x458(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x491(%rbp)
jmp 0x1b0f9
movb -0x491(%rbp), %al
testb $0x1, %al
jne 0x1b108
jmp 0x1b1ba
movq 0x1cee1(%rip), %rdi     # 0x37ff0
leaq 0xe72c(%rip), %rsi      # 0x29842
callq 0x32a0
movq %rax, -0x4a0(%rbp)
jmp 0x1b124
movq -0x4a0(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x3280
movq %rax, -0x4a8(%rbp)
jmp 0x1b140
movq -0x4a8(%rbp), %rdi
leaq 0xe776(%rip), %rsi      # 0x298c4
callq 0x32a0
movq %rax, -0x4b0(%rbp)
jmp 0x1b15c
movq -0x4b0(%rbp), %rdi
movq 0x1ce46(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x1b171
movl $0x1, -0x230(%rbp)
jmp 0x1b261
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x1b28e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x458(%rbp), %rdi
callq 0x30e0
jmp 0x1b28e
movq -0x468(%rbp), %rsi
addq $0x2c, %rsi
leaq -0x458(%rbp), %rdi
movl $0x4, %edx
callq 0x33c0
jmp 0x1b1d8
movq -0x468(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3030
movq %rax, -0x4b8(%rbp)
jmp 0x1b1f6
movq -0x468(%rbp), %rax
movq -0x4b8(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
shlq $0x2, %rdx
leaq -0x458(%rbp), %rdi
callq 0x33c0
jmp 0x1b223
leaq -0x458(%rbp), %rdi
callq 0x30c0
jmp 0x1b231
movq -0x468(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x18(%rax)
movl 0x2c(%rax), %edx
movq 0x10(%rax), %rcx
movl %edx, %edx
shlq $0x2, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movb $0x1, (%rax)
movl $0x0, -0x230(%rbp)
leaq -0x458(%rbp), %rdi
callq 0x30e0
leaq -0x250(%rbp), %rdi
callq 0x35d8
leaq -0x220(%rbp), %rdi
callq 0x30e0
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
leaq -0x250(%rbp), %rdi
callq 0x35d8
leaq -0x220(%rbp), %rdi
callq 0x30e0
movq -0x228(%rbp), %rdi
callq 0x3530
nopw %cs:(%rax,%rax)