// File: adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::RLCSA(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned int, CSA::Sampler*, bool)
RLCSA::RLCSA(uchar* data, usint bytes, usint block_size, usint sa_sample_rate, usint threads, Sampler* sampler, bool delete_data) :
  ok(false),
  alphabet(0),
  sa_samples(0), support_locate(false), support_display(false),
  sample_rate(sa_sample_rate),
  end_points(0)
{
  for(usint c = 0; c < CHARS; c++) { this->array[c] = 0; }

  if(!data || bytes == 0)
  {
    std::cerr << "RLCSA: No input data given!" << std::endl;
    if(delete_data) { delete[] data; }
    return;
  }
  if(block_size < 2 * sizeof(usint) || block_size % sizeof(usint) != 0)
  {
    std::cerr << "RLCSA: Block size must be a multiple of " << sizeof(usint) << " bytes!" << std::endl;
    if(delete_data) { delete[] data; }
    return;
  }
  if(sampler != 0 && sampler->getStatus() != Sampler::SAMPLED)
  {
    std::cerr << "RLCSA: No samples given!" << std::endl;
    if(delete_data) { delete[] data; }
    return;
  }

  this->buildRLCSA(data, 0, bytes, block_size, threads, sampler, false, delete_data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb 0x18(%rbp), %al
movq 0x10(%rbp), %r10
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movb $0x0, (%rax)
movq $0x0, 0x808(%rax)
movq $0x0, 0x810(%rax)
movb $0x0, 0x818(%rax)
movb $0x0, 0x819(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x81c(%rax)
movq $0x0, 0x828(%rax)
movl $0x0, -0x28(%rbp)
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
jae 0x8288
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
movq $0x0, 0x8(%rax,%rcx,8)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x8264
cmpq $0x0, -0x10(%rbp)
je 0x8295
cmpl $0x0, -0x14(%rbp)
jne 0x82db
movq 0x2fd54(%rip), %rdi     # 0x37ff0
leaq 0x21161(%rip), %rsi     # 0x29404
callq 0x32a0
movq %rax, %rdi
movq 0x2fcfe(%rip), %rsi     # 0x37fb0
callq 0x3300
testb $0x1, -0x21(%rbp)
je 0x82d6
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x82d4
movq -0x38(%rbp), %rdi
callq 0x33e0
jmp 0x82d6
jmp 0x83e4
movl -0x18(%rbp), %eax
cmpq $0x8, %rax
jb 0x82f1
movl -0x18(%rbp), %eax
andq $0x3, %rax
cmpq $0x0, %rax
je 0x8353
movq 0x2fcf8(%rip), %rdi     # 0x37ff0
leaq 0x21121(%rip), %rsi     # 0x29420
callq 0x32a0
movq %rax, %rdi
movl $0x4, %esi
callq 0x30d0
movq %rax, %rdi
leaq 0x2112e(%rip), %rsi     # 0x29449
callq 0x32a0
movq %rax, %rdi
movq 0x2fc86(%rip), %rsi     # 0x37fb0
callq 0x3300
testb $0x1, -0x21(%rbp)
je 0x834e
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x834c
movq -0x40(%rbp), %rdi
callq 0x33e0
jmp 0x834e
jmp 0x83e4
cmpq $0x0, 0x10(%rbp)
je 0x83ab
movq 0x10(%rbp), %rdi
callq 0xd500
cmpl $0x2, %eax
je 0x83ab
movq 0x2fc81(%rip), %rdi     # 0x37ff0
leaq 0x210db(%rip), %rsi     # 0x29451
callq 0x32a0
movq %rax, %rdi
movq 0x2fc2b(%rip), %rsi     # 0x37fb0
callq 0x3300
testb $0x1, -0x21(%rbp)
je 0x83a9
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x83a7
movq -0x48(%rbp), %rdi
callq 0x33e0
jmp 0x83a9
jmp 0x83e4
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x20(%rbp), %r9d
movq 0x10(%rbp), %r10
movb -0x21(%rbp), %al
xorl %edx, %edx
xorl %r11d, %r11d
andb $0x1, %al
movq %r10, (%rsp)
movl $0x0, 0x8(%rsp)
movzbl %al, %eax
movl %eax, 0x10(%rsp)
callq 0x7480
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)