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

  if(value >= par.size) { return pair_type(par.size, par.items); }

  this->getSample(this->sampleForValue(value));
  if(this->val > value) { return pair_type(par.size, par.items); }
  this->run = 0;

  while(this->cur < this->block_items && this->val < value)
  {
    usint temp = this->buffer.readDeltaCode(value - this->val);
    if(temp == 0) { break; }
    this->val += temp;

    temp = this->buffer.readDeltaCode();
    this->cur += temp;
    this->val += temp - 1;
  }
  if(this->val > value)
  {
    this->run = this->val - value;
    this->val = value;
    this->cur -= this->run;
  }

  return pair_type(this->val, this->sample.first + this->cur);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq (%rdi), %r14
movl (%r14), %eax
cmpl %esi, %eax
jbe 0x13b48
movl %esi, %ebp
movq %rdi, %rbx
callq 0x12226
movq %rbx, %rdi
movl %eax, %esi
callq 0x130d8
cmpl %ebp, 0x18(%rbx)
jbe 0x13b51
movl (%r14), %eax
movl 0x4(%r14), %ecx
jmp 0x13cb4
movl $0x0, 0x1c(%rbx)
leaq 0x28(%rbx), %r14
movl 0x14(%rbx), %eax
cmpl 0x20(%rbx), %eax
jae 0x13c9b
movl %ebp, %esi
subl 0x18(%rbx), %esi
jbe 0x13c9b
movq %r14, %rdi
callq 0x13268
testl %eax, %eax
je 0x13c9b
movl 0x18(%rbx), %edi
addl %eax, %edi
movl %edi, 0x18(%rbx)
movq 0x28(%rbx), %r8
movl 0x44(%rbx), %esi
movl 0x40(%rbx), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
decl %esi
movl %esi, 0x44(%rbx)
movl %ecx, %r9d
movl (%r8,%r9,4), %r9d
je 0x13bad
movl %esi, %r10d
jmp 0x13bbf
incl %ecx
movl %ecx, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl $0x20, %r10d
incl %edx
btl %esi, %r9d
movl %r10d, %esi
jae 0x13b9a
movl $0x1, %esi
movl %edx, %ecx
shll %cl, %esi
movl 0x44(%rbx), %ecx
xorl %r9d, %r9d
cmpl %edx, %ecx
ja 0x13c02
subl %ecx, %edx
movl 0x40(%rbx), %r10d
movl (%r8,%r10,4), %r9d
negb %cl
shll %cl, %r9d
shrl %cl, %r9d
movl %edx, %ecx
shll %cl, %r9d
leal 0x1(%r10), %ecx
movl %ecx, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
testl %edx, %edx
je 0x13c26
movl 0x40(%rbx), %r10d
movl 0x44(%rbx), %ecx
subl %edx, %ecx
movl %ecx, 0x44(%rbx)
movl (%r8,%r10,4), %r10d
shrl %cl, %r10d
negb %dl
movl %edx, %ecx
shll %cl, %r10d
shrl %cl, %r10d
orl %r10d, %r9d
orl %esi, %r9d
decl %r9d
movl 0x44(%rbx), %ecx
xorl %r10d, %r10d
movl %r9d, %esi
movl %r9d, %edx
subl %ecx, %esi
jb 0x13c5f
movl 0x40(%rbx), %edx
movl (%r8,%rdx,4), %r10d
negb %cl
shll %cl, %r10d
shrl %cl, %r10d
movl %esi, %ecx
shll %cl, %r10d
leal 0x1(%rdx), %ecx
movl %ecx, 0x40(%rbx)
movl $0x20, 0x44(%rbx)
movl %esi, %edx
testl %edx, %edx
je 0x13c82
movl 0x40(%rbx), %esi
movl 0x44(%rbx), %ecx
subl %edx, %ecx
movl %ecx, 0x44(%rbx)
movl (%r8,%rsi,4), %esi
shrl %cl, %esi
negb %dl
movl %edx, %ecx
shll %cl, %esi
shrl %cl, %esi
orl %r10d, %esi
movl %esi, %r10d
btsl %r9d, %r10d
addl %r10d, 0x14(%rbx)
leal (%rdi,%r10), %ecx
decl %ecx
movl %ecx, 0x18(%rbx)
testl %eax, %eax
jne 0x13b5c
movl 0x18(%rbx), %eax
subl %ebp, %eax
jbe 0x13cab
movl %eax, 0x1c(%rbx)
movl %ebp, 0x18(%rbx)
subl %eax, 0x14(%rbx)
movl 0x14(%rbx), %ecx
movl 0x18(%rbx), %eax
addl 0xc(%rbx), %ecx
shlq $0x20, %rcx
movl %eax, %eax
orq %rcx, %rax
popq %rbx
popq %r14
popq %rbp
retq