// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl %ecx, %ebp
movq %rdi, %rbx
movq %rsi, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x38(%rdi)
andl $0x0, 0x47(%rdi)
leaq 0x15333(%rip), %rax     # 0x248b8
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0x934c
movq (%r14), %rsi
leaq 0x30(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3450
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x50(%rsp,%rax)
je 0xf5f4
movq 0x14a31(%rip), %rdi     # 0x23ff0
leaq 0x93af(%rip), %rsi      # 0x18975
callq 0x3210
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3200
leaq 0x9299(%rip), %rsi      # 0x18878
movq %rax, %rdi
callq 0x3210
movq %rax, %rdi
callq 0x3100
jmp 0xf76e
leaq 0xc(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0x30(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3290
testb $0x1, 0xc(%rsp)
je 0xf614
movb $0x1, 0x4a(%rbx)
pushq $0x48
popq %rdi
callq 0x3230
movq %rax, %r14
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x13c38
leaq 0x8(%rbx), %rax
movq %r14, (%rax)
pushq $0x48
popq %rdi
callq 0x3230
movq %rax, %r14
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x146b4
movq %r14, 0x10(%rbx)
pushq $0x28
popq %rdi
callq 0x3230
movq %rax, %r15
movl 0x4(%r14), %r14d
leal -0x1(%r14), %edi
callq 0xbad4
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
movl %r14d, %edx
movl %eax, %ecx
callq 0x129d0
movq %r15, 0x18(%rbx)
pushq $0x28
popq %rdi
callq 0x3230
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
movl 0x4(%rcx), %r15d
movl 0x4(%rax), %edi
callq 0xbad4
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %eax, %ecx
callq 0x129d0
movq %r14, 0x20(%rbx)
movb $0x1, 0x48(%rbx)
testb %bpl, %bpl
je 0xf764
pushq $0x48
popq %rdi
callq 0x3230
movq %rax, %r14
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x146b4
movq %r14, 0x28(%rbx)
pushq $0x28
popq %rdi
callq 0x3230
movq %rax, %r15
movl (%r14), %ebp
movq (%rbx), %rax
movl 0x820(%rax), %edi
callq 0xbad4
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
movl %ebp, %edx
movl %eax, %ecx
callq 0x129d0
movq %r15, 0x30(%rbx)
pushq $0x48
popq %rdi
callq 0x3230
movq %rax, %r15
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x146b4
movq %r15, 0x38(%rbx)
pushq $0x28
popq %rdi
callq 0x3230
movq %rax, %r14
movl (%r15), %ebp
movq (%rbx), %rax
movq 0x28(%rbx), %rcx
movl 0x4(%rcx), %edi
addl 0x820(%rax), %edi
callq 0xbad4
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %eax, %ecx
callq 0x129d0
movq %r14, 0x40(%rbx)
movb $0x1, 0x49(%rbx)
leaq 0x30(%rsp), %rdi
callq 0x3080
leaq 0x30(%rsp), %rdi
callq 0x30a0
leaq 0x10(%rsp), %rdi
callq 0x34a8
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf79d
movq %rax, %rbx
pushq $0x48
jmp 0xf7a9
jmp 0xf7a4
jmp 0xf7b1
movq %rax, %rbx
pushq $0x28
jmp 0xf7b6
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r15, %rdi
jmp 0xf7ba
jmp 0xf7b1
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r14, %rdi
callq 0x3240
jmp 0xf7cb
movq %rax, %rbx
jmp 0xf7d5
jmp 0xf7c8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x30a0
leaq 0x10(%rsp), %rdi
callq 0x34a8
movq %rbx, %rdi
callq 0x3430
nop