// File: adamnovak[P]rlcsa/suffixarray.cpp
// Function: CSA::SuffixArray::writeTo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool) const
void
SuffixArray::writeTo(const std::string& base_name, bool write_data) const
{
  if(!this->ok) { return; }

  if(write_data)
  {
    std::ofstream data_file(base_name.c_str(), std::ios_base::binary);
    if(!data_file)
    {
      std::cerr << "Error: Cannot open data file " << base_name << "!" << std::endl;
      return;
    }
    data_file.write((char*)(this->data), this->data_size);
    data_file.close();
  }

  std::string sa_name = base_name + SA_EXTENSION;
  std::ofstream sa_file(sa_name.c_str(), std::ios_base::binary);
  if(!sa_file)
  {
    std::cerr << "Error: Cannot open suffix array file " << sa_name << "!" << std::endl;
    return;
  }
  sa_file.write((char*)&(this->sequences), sizeof(uint));
  sa_file.write((char*)(this->original_sa), this->data_size * sizeof(uint));
  sa_file.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x450(%rbp)
testb $0x1, (%rax)
jne 0x1b83f
jmp 0x1bb0d
testb $0x1, -0x11(%rbp)
je 0x1b97f
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x451(%rbp)
jmp 0x1b886
movb -0x451(%rbp), %al
testb $0x1, %al
jne 0x1b895
jmp 0x1b92a
movq 0x1c754(%rip), %rdi     # 0x37ff0
leaq 0xdf81(%rip), %rsi      # 0x29824
callq 0x32a0
movq %rax, -0x460(%rbp)
jmp 0x1b8b1
movq -0x460(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3280
movq %rax, -0x468(%rbp)
jmp 0x1b8ca
movq -0x468(%rbp), %rdi
leaq 0xdfec(%rip), %rsi      # 0x298c4
callq 0x32a0
movq %rax, -0x470(%rbp)
jmp 0x1b8e6
movq -0x470(%rbp), %rdi
movq 0x1c6bc(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x1b8fb
movl $0x1, -0x228(%rbp)
jmp 0x1b960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3450
jmp 0x1bb22
movq -0x450(%rbp), %rax
movq 0x8(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
callq 0x33f0
jmp 0x1b948
leaq -0x218(%rbp), %rdi
callq 0x3430
jmp 0x1b956
movl $0x0, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3450
movl -0x228(%rbp), %eax
testl %eax, %eax
je 0x1b97d
jmp 0x1b978
jmp 0x1bb0d
jmp 0x1b97f
movq -0x10(%rbp), %rsi
leaq 0x1cf26(%rip), %rdx     # 0x388b0
leaq -0x248(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0xd3c0
movq -0x478(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x448(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
jmp 0x1b9bf
movq -0x448(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x448(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x479(%rbp)
jmp 0x1b9df
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x1b9ee
jmp 0x1ba9d
movq 0x1c5fb(%rip), %rdi     # 0x37ff0
leaq 0xde46(%rip), %rsi      # 0x29842
callq 0x32a0
movq %rax, -0x488(%rbp)
jmp 0x1ba0a
movq -0x488(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3280
movq %rax, -0x490(%rbp)
jmp 0x1ba26
movq -0x490(%rbp), %rdi
leaq 0xde90(%rip), %rsi      # 0x298c4
callq 0x32a0
movq %rax, -0x498(%rbp)
jmp 0x1ba42
movq -0x498(%rbp), %rdi
movq 0x1c560(%rip), %rsi     # 0x37fb0
callq 0x3300
jmp 0x1ba57
movl $0x1, -0x228(%rbp)
jmp 0x1baf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x1bb16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x3450
jmp 0x1bb16
movq -0x450(%rbp), %rsi
addq $0x2c, %rsi
leaq -0x448(%rbp), %rdi
movl $0x4, %edx
callq 0x33f0
jmp 0x1babb
movq -0x450(%rbp), %rax
movq 0x18(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
shlq $0x2, %rdx
leaq -0x448(%rbp), %rdi
callq 0x33f0
jmp 0x1badd
leaq -0x448(%rbp), %rdi
callq 0x3430
jmp 0x1baeb
movl $0x0, -0x228(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x3450
leaq -0x248(%rbp), %rdi
callq 0x35d8
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
leaq -0x248(%rbp), %rdi
callq 0x35d8
movq -0x220(%rbp), %rdi
callq 0x3530
nop