// File: /workspace/github_cpp_makefile_star2_O2/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 0x175f0(%rip), %rdx     # 0x1d498
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x8410
movq (%r15), %rsi
leaq 0x240(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3260
movq 0x240(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%rsp,%rax)
je 0x5efe
movq 0x1710b(%rip), %rdi     # 0x1cff0
leaq 0xd581(%rip), %rsi      # 0x1346d
callq 0x3200
movq %rax, %rdi
callq 0x3100
jmp 0x6102
movq 0x808(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0xb4f6
xorl %r12d, %r12d
leaq 0x240(%rsp), %r15
cmpq $0x100, %r12            # imm = 0x100
je 0x5f3d
movq 0x8(%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x5f38
movq %r15, %rsi
callq 0xf204
incq %r12
jmp 0x5f1d
movq 0x828(%r14), %rdi
leaq 0x240(%rsp), %rsi
callq 0xf204
leaq 0x81c(%r14), %r15
leaq 0x240(%rsp), %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x32d0
leaq 0x240(%rsp), %rdi
callq 0x3300
cmpq $0x0, 0x810(%r14)
je 0x6010
leaq 0x1752b(%rip), %rdx     # 0x1d4b8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x8410
movq (%rsp), %rsi
leaq 0x40(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3260
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x60(%rsp,%rax), %ebp
testb $0x5, %bpl
je 0x5fd9
movq 0x1702d(%rip), %rdi     # 0x1cff0
leaq 0xd4c9(%rip), %rsi      # 0x13493
callq 0x3200
movq %rax, %rdi
callq 0x3100
jmp 0x5ff4
movq 0x810(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xa7b0
leaq 0x40(%rsp), %rdi
callq 0x3300
leaq 0x40(%rsp), %rdi
callq 0x3320
movq %rsp, %rdi
callq 0x3478
testb $0x5, %bpl
jne 0x6102
leaq 0x48(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x808(%r14), %rax
movl 0x804(%rax), %eax
movq 0x8(%r14,%rax,8), %rax
movl 0x10(%rax), %edx
shll $0x2, %edx
leaq 0x1750f(%rip), %rsi     # 0x1d558
leaq 0x40(%rsp), %rdi
callq 0x10368
movl (%r15), %edx
leaq 0x17523(%rip), %rsi     # 0x1d580
leaq 0x40(%rsp), %rdi
callq 0x10368
movzbl 0x818(%r14), %edx
leaq 0x17532(%rip), %rsi     # 0x1d5a8
leaq 0x40(%rsp), %rdi
callq 0x10368
movzbl 0x819(%r14), %edx
leaq 0x17541(%rip), %rsi     # 0x1d5d0
leaq 0x40(%rsp), %rdi
callq 0x10368
movq 0x810(%r14), %rax
testq %rax, %rax
je 0x60c0
cmpb $0x1, (%rax)
jne 0x60c0
leaq 0x17547(%rip), %rsi     # 0x1d5f8
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x10368
jmp 0x60d1
leaq 0x17531(%rip), %rsi     # 0x1d5f8
leaq 0x40(%rsp), %rdi
callq 0x10374
leaq 0x17400(%rip), %rdx     # 0x1d4d8
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x8410
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x107c8
movq %rsp, %rdi
callq 0x3478
leaq 0x40(%rsp), %rdi
callq 0x4a5a
leaq 0x240(%rsp), %rdi
callq 0x3320
leaq 0x20(%rsp), %rdi
callq 0x3478
addq $0x440, %rsp            # imm = 0x440
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3478
jmp 0x615e
jmp 0x615b
movq %rax, %rbx
jmp 0x614c
jmp 0x616c
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3320
movq %rsp, %rdi
callq 0x3478
jmp 0x616f
movq %rax, %rbx
jmp 0x617c
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4a5a
jmp 0x616f
jmp 0x616c
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
callq 0x3320
leaq 0x20(%rsp), %rdi
callq 0x3478
movq %rbx, %rdi
callq 0x3410