// File: /workspace/github_cpp_makefile_star2_O1/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 0x1875a(%rip), %rdx     # 0x1f4b8
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x9f63
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 0x6de1
movq 0x18253(%rip), %rbx     # 0x1eff0
leaq 0x106c4(%rip), %rsi     # 0x17468
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 0x18221(%rip), %rdi     # 0x1eff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x7066
movq 0x808(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0xce72
xorl %r12d, %r12d
leaq 0x240(%rsp), %r15
movq 0x8(%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x6e12
movq %r15, %rsi
callq 0x11e30
incq %r12
cmpq $0x100, %r12            # imm = 0x100
jne 0x6e00
movq 0x828(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0x11e30
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 0x6f5c
leaq 0x18668(%rip), %rdx     # 0x1f4d8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x9f63
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 0x6eea
movq 0x18148(%rip), %r12     # 0x1eff0
leaq 0x105df(%rip), %rsi     # 0x1748e
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 0x18115(%rip), %rdi     # 0x1eff0
callq 0x3040
movq %rax, %rdi
callq 0x3190
jmp 0x6f05
movq 0x810(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xc068
leaq 0x40(%rsp), %rdi
callq 0x3330
movq 0x180bc(%rip), %rax     # 0x1efc8
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 0x6f52
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
testb $0x5, %bpl
jne 0x7066
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 0x185e0(%rip), %rsi     # 0x1f578
leaq 0x40(%rsp), %rdi
callq 0x142fa
movl (%r15), %edx
leaq 0x185f4(%rip), %rsi     # 0x1f5a0
leaq 0x40(%rsp), %rdi
callq 0x142fa
movzbl 0x818(%r14), %edx
leaq 0x18603(%rip), %rsi     # 0x1f5c8
leaq 0x40(%rsp), %rdi
callq 0x142fa
movzbl 0x819(%r14), %edx
leaq 0x18612(%rip), %rsi     # 0x1f5f0
leaq 0x40(%rsp), %rdi
callq 0x142fa
movq 0x810(%r14), %rax
testq %rax, %rax
je 0x7011
cmpb $0x1, (%rax)
jne 0x7011
leaq 0x18618(%rip), %rsi     # 0x1f618
leaq 0x40(%rsp), %rdi
movl $0x1, %edx
callq 0x142fa
jmp 0x7022
leaq 0x18600(%rip), %rsi     # 0x1f618
leaq 0x40(%rsp), %rdi
callq 0x14306
leaq 0x184cf(%rip), %rdx     # 0x1f4f8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x9f63
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x14920
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x705c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
leaq 0x40(%rsp), %rdi
callq 0x5694
movq 0x17f5b(%rip), %rax     # 0x1efc8
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 0x70b9
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 0x7124
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x7124
jmp 0x7121
movq %rax, %rbx
jmp 0x70ff
jmp 0x7132
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3350
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7135
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x7135
movq %rax, %rbx
jmp 0x7142
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5694
jmp 0x7135
jmp 0x7132
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
callq 0x3350
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x715d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460
nop