// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movb %cl, %al
movq %rsi, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x90(%rbp)
leaq -0x8(%rbp), %rsi
callq 0xa110
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xdc40
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %edi
callq 0x3030
movq -0x90(%rbp), %rdi
movq %rax, -0x38(%rbp)
callq 0x9860
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x9c0b
movl -0x48(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x9bc9
movb $0x0, -0x49(%rbp)
movb -0x49(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x9c1d
jmp 0x9d9b
movb $0x1, -0x49(%rbp)
movq 0x1faec(%rip), %rax     # 0x29714
movq %rax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x9d2e
movq -0x38(%rbp), %rax
movl -0x58(%rbp), %ecx
testb $0x1, (%rax,%rcx)
je 0x9c51
jmp 0x9d20
movq -0x54(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0xdaf0
testb $0x1, %al
jne 0x9c68
jmp 0x9c8a
leaq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rdx
movq %rdx, %rsi
callq 0xdec0
leaq -0x54(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xdb70
jmp 0x9d1c
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movl -0x54(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9cb0
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x9d1a
movq -0x90(%rbp), %rdi
movq -0x54(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movb -0x19(%rbp), %al
movq -0x70(%rbp), %rsi
andb $0x1, %al
movzbl %al, %eax
movl %eax, (%rsp)
callq 0xa140
andb $0x1, %al
movzbl %al, %ecx
movb -0x49(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x49(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x58(%rbp), %rdx
movq %rdx, %rsi
callq 0xdec0
leaq -0x54(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xdb70
jmp 0x9d1c
jmp 0x9d1e
jmp 0x9d20
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x9c33
movq -0x54(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0xdaf0
testb $0x1, %al
jne 0x9d96
movq -0x90(%rbp), %rdi
movq -0x54(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movb -0x19(%rbp), %al
movq -0x88(%rbp), %rsi
andb $0x1, %al
movzbl %al, %eax
movl %eax, (%rsp)
callq 0xa140
andb $0x1, %al
movzbl %al, %ecx
movb -0x49(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x9c0f
movq -0x90(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x9930
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x9dc8
movq -0x98(%rbp), %rdi
callq 0x33e0
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0x9de5
movq -0xa0(%rbp), %rdi
callq 0x33e0
addq $0xb0, %rsp
popq %rbp
retq
nop