// File: adamnovak[P]rlcsa/docarray.cpp
// Function: CSA::DocArray::DocArray(CSA::RLCSA const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
DocArray::DocArray(const RLCSA& _rlcsa, const std::string& base_name, bool load_grammar) :
  rlcsa(_rlcsa),
  leaf_ranges(0), first_children(0), parents(0), next_leaves(0),
  rule_borders(0), rules(0),
  block_borders(0), blocks(0),
  ok(false), has_grammar(false), uses_rle(false)
{
  std::string input_name = base_name + DOCUMENT_EXTENSION;
  std::ifstream input(input_name.c_str(), std::ios_base::binary);
  if(!input)
  {
    std::cerr << "DocArray: Error opening input file " << input_name << "!" << std::endl;
    return;
  }

  usint flags = 0;
  input.read((char*)(&flags), sizeof(flags));
  if(flags & RLE_FLAG) { this->uses_rle = true; }

  this->leaf_ranges = new DeltaVector(input);
  this->first_children = new SuccinctVector(input);

  this->parents = new ReadBuffer(input, this->getNumberOfInternalNodes(),
    length(this->getNumberOfInternalNodes() - 1));
  this->next_leaves = new ReadBuffer(input, this->getNumberOfInternalNodes(),
    length(this->getNumberOfLeaves()));
  this->ok = true;

  if(load_grammar)
  {
    this->rule_borders = new SuccinctVector(input);
    this->rules = new ReadBuffer(input, this->rule_borders->getSize(),
      length(this->getNumberOfDocuments()));
    this->block_borders = new SuccinctVector(input);
    this->blocks = new ReadBuffer(input, this->block_borders->getSize(),
      length(this->maxInteger()));
    this->has_grammar = true;
  }

  input.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq $0x0, 0x30(%rax)
movq $0x0, 0x38(%rax)
movq $0x0, 0x40(%rax)
movb $0x0, 0x48(%rax)
movb $0x0, 0x49(%rax)
movb $0x0, 0x4a(%rax)
movq -0x18(%rbp), %rsi
leaq 0x263f9(%rip), %rdx     # 0x46980
leaq -0x40(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0xfc50
movq -0x268(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x248(%rbp), %rdi
movl $0x4, %edx
callq 0x35a0
jmp 0x205b9
movq -0x248(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x248(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x271(%rbp)
jmp 0x205d9
movb -0x271(%rbp), %al
testb $0x1, %al
jne 0x205e8
jmp 0x2068b
movq 0x25a01(%rip), %rdi     # 0x45ff0
leaq 0x14383(%rip), %rsi     # 0x34979
callq 0x32c0
movq %rax, -0x280(%rbp)
jmp 0x20604
movq -0x280(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3290
movq %rax, -0x288(%rbp)
jmp 0x2061d
movq -0x288(%rbp), %rdi
leaq 0x14265(%rip), %rsi     # 0x34890
callq 0x32c0
movq %rax, -0x290(%rbp)
jmp 0x20639
movq -0x290(%rbp), %rdi
movq 0x25969(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x2064e
movl $0x1, -0x258(%rbp)
jmp 0x20b27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x20b51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x20b45
movl $0x0, -0x25c(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
movl $0x4, %edx
callq 0x33e0
jmp 0x206af
movl -0x25c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x206c8
movq -0x270(%rbp), %rax
movb $0x1, 0x4a(%rax)
movl $0x48, %edi
callq 0x32e0
movq %rax, -0x298(%rbp)
jmp 0x206db
movq -0x298(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x2a9c0
jmp 0x206f0
movq -0x270(%rbp), %rax
movq -0x298(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x48, %edi
callq 0x32e0
movq %rax, -0x2a0(%rbp)
jmp 0x20715
movq -0x2a0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x2c100
jmp 0x2072a
movq -0x270(%rbp), %rax
movq -0x2a0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x28, %edi
callq 0x32e0
movq %rax, -0x2a8(%rbp)
jmp 0x2074f
movq -0x270(%rbp), %rdi
callq 0x7a10
movl %eax, -0x2ac(%rbp)
jmp 0x20763
movq -0x270(%rbp), %rdi
callq 0x7a10
movl %eax, -0x2b0(%rbp)
jmp 0x20777
movl -0x2b0(%rbp), %edi
decl %edi
callq 0x178e0
movl %eax, -0x2b4(%rbp)
jmp 0x2078c
movl -0x2b4(%rbp), %ecx
movl -0x2ac(%rbp), %edx
movq -0x2a8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x289a0
jmp 0x207ad
movq -0x270(%rbp), %rax
movq -0x2a8(%rbp), %rcx
movq %rcx, 0x18(%rax)
movl $0x28, %edi
callq 0x32e0
movq %rax, -0x2c0(%rbp)
jmp 0x207d2
movq -0x270(%rbp), %rdi
callq 0x7a10
movl %eax, -0x2c4(%rbp)
jmp 0x207e6
movq -0x270(%rbp), %rdi
callq 0x79f0
movl %eax, -0x2c8(%rbp)
jmp 0x207fa
movl -0x2c8(%rbp), %edi
callq 0x178e0
movl %eax, -0x2cc(%rbp)
jmp 0x2080d
movl -0x2cc(%rbp), %ecx
movl -0x2c4(%rbp), %edx
movq -0x2c0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x289a0
jmp 0x2082e
movq -0x270(%rbp), %rax
movq -0x2c0(%rbp), %rcx
movq %rcx, 0x20(%rax)
movb $0x1, 0x48(%rax)
testb $0x1, -0x19(%rbp)
je 0x20b0f
movl $0x48, %edi
callq 0x32e0
movq %rax, -0x2d8(%rbp)
jmp 0x20861
movq -0x2d8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x2c100
jmp 0x20876
movq -0x270(%rbp), %rax
movq -0x2d8(%rbp), %rcx
movq %rcx, 0x28(%rax)
movl $0x28, %edi
callq 0x32e0
movq %rax, -0x2e0(%rbp)
jmp 0x2089b
movq -0x270(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x11060
movl %eax, -0x2e4(%rbp)
jmp 0x208b3
movq -0x270(%rbp), %rdi
callq 0x237c0
movl %eax, -0x2e8(%rbp)
jmp 0x208c7
movl -0x2e8(%rbp), %edi
callq 0x178e0
movl %eax, -0x2ec(%rbp)
jmp 0x208da
movl -0x2ec(%rbp), %ecx
movl -0x2e4(%rbp), %edx
movq -0x2e0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x289a0
jmp 0x208fb
movq -0x270(%rbp), %rax
movq -0x2e0(%rbp), %rcx
movq %rcx, 0x30(%rax)
movl $0x48, %edi
callq 0x32e0
movq %rax, -0x2f8(%rbp)
jmp 0x20920
movq -0x2f8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x2c100
jmp 0x20935
movq -0x270(%rbp), %rax
movq -0x2f8(%rbp), %rcx
movq %rcx, 0x38(%rax)
movl $0x28, %edi
callq 0x32e0
movq %rax, -0x300(%rbp)
jmp 0x2095a
movq -0x270(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x11060
movl %eax, -0x304(%rbp)
jmp 0x20972
movq -0x270(%rbp), %rdi
callq 0x237e0
movl %eax, -0x308(%rbp)
jmp 0x20986
movl -0x308(%rbp), %edi
callq 0x178e0
movl %eax, -0x30c(%rbp)
jmp 0x20999
movl -0x30c(%rbp), %ecx
movl -0x304(%rbp), %edx
movq -0x300(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x289a0
jmp 0x209ba
movq -0x270(%rbp), %rax
movq -0x300(%rbp), %rcx
movq %rcx, 0x40(%rax)
movb $0x1, 0x49(%rax)
jmp 0x20b0f
movq -0x298(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x48, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2a0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x48, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2a8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x28, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2c0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x28, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x48, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x28, %esi
callq 0x32f0
jmp 0x20b45
movq -0x2f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x48, %esi
callq 0x32f0
jmp 0x20b45
movq -0x300(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
movl $0x28, %esi
callq 0x32f0
jmp 0x20b45
leaq -0x248(%rbp), %rdi
callq 0x30b0
jmp 0x20b1d
movl $0x0, -0x258(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x30e0
leaq -0x40(%rbp), %rdi
callq 0x3638
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x248(%rbp), %rdi
callq 0x30e0
leaq -0x40(%rbp), %rdi
callq 0x3638
movq -0x250(%rbp), %rdi
callq 0x3570
nopw %cs:(%rax,%rax)