// File: /workspace/github_cpp_makefile_star2_O1/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)
movl $0x0, 0x47(%rdi)
leaq 0x167f2(%rip), %rax     # 0x288c8
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0xb2f7
movq (%r14), %rsi
leaq 0x30(%rsp), %rdi
movl $0x4, %edx
callq 0x3480
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x50(%rsp,%rax)
je 0x1217c
movq 0x15ede(%rip), %rdi     # 0x27ff0
leaq 0xc84c(%rip), %rsi      # 0x1e965
movl $0x23, %edx
callq 0x32b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x15ebc(%rip), %rdi     # 0x27ff0
callq 0x32b0
movq %rax, %rbx
leaq 0xc72d(%rip), %rsi      # 0x1e870
movl $0x1, %edx
movq %rax, %rdi
callq 0x32b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x1231b
leaq 0xc(%rsp), %rsi
movl $0x0, (%rsi)
leaq 0x30(%rsp), %rdi
movl $0x4, %edx
callq 0x32d0
testb $0x1, 0xc(%rsp)
je 0x121a1
movb $0x1, 0x4a(%rbx)
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x18420
leaq 0x8(%rbx), %rax
movq %r14, (%rax)
movl $0x48, %edi
callq 0x3260
movq %rax, %r15
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x19fac
movq %r15, 0x10(%rbx)
movl $0x28, %edi
callq 0x3260
movq %rax, %r14
movl 0x4(%r15), %edx
leal -0x1(%rdx), %eax
bsrl %eax, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
testl %eax, %eax
cmovel %eax, %ecx
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x16b0a
movq %r14, 0x18(%rbx)
movl $0x28, %edi
callq 0x3260
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
movl 0x4(%rcx), %edx
movl 0x4(%rax), %eax
bsrl %eax, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
testl %eax, %eax
cmovel %eax, %ecx
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x16b0a
movq %r14, 0x20(%rbx)
movb $0x1, 0x48(%rbx)
testb %bpl, %bpl
je 0x12311
movl $0x48, %edi
callq 0x3260
movq %rax, %r15
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x19fac
movq %r15, 0x28(%rbx)
movl $0x28, %edi
callq 0x3260
movq %rax, %r14
movl (%r15), %edx
movq (%rbx), %rax
movl 0x820(%rax), %eax
bsrl %eax, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
testl %eax, %eax
cmovel %eax, %ecx
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x16b0a
movq %r14, 0x30(%rbx)
movl $0x48, %edi
callq 0x3260
movq %rax, %r15
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x19fac
movq %r15, 0x38(%rbx)
movl $0x28, %edi
callq 0x3260
movq %rax, %r14
movl (%r15), %edx
movq (%rbx), %rax
movq 0x28(%rbx), %rcx
movl 0x4(%rcx), %esi
addl 0x820(%rax), %esi
bsrl %esi, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
testl %esi, %esi
cmovel %esi, %ecx
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x16b0a
movq %r14, 0x40(%rbx)
movb $0x1, 0x49(%rbx)
leaq 0x30(%rsp), %rdi
callq 0x3080
leaq 0x30(%rsp), %rdi
callq 0x3090
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12340
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12358
jmp 0x12362
jmp 0x12358
jmp 0x12362
jmp 0x12358
movq %rax, %rbx
movl $0x28, %esi
jmp 0x12377
movq %rax, %rbx
movl $0x48, %esi
movq %r15, %rdi
jmp 0x1237a
movq %rax, %rbx
movl $0x48, %esi
movq %r14, %rdi
callq 0x3270
jmp 0x1238b
movq %rax, %rbx
jmp 0x12395
jmp 0x12388
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3090
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x123b0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460