// File: adamnovak[P]rlcsa/docarray.cpp
// Function: CSA::DocArray::writeTo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
void
DocArray::writeTo(const std::string& base_name) const
{
  std::string output_name = base_name + DOCUMENT_EXTENSION;
  std::ofstream output(output_name.c_str(), std::ios_base::binary);
  if(!output)
  {
    std::cerr << "DocArray: Error creating output file " << output_name << "!" << std::endl;
    return;
  }

  usint flags = 0; if(this->usesRLE()) { flags |= RLE_FLAG; }
  output.write((char*)(&flags), sizeof(flags));

  this->leaf_ranges->writeTo(output);
  this->first_children->writeTo(output);
  this->parents->writeBuffer(output);
  this->next_leaves->writeBuffer(output);

  if(this->hasGrammar())
  {
    this->rule_borders->writeTo(output);
    this->rules->writeBuffer(output);
    this->block_borders->writeTo(output);
    this->blocks->writeBuffer(output);
  }

  output.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x23da7(%rip), %rdx     # 0x46980
leaq -0x30(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0xfc50
movq -0x250(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movl $0x4, %edx
callq 0x3360
jmp 0x22c0b
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x259(%rbp)
jmp 0x22c2b
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x22c3a
jmp 0x22ce9
movq 0x233af(%rip), %rdi     # 0x45ff0
leaq 0x11e80(%rip), %rsi     # 0x34ac8
callq 0x32c0
movq %rax, -0x268(%rbp)
jmp 0x22c56
movq -0x268(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3290
movq %rax, -0x270(%rbp)
jmp 0x22c6f
movq -0x270(%rbp), %rdi
leaq 0x11c13(%rip), %rsi     # 0x34890
callq 0x32c0
movq %rax, -0x278(%rbp)
jmp 0x22c8b
movq -0x278(%rbp), %rdi
movq 0x23317(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x22ca0
movl $0x1, -0x240(%rbp)
jmp 0x22e3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x22e5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3480
jmp 0x22e5c
movq -0x258(%rbp), %rdi
movl $0x0, -0x244(%rbp)
callq 0x23b20
movb %al, -0x279(%rbp)
jmp 0x22d07
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x22d13
jmp 0x22d22
movl -0x244(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x244(%rbp)
leaq -0x230(%rbp), %rdi
leaq -0x244(%rbp), %rsi
movl $0x4, %edx
callq 0x3410
jmp 0x22d3c
movq -0x258(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x29e70
jmp 0x22d55
movq -0x258(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2c720
jmp 0x22d6e
movq -0x258(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x17b50
jmp 0x22d87
movq -0x258(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x17b50
jmp 0x22da0
movq -0x258(%rbp), %rdi
callq 0x79d0
movb %al, -0x27a(%rbp)
jmp 0x22db4
movb -0x27a(%rbp), %al
testb $0x1, %al
jne 0x22dc0
jmp 0x22e26
movq -0x258(%rbp), %rax
movq 0x28(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2c720
jmp 0x22dd9
movq -0x258(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x17b50
jmp 0x22df2
movq -0x258(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2c720
jmp 0x22e0b
movq -0x258(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x17b50
jmp 0x22e24
jmp 0x22e26
leaq -0x230(%rbp), %rdi
callq 0x3460
jmp 0x22e34
movl $0x0, -0x240(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3480
leaq -0x30(%rbp), %rdi
callq 0x3638
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x3638
movq -0x238(%rbp), %rdi
callq 0x3570
nopw %cs:(%rax,%rax)