// File: adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::processRun(std::pair<unsigned int, unsigned int>, unsigned int*, unsigned int*, bool*, CSA::RLEVector::Iterator**, bool) const
bool
RLCSA::processRun(pair_type run, usint* data, usint* offsets, bool* finished, PsiVector::Iterator** iters, bool steps) const
{
  bool found = true;
  usint run_start = 0, run_left = 0;
  pair_type next_sample = pair_type(0, 0);

  for(usint i = run.first; i <= run.second; i++)
  {
    if(finished[i])
    {
      if(run_left > 0) { run_left--; }
      continue;
    }
    if(data[i] < this->number_of_sequences) // Implicit sample here.
    {
      DeltaVector::Iterator iter(*(this->end_points));
      data[i] = (steps ? offsets[i] : iter.select(data[i]) + 1 - offsets[i]);
      finished[i] = true;
      if(run_left > 0) { run_left--; }
      continue;
    }
    if(next_sample.first < data[i]) // Need another sample.
    {
      next_sample = this->sa_samples->getFirstSampleAfter(data[i] - this->number_of_sequences);
      next_sample.first += this->number_of_sequences;
    }
    if(data[i] < next_sample.first) // No sample found for current position.
    {
      if(run_left > 0)
      {
        data[i] = data[run_start] + i - run_start;
        run_left--;
      }
      else
      {
        pair_type value = this->psi(data[i] - this->number_of_sequences, run.second - i, iters);
        data[i] = value.first;
        run_left = value.second;
        run_start = i;
      }
      offsets[i]++;
      found = false;
    }
    else  // Sampled position found.
    {
      data[i] = (steps ? offsets[i] : this->sa_samples->getSample(next_sample.second) - offsets[i]);
      finished[i] = true;
      if(run_left > 0) { run_left--; }
    }
  }
  return found;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movb 0x10(%rbp), %al
movq %rsi, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movb $0x1, -0x32(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq -0x44(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0xdef0
movl -0x8(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x4(%rbp), %eax
ja 0xa436
movq -0x28(%rbp), %rax
movl -0x50(%rbp), %ecx
testb $0x1, (%rax,%rcx)
je 0xa1da
cmpl $0x0, -0x3c(%rbp)
jbe 0xa1d5
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa428
movq -0xf0(%rbp), %rcx
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %edx
movl (%rax,%rdx,4), %eax
cmpl 0x820(%rcx), %eax
jae 0xa2c0
movq -0xf0(%rbp), %rax
movq 0x828(%rax), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x200a0
testb $0x1, -0x31(%rbp)
je 0xa229
movq -0x20(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xf4(%rbp)
jmp 0xa260
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0xc8(%rbp), %rdi
callq 0x20200
movl %eax, -0xf8(%rbp)
jmp 0xa247
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movq -0x20(%rbp), %rcx
movl -0x50(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x50(%rbp), %ecx
movb $0x1, (%rax,%rcx)
cmpl $0x0, -0x3c(%rbp)
jbe 0xa2af
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa2af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x200d0
jmp 0xa444
leaq -0xc8(%rbp), %rdi
callq 0x200d0
jmp 0xa428
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x50(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0xa31c
movq -0xf0(%rbp), %rax
movq 0x810(%rax), %rdi
movq -0x18(%rbp), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %esi
subl 0x820(%rax), %esi
callq 0xdf20
movq %rax, -0xdc(%rbp)
leaq -0x44(%rbp), %rdi
leaq -0xdc(%rbp), %rsi
callq 0xdb70
movq -0xf0(%rbp), %rax
movl 0x820(%rax), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x44(%rbp), %eax
jae 0xa3bc
cmpl $0x0, -0x3c(%rbp)
jbe 0xa35a
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl -0x50(%rbp), %edx
subl -0x38(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa3a6
movq -0xf0(%rbp), %rdi
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %esi
subl 0x820(%rdi), %esi
movl -0x4(%rbp), %edx
subl -0x50(%rbp), %edx
movq -0x30(%rbp), %rcx
callq 0xdfc0
movq %rax, -0xe4(%rbp)
movl -0xe4(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0xe0(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movb $0x0, -0x32(%rbp)
jmp 0xa426
testb $0x1, -0x31(%rbp)
je 0xa3d4
movq -0x20(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xfc(%rbp)
jmp 0xa3fa
movq -0xf0(%rbp), %rax
movq 0x810(%rax), %rdi
movl -0x40(%rbp), %esi
callq 0xe040
movq -0x20(%rbp), %rcx
movl -0x50(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x50(%rbp), %ecx
movb $0x1, (%rax,%rcx)
cmpl $0x0, -0x3c(%rbp)
jbe 0xa424
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa426
jmp 0xa428
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xa1ad
movb -0x32(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xd0(%rbp), %rdi
callq 0x3530