// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::locateUnsafe(std::pair<unsigned int, unsigned int>, unsigned int*, bool) const
void
RLCSA::locateUnsafe(pair_type range, usint* data, bool steps) const
{
  this->convertToBWTRange(range);
  usint items = length(range);
  usint* offsets = new usint[items];
  bool* finished = new bool[items];  // FIXME This could be more space efficient...

  PsiVector::Iterator** iters = this->getIterators();

  for(usint i = 0, j = range.first; i < items; i++, j++)
  {
    data[i] = j;
    offsets[i] = 0;
    finished[i] = false;
  }

  bool found = false;
  while(!found)
  {
    found = true;
    pair_type run = EMPTY_PAIR;
    for(usint i = 0; i < items; i++)
    {
      if(finished[i])
      {
        continue; // The run might continue after this.
      }
      else if(isEmpty(run))
      {
        run = pair_type(i, i);
      }
      else if(data[i] - data[run.first] == i - run.first)
      {
        run.second = i;
      }
      else
      {
        found &= this->processRun(run, data, offsets, finished, iters, steps);
        run = pair_type(i, i);
      }
    }
    if(!isEmpty(run)) { found &= this->processRun(run, data, offsets, finished, iters, steps); }
  }

  this->deleteIterators(iters);
  delete[] offsets;
  delete[] finished;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %rbp
movq %rsi, %r14
shrq $0x20, %r14
movl 0x820(%rdi), %r15d
incl %r14d
movl %r14d, %r13d
subl %r12d, %r13d
leaq (,%r13,4), %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
movq %r13, %rdi
callq 0x3030
movq %rax, %r13
movq %rbp, 0x28(%rsp)
movq %rbp, %rdi
callq 0x73ca
movq %rax, 0x10(%rsp)
movq %r14, 0x30(%rsp)
movq %r12, 0x20(%rsp)
subl %r12d, %r14d
je 0x7621
addl 0x20(%rsp), %r15d
cmpl $0x1, %r14d
movl %r14d, %ebp
adcl $0x0, %ebp
leaq (,%rbp,4), %rdx
xorl %r12d, %r12d
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x3150
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3150
leal (%r15,%r12), %eax
movl %eax, (%rbx,%r12,4)
incq %r12
cmpq %r12, %rbp
jne 0x7611
cmpl $0x1, %r14d
adcl $0x0, %r14d
movzbl 0x1c(%rsp), %r15d
movq 0x30(%rsp), %rax
cmpl 0x20(%rsp), %eax
jne 0x7646
movb $0x1, %r12b
xorl %esi, %esi
movl $0x1, %eax
jmp 0x76a2
movl $0x1, %eax
xorl %ebp, %ebp
movb $0x1, %r12b
xorl %esi, %esi
cmpb $0x0, (%r13,%rbp)
jne 0x769a
cmpl %esi, %eax
ja 0x7696
movl %eax, %ecx
movl (%rbx,%rbp,4), %edx
subl (%rbx,%rcx,4), %edx
movl %ebp, %edi
subl %eax, %edi
cmpl %edx, %edi
je 0x7698
shlq $0x20, %rsi
orq %rcx, %rsi
movl %r15d, (%rsp)
movq 0x28(%rsp), %rdi
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
movq %r13, %r8
movq 0x10(%rsp), %r9
callq 0x7ac0
andb %al, %r12b
movl %ebp, %eax
movl %ebp, %esi
incq %rbp
cmpq %rbp, %r14
jne 0x7652
cmpl %esi, %eax
ja 0x76d3
shlq $0x20, %rsi
movl %eax, %eax
orq %rsi, %rax
movl %r15d, (%rsp)
movq 0x28(%rsp), %rdi
movq %rax, %rsi
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
movq %r13, %r8
movq 0x10(%rsp), %r9
callq 0x7ac0
andb %al, %r12b
testb $0x1, %r12b
je 0x762f
movq 0x10(%rsp), %rsi
callq 0x7442
movq 0x8(%rsp), %rdi
callq 0x3300
movq %r13, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3300
nop