// File: 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
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2f69f(%rip), %rdx     # 0x38548
leaq -0x30(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
callq 0xd3c0
movq -0x4c0(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
jmp 0x8edb
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x4c9(%rbp)
jmp 0x8efb
movb -0x4c9(%rbp), %al
testb $0x1, %al
jne 0x8f07
jmp 0x8f75
movq 0x2f0e2(%rip), %rdi     # 0x37ff0
leaq 0x205e0(%rip), %rsi     # 0x294f5
callq 0x32a0
movq %rax, -0x4d8(%rbp)
jmp 0x8f23
movq -0x4d8(%rbp), %rdi
movq 0x2f07f(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x8f38
movl $0x1, -0x240(%rbp)
jmp 0x9318
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x936c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x9360
movq -0x4c8(%rbp), %rax
movq 0x808(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x17180
jmp 0x8f91
movl $0x0, -0x244(%rbp)
cmpl $0x100, -0x244(%rbp)    # imm = 0x100
jae 0x8ff1
movq -0x4c8(%rbp), %rax
movl -0x244(%rbp), %ecx
cmpq $0x0, 0x8(%rax,%rcx,8)
je 0x8fde
movq -0x4c8(%rbp), %rax
movl -0x244(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rdi
leaq -0x230(%rbp), %rsi
callq 0x1f470
jmp 0x8fdc
jmp 0x8fde
jmp 0x8fe0
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x8f9b
movq -0x4c8(%rbp), %rax
movq 0x828(%rax), %rdi
leaq -0x230(%rbp), %rsi
callq 0x1f470
jmp 0x900d
movq -0x4c8(%rbp), %rsi
addq $0x81c, %rsi            # imm = 0x81C
leaq -0x230(%rbp), %rdi
movl $0x4, %edx
callq 0x33f0
jmp 0x902e
leaq -0x230(%rbp), %rdi
callq 0x3430
jmp 0x903c
movq -0x4c8(%rbp), %rax
cmpq $0x0, 0x810(%rax)
je 0x9198
movq -0x10(%rbp), %rsi
leaq 0x2f50c(%rip), %rdx     # 0x38568
leaq -0x268(%rbp), %rdi
callq 0xd3c0
jmp 0x906a
leaq -0x268(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x468(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
jmp 0x908c
movq -0x468(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x468(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x4d9(%rbp)
jmp 0x90ac
movb -0x4d9(%rbp), %al
testb $0x1, %al
jne 0x90b8
jmp 0x9129
movq 0x2ef31(%rip), %rdi     # 0x37ff0
leaq 0x20455(%rip), %rsi     # 0x2951b
callq 0x32a0
movq %rax, -0x4e8(%rbp)
jmp 0x90d4
movq -0x4e8(%rbp), %rdi
movq 0x2eece(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x90e9
movl $0x1, -0x240(%rbp)
jmp 0x915d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x9187
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x468(%rbp), %rdi
callq 0x3450
jmp 0x9187
movq -0x4c8(%rbp), %rax
movq 0x810(%rax), %rdi
leaq -0x468(%rbp), %rsi
callq 0x146e0
jmp 0x9145
leaq -0x468(%rbp), %rdi
callq 0x3430
jmp 0x9153
movl $0x0, -0x240(%rbp)
leaq -0x468(%rbp), %rdi
callq 0x3450
leaq -0x268(%rbp), %rdi
callq 0x35d8
movl -0x240(%rbp), %eax
testl %eax, %eax
jne 0x9318
jmp 0x9185
jmp 0x9198
leaq -0x268(%rbp), %rdi
callq 0x35d8
jmp 0x9360
leaq -0x498(%rbp), %rdi
callq 0x6430
jmp 0x91a6
movq -0x4c8(%rbp), %rdi
callq 0xda60
movl %eax, -0x4ec(%rbp)
jmp 0x91ba
movl -0x4ec(%rbp), %edx
shll $0x2, %edx
leaq 0x2f43e(%rip), %rsi     # 0x38608
leaq -0x498(%rbp), %rdi
callq 0x217f0
jmp 0x91d8
movq -0x4c8(%rbp), %rax
movl 0x81c(%rax), %edx
leaq 0x2f444(%rip), %rsi     # 0x38630
leaq -0x498(%rbp), %rdi
callq 0x217f0
jmp 0x91fa
movq -0x4c8(%rbp), %rax
movzbl 0x818(%rax), %edx
andl $0x1, %edx
leaq 0x2f446(%rip), %rsi     # 0x38658
leaq -0x498(%rbp), %rdi
callq 0x217f0
jmp 0x9220
movq -0x4c8(%rbp), %rax
movzbl 0x819(%rax), %edx
andl $0x1, %edx
leaq 0x2f448(%rip), %rsi     # 0x38680
leaq -0x498(%rbp), %rdi
callq 0x217f0
jmp 0x9246
movq -0x4c8(%rbp), %rax
cmpq $0x0, 0x810(%rax)
je 0x92b1
movq -0x4c8(%rbp), %rax
movq 0x810(%rax), %rdi
callq 0xdaa0
movb %al, -0x4ed(%rbp)
jmp 0x9272
movb -0x4ed(%rbp), %al
testb $0x1, %al
jne 0x927e
jmp 0x92b1
leaq 0x2f423(%rip), %rsi     # 0x386a8
leaq -0x498(%rbp), %rdi
movl $0x1, %edx
callq 0x217f0
jmp 0x9298
jmp 0x92c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x9354
leaq 0x2f3f0(%rip), %rsi     # 0x386a8
leaq -0x498(%rbp), %rdi
callq 0x21830
jmp 0x92c6
jmp 0x92c8
movq -0x10(%rbp), %rsi
leaq 0x2f2b5(%rip), %rdx     # 0x38588
leaq -0x4b8(%rbp), %rdi
callq 0xd3c0
jmp 0x92e1
leaq -0x498(%rbp), %rdi
leaq -0x4b8(%rbp), %rsi
callq 0x21f80
jmp 0x92f6
leaq -0x4b8(%rbp), %rdi
callq 0x35d8
leaq -0x498(%rbp), %rdi
callq 0x6470
movl $0x0, -0x240(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3450
leaq -0x30(%rbp), %rdi
callq 0x35d8
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x4b8(%rbp), %rdi
callq 0x35d8
leaq -0x498(%rbp), %rdi
callq 0x6470
leaq -0x230(%rbp), %rdi
callq 0x3450
leaq -0x30(%rbp), %rdi
callq 0x35d8
movq -0x238(%rbp), %rdi
callq 0x3530
nopw %cs:(%rax,%rax)