// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/rlcsa.cpp
// Function: CSA::RLCSA::directLocate(unsigned int, bool) const
usint
RLCSA::directLocate(usint index, bool steps) const
{
  // Note that index is in BWT coordinates initially.
  
  // This keeps track of how far along the sequence we had to go to find an SA
  // sample.
  usint offset = 0;
  while(true)
  {
    // First try in BWT space, so we can account for the text end characters.
    if(this->hasImplicitSample(index))
    {
      // If we took an implicit sample at this index in the BWT (due to us being
      // in the range occupied by sequence start characters), we know where it
      // falls in the original sequences: at the endpoint of the appropriate
      // text.
      if(steps) { return offset; }
      else      { return this->getImplicitSample(index) - offset; }
    }
    // Pop index into SA space, where the SA samples live
    index -= this->number_of_sequences;
    if(this->sa_samples->isSampled(index))
    {
      // If we took a real SA sample here, we know where it falls in the
      // original sequences.
      return (steps ? offset : this->sa_samples->getSampleAt(index) - offset);
    }
    
    // If we get here, we couldn't map this position. Proceed forwards (towards
    // the end of the sequence), in hopes of hitting either a sample or the
    // sequence end character. Note that psi maps from SA position to the *BWT*
    // position of the subsequent character, popping index back into BWT space.
    index = this->psi(index);
    offset++;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %r15d
movl %esi, %ebp
movq %rdi, %r14
movl 0x820(%rdi), %eax
xorl %ebx, %ebx
cmpl %esi, %eax
ja 0x785a
xorl %ebx, %ebx
movq %rsp, %r12
subl %eax, %ebp
movq 0x810(%r14), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x12744
movq %r12, %rdi
movl %ebp, %esi
callq 0x12eba
movl %eax, %r13d
movq %r12, %rdi
callq 0x1274a
testb %r13b, %r13b
jne 0x7892
movl 0x4(%r14), %eax
cmpl %ebp, %eax
jbe 0x7840
movq 0x808(%r14), %rcx
movl %ebp, %eax
xorl %edx, %edx
divl 0x1008(%rcx)
movl 0xc08(%rcx,%rax,4), %eax
leaq (%rcx,%rax,4), %rax
addq $0x804, %rax            # imm = 0x804
movl (%rax), %r13d
addq $0x4, %rax
cmpl %ebp, 0x4(%rcx,%r13,8)
jb 0x7804
movq 0x8(%r14,%r13,8), %rsi
movq %r12, %rdi
callq 0x13394
movq 0x808(%r14), %rax
subl (%rax,%r13,8), %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x1368a
movl %eax, %ebp
movq %r12, %rdi
callq 0x1339a
jmp 0x7849
addl 0x820(%r14), %eax
movl %eax, %ebp
incl %ebx
movl 0x820(%r14), %eax
cmpl %ebp, %eax
jbe 0x77a7
testb %r15b, %r15b
jne 0x7948
movq 0x828(%r14), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x12744
movq %r14, %rdi
movl %ebp, %esi
callq 0x128f8
movl %eax, %ebp
movq %rsp, %rdi
callq 0x1274a
subl %ebx, %ebp
incl %ebp
jmp 0x7946
testb %r15b, %r15b
jne 0x7948
movq 0x810(%r14), %r15
movq 0x10(%r15), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x12744
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x12750
movl %eax, %ecx
decl %ecx
movq 0x18(%r15), %rsi
movl 0xc(%rsi), %r8d
imull %r8d, %ecx
movl %ecx, %edi
shrl $0x5, %edi
andl $0x1f, %ecx
movl $0x20, %edx
movl $0x20, %r9d
subl %ecx, %r9d
movl %r8d, %eax
subl %r9d, %eax
jae 0x78f6
movl %r9d, %edx
movl %r8d, %eax
jmp 0x790d
movq (%rsi), %r8
movl %edi, %r9d
movl (%r8,%r9,4), %r12d
shll %cl, %r12d
shrl %cl, %r12d
movl %eax, %ecx
shll %cl, %r12d
incl %edi
testl %eax, %eax
je 0x792a
subl %eax, %edx
movq (%rsi), %rcx
movl %edi, %esi
movl (%rcx,%rsi,4), %esi
movl %edx, %ecx
shrl %cl, %esi
negb %al
movl %eax, %ecx
shll %cl, %esi
shrl %cl, %esi
orl %esi, %r12d
imull 0x4(%r15), %r12d
movl 0x8(%r15), %ebp
decl %ebp
cmpl %r12d, %ebp
cmovael %r12d, %ebp
movq %rsp, %rdi
callq 0x1274a
subl %ebx, %ebp
movl %ebp, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x796a
jmp 0x796a
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1339a
jmp 0x7975
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1274a
movq %rbx, %rdi
callq 0x3460
nop