// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/bits/rlevector.cpp
// Function: CSA::RLEVector::Iterator::select(unsigned int)
usint
RLEVector::Iterator::select(usint index)
{
  const RLEVector& par = (const RLEVector&)(this->parent);

  if(index >= par.items) { return par.size; }
  this->getSample(this->sampleForIndex(index));
  this->run = 0;

  usint lim = index - this->sample.first;
  while(this->cur < lim)
  {
    this->val += this->buffer.readDeltaCode();
    usint temp = this->buffer.readDeltaCode();
    this->val += temp - 1;
    this->cur += temp;
  }
  if(this->cur > lim)
  {
    this->run = this->cur - lim;
    this->cur -= this->run;
    this->val -= this->run;
  }

  return this->val;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq (%rdi), %rax
cmpl %esi, 0x4(%rax)
jbe 0x13caa
movl %esi, %ebp
movq %rdi, %rbx
callq 0x1240e
movq %rbx, %rdi
movl %eax, %esi
callq 0x135a4
movl $0x0, 0x1c(%rbx)
subl 0xc(%rbx), %ebp
movl 0x14(%rbx), %esi
cmpl %ebp, %esi
jae 0x13c96
movq 0x28(%rbx), %rdi
movl 0x44(%rbx), %eax
movl 0x40(%rbx), %r8d
movl 0x18(%rbx), %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %eax, %ecx
decl %ecx
movl %ecx, 0x44(%rbx)
movl %r8d, %eax
movl (%rdi,%rax,4), %r10d
je 0x13aac
movl %ecx, %eax
jmp 0x13abf
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %eax
incl %edx
btl %ecx, %r10d
jae 0x13a98
movl $0x1, %r11d
movl %edx, %ecx
shll %cl, %r11d
xorl %r10d, %r10d
cmpl %edx, %eax
ja 0x13b04
subl %eax, %edx
movl %r8d, %ecx
movl (%rdi,%rcx,4), %r10d
negb %al
movl %eax, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl %edx, %ecx
shll %cl, %r10d
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %eax
movl %r8d, %r14d
testl %edx, %edx
je 0x13b26
subl %edx, %eax
movl %eax, 0x44(%rbx)
movl (%rdi,%r14,4), %r15d
movl %eax, %ecx
shrl %cl, %r15d
negb %dl
movl %edx, %ecx
shll %cl, %r15d
shrl %cl, %r15d
orl %r15d, %r10d
orl %r11d, %r10d
decl %r10d
xorl %r11d, %r11d
movl %r10d, %edx
subl %eax, %edx
jae 0x13b3b
movl %r10d, %edx
jmp 0x13b5a
movl (%rdi,%r14,4), %r11d
negb %al
movl %eax, %ecx
shll %cl, %r11d
shrl %cl, %r11d
movl %edx, %ecx
shll %cl, %r11d
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, %eax
testl %edx, %edx
je 0x13b7c
subl %edx, %eax
movl %eax, 0x44(%rbx)
movl %r8d, %ecx
movl (%rdi,%rcx,4), %r14d
movl %eax, %ecx
shrl %cl, %r14d
negb %dl
movl %edx, %ecx
shll %cl, %r14d
shrl %cl, %r14d
orl %r14d, %r11d
btsl %r10d, %r11d
addl %r11d, %r9d
movl %r9d, 0x18(%rbx)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %eax, %ecx
decl %ecx
movl %ecx, 0x44(%rbx)
movl %r8d, %eax
movl (%rdi,%rax,4), %r10d
je 0x13ba0
movl %ecx, %eax
jmp 0x13bb3
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %eax
incl %edx
btl %ecx, %r10d
jae 0x13b8c
movl $0x1, %r11d
movl %edx, %ecx
shll %cl, %r11d
xorl %r10d, %r10d
cmpl %edx, %eax
ja 0x13bf8
subl %eax, %edx
movl %r8d, %ecx
movl (%rdi,%rcx,4), %r10d
negb %al
movl %eax, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl %edx, %ecx
shll %cl, %r10d
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %eax
movl %r8d, %r14d
testl %edx, %edx
je 0x13c1a
subl %edx, %eax
movl %eax, 0x44(%rbx)
movl (%rdi,%r14,4), %r15d
movl %eax, %ecx
shrl %cl, %r15d
negb %dl
movl %edx, %ecx
shll %cl, %r15d
shrl %cl, %r15d
orl %r15d, %r10d
orl %r11d, %r10d
decl %r10d
xorl %r11d, %r11d
movl %r10d, %edx
subl %eax, %edx
jae 0x13c2f
movl %r10d, %edx
jmp 0x13c55
movl (%rdi,%r14,4), %r11d
negb %al
movl %eax, %ecx
shll %cl, %r11d
shrl %cl, %r11d
movl %edx, %ecx
shll %cl, %r11d
incl %r8d
movl %r8d, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %eax
testl %edx, %edx
je 0x13c7a
subl %edx, %eax
movl %eax, 0x44(%rbx)
movl %r8d, %ecx
movl (%rdi,%rcx,4), %r14d
movl %eax, %ecx
shrl %cl, %r14d
negb %dl
movl %edx, %ecx
shll %cl, %r14d
shrl %cl, %r14d
orl %r11d, %r14d
movl %r14d, %r11d
btsl %r10d, %r11d
addl %r11d, %r9d
decl %r9d
movl %r9d, 0x18(%rbx)
addl %r11d, %esi
movl %esi, 0x14(%rbx)
cmpl %ebp, %esi
jb 0x13a93
subl %ebp, %esi
jbe 0x13ca3
movl %esi, 0x1c(%rbx)
movl %ebp, 0x14(%rbx)
subl %esi, 0x18(%rbx)
addq $0x18, %rbx
movq %rbx, %rax
movl (%rax), %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop