// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::writeTo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
void
RLCSA::writeTo(const std::string& base_name) const
{
  std::string array_name = base_name + ARRAY_EXTENSION;
  std::ofstream array_file(array_name.c_str(), std::ios_base::binary);
  if(!array_file)
  {
    std::cerr << "RLCSA: Error creating Psi array file!" << std::endl;
    return;
  }

  this->alphabet->writeTo(array_file);
  for(usint c = 0; c < CHARS; c++)
  {
    if(this->array[c] != 0)
    {
      this->array[c]->writeTo(array_file);
    }
  }

  this->end_points->writeTo(array_file);
  array_file.write((char*)&(this->sample_rate), sizeof(this->sample_rate));
  array_file.close();

  if(this->sa_samples != 0)
  {
    std::string sa_sample_name = base_name + SA_SAMPLES_EXTENSION;
    std::ofstream sa_sample_file(sa_sample_name.c_str(), std::ios_base::binary);
    if(!sa_sample_file)
    {
      std::cerr << "RLCSA: Error creating suffix array sample file!" << std::endl;
      return;
    }

    this->sa_samples->writeTo(sa_sample_file);
    sa_sample_file.close();
  }

  Parameters parameters;
  parameters.set(RLCSA_BLOCK_SIZE.first, this->getBlockSize() * sizeof(usint));
  parameters.set(SAMPLE_RATE.first, this->sample_rate);
  parameters.set(SUPPORT_LOCATE.first, this->support_locate);
  parameters.set(SUPPORT_DISPLAY.first, this->support_display);
  if(this->sa_samples != 0 && this->sa_samples->isWeighted())
  {
    parameters.set(WEIGHTED_SAMPLES.first, 1);
  }
  else { parameters.set(WEIGHTED_SAMPLES); }
  parameters.write(base_name + PARAMETERS_EXTENSION);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x440, %rsp            # imm = 0x440
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1980c(%rip), %rdx     # 0x204b8
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0xa0a5
movq (%r15), %rsi
leaq 0x240(%rsp), %rdi
movl $0x4, %edx
callq 0x32a0
movq 0x240(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%rsp,%rax)
je 0x6d2f
movq 0x19305(%rip), %rbx     # 0x1fff0
leaq 0x117c3(%rip), %rsi     # 0x184b5
movl $0x25, %edx
movq %rbx, %rdi
callq 0x32b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x192d3(%rip), %rdi     # 0x1fff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x6fb4
movq 0x808(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0xcf9a
xorl %r12d, %r12d
leaq 0x240(%rsp), %r15
movq 0x8(%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x6d60
movq %r15, %rsi
callq 0x12196
incq %r12
cmpq $0x100, %r12            # imm = 0x100
jne 0x6d4e
movq 0x828(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0x12196
leaq 0x81c(%r14), %r15
leaq 0x240(%rsp), %rdi
movl $0x4, %edx
movq %r15, %rsi
callq 0x3310
leaq 0x240(%rsp), %rdi
callq 0x3330
cmpq $0x0, 0x810(%r14)
je 0x6eaa
leaq 0x1971a(%rip), %rdx     # 0x204d8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0xa0a5
movq (%rsp), %rsi
leaq 0x40(%rsp), %rdi
movl $0x4, %edx
callq 0x32a0
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x60(%rsp,%rax), %ebp
testb $0x5, %bpl
je 0x6e38
movq 0x191fa(%rip), %r12     # 0x1fff0
leaq 0x116de(%rip), %rsi     # 0x184db
movl $0x2f, %edx
movq %r12, %rdi
callq 0x32b0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x191c7(%rip), %rdi     # 0x1fff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x6e53
movq 0x810(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xc190
leaq 0x40(%rsp), %rdi
callq 0x3330
movq 0x1916e(%rip), %rax     # 0x1ffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x48(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x40(%rsp,%rcx)
callq 0x3200
leaq 0x138(%rsp), %rdi
callq 0x30e0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ea0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
testb $0x5, %bpl
jne 0x6fb4
leaq 0x48(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq 0x808(%r14), %rax
movl 0x804(%rax), %eax
movq 0x8(%r14,%rax,8), %rax
movl 0x10(%rax), %edx
shll $0x2, %edx
leaq 0x19692(%rip), %rsi     # 0x20578
leaq 0x40(%rsp), %rdi
callq 0x1489e
movl (%r15), %edx
leaq 0x196a6(%rip), %rsi     # 0x205a0
leaq 0x40(%rsp), %rdi
callq 0x1489e
movzbl 0x818(%r14), %edx
leaq 0x196b5(%rip), %rsi     # 0x205c8
leaq 0x40(%rsp), %rdi
callq 0x1489e
movzbl 0x819(%r14), %edx
leaq 0x196c4(%rip), %rsi     # 0x205f0
leaq 0x40(%rsp), %rdi
callq 0x1489e
movq 0x810(%r14), %rax
testq %rax, %rax
je 0x6f5f
cmpb $0x1, (%rax)
jne 0x6f5f
leaq 0x196ca(%rip), %rsi     # 0x20618
leaq 0x40(%rsp), %rdi
movl $0x1, %edx
callq 0x1489e
jmp 0x6f70
leaq 0x196b2(%rip), %rsi     # 0x20618
leaq 0x40(%rsp), %rdi
callq 0x148aa
leaq 0x19581(%rip), %rdx     # 0x204f8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0xa0a5
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x14eb2
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6faa
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
leaq 0x40(%rsp), %rdi
callq 0x55c8
movq 0x1900d(%rip), %rax     # 0x1ffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x248(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x240(%rsp,%rcx)
callq 0x3200
leaq 0x338(%rsp), %rdi
callq 0x30e0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7007
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
addq $0x440, %rsp            # imm = 0x440
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7072
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x7072
jmp 0x706f
movq %rax, %rbx
jmp 0x704d
jmp 0x7080
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3350
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7083
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x7083
movq %rax, %rbx
jmp 0x7090
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x55c8
jmp 0x7083
jmp 0x7080
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
callq 0x3350
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x70ab
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460
nop