// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/bits/succinctvector.cpp
// Function: CSA::SuccinctVector::indexForSelect()
void
SuccinctVector::indexForSelect()
{
  delete this->select_index; this->select_index = 0;

  this->select_rate = (this->items + this->number_of_blocks - 1) / this->number_of_blocks;
  usint index_samples = (this->items + this->select_rate - 1) / this->select_rate + 1;
  WriteBuffer buffer(index_samples, this->integer_bits);

  // pointer is the largest block number such that rank_index[pointer] <= current.
  usint pointer = 0;
  usint next_rank = this->rank_index->readItem(1);
  for(usint current = 0; current < this->items; current += this->select_rate)
  {
    while(next_rank <= current)
    {
      pointer++; next_rank = this->rank_index->readItem();
    }
    buffer.writeItem(pointer);
  }
  buffer.writeItem(this->number_of_blocks - 1);

  this->select_index = buffer.getReadBuffer();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x1a692
movq %r14, %rdi
callq 0x16f06
movl $0x28, %esi
movq %r14, %rdi
callq 0x3270
movq $0x0, 0x38(%rbx)
movl 0x4(%rbx), %esi
movl 0x14(%rbx), %ecx
leal (%rsi,%rcx), %eax
decl %eax
xorl %ebp, %ebp
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl %eax, 0x40(%rbx)
leal (%rsi,%rcx), %eax
decl %eax
xorl %edx, %edx
divl %ecx
leal 0x1(%rax), %esi
movl 0x20(%rbx), %edx
leaq 0x8(%rsp), %rdi
callq 0x17002
movq 0x28(%rbx), %rsi
movl 0xc(%rsi), %r8d
movl %r8d, %edi
shrl $0x5, %edi
movl %edi, 0x18(%rsi)
movl %r8d, %ecx
andl $0x1f, %ecx
movl $0x20, %edx
movl $0x20, %r9d
subl %ecx, %r9d
movl %r9d, 0x1c(%rsi)
movl $0x2, 0x20(%rsi)
movl %r8d, %eax
subl %r9d, %eax
jae 0x1a716
movl %r9d, %edx
movl %r8d, %eax
jmp 0x1a731
movq (%rsi), %r8
movl (%r8,%rdi,4), %ebp
shll %cl, %ebp
shrl %cl, %ebp
movl %eax, %ecx
shll %cl, %ebp
incl %edi
movl %edi, 0x18(%rsi)
movl $0x20, 0x1c(%rsi)
testl %eax, %eax
je 0x1a750
subl %eax, %edx
movl %edx, 0x1c(%rsi)
movq (%rsi), %rcx
movl %edi, %edi
movl (%rcx,%rdi,4), %edi
movl %edx, %ecx
shrl %cl, %edi
negb %al
movl %eax, %ecx
shll %cl, %edi
shrl %cl, %edi
orl %edi, %ebp
cmpl $0x0, 0x4(%rbx)
je 0x1a853
xorl %edi, %edi
movq 0x8(%rsp), %r8
xorl %r9d, %r9d
cmpl %edi, %ebp
ja 0x1a7e2
movl 0xc(%rsi), %r10d
movl 0x1c(%rsi), %eax
movl 0x20(%rsi), %r11d
incl %r11d
movl %r11d, 0x20(%rsi)
xorl %ebp, %ebp
movl %r10d, %edx
subl %eax, %edx
jae 0x1a788
movl %r10d, %edx
jmp 0x1a7b2
movq (%rsi), %rcx
movl 0x18(%rsi), %r14d
movl (%rcx,%r14,4), %ebp
negb %al
movl %eax, %ecx
shll %cl, %ebp
shrl %cl, %ebp
movl %edx, %ecx
shll %cl, %ebp
leal 0x1(%r14), %eax
movl %eax, 0x18(%rsi)
movl $0x20, 0x1c(%rsi)
movl $0x20, %eax
testl %edx, %edx
je 0x1a7d8
subl %edx, %eax
movl %eax, 0x1c(%rsi)
movq (%rsi), %rcx
movl 0x18(%rsi), %r14d
movl (%rcx,%r14,4), %r14d
movl %eax, %ecx
shrl %cl, %r14d
negb %dl
movl %edx, %ecx
shll %cl, %r14d
shrl %cl, %r14d
orl %r14d, %ebp
incl %r9d
incl %r11d
cmpl %edi, %ebp
jbe 0x1a776
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0x1a7f4
movl %ecx, %eax
jmp 0x1a81f
movl %r9d, %r10d
movl %eax, %ecx
shrl %cl, %r10d
negb %dl
movl %edx, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl 0x20(%rsp), %ecx
orl %r10d, (%r8,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %edx
testl %eax, %eax
je 0x1a843
subl %eax, %edx
movl %edx, 0x24(%rsp)
negb %al
movl %r9d, %r10d
movl %eax, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl %edx, %ecx
shll %cl, %r10d
movl 0x20(%rsp), %eax
orl %r10d, (%r8,%rax,4)
incl 0x28(%rsp)
addl 0x40(%rbx), %edi
cmpl 0x4(%rbx), %edi
jb 0x1a764
movl 0x14(%rbx), %esi
decl %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0x1a86a
movl %ecx, %eax
jmp 0x1a895
movl %esi, %edi
movl %eax, %ecx
shrl %cl, %edi
negb %dl
movl %edx, %ecx
shll %cl, %edi
shrl %cl, %edi
movq 0x8(%rsp), %rcx
movl 0x20(%rsp), %edx
orl %edi, (%rcx,%rdx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %edx
testl %eax, %eax
je 0x1a8b7
subl %eax, %edx
movl %edx, 0x24(%rsp)
negb %al
movl %eax, %ecx
shll %cl, %esi
shrl %cl, %esi
movl %edx, %ecx
shll %cl, %esi
movq 0x8(%rsp), %rax
movl 0x20(%rsp), %ecx
orl %esi, (%rax,%rcx,4)
leaq 0x8(%rsp), %rdi
incl 0x20(%rdi)
callq 0x170c6
movq %rax, 0x38(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x170b2
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x170b2
movq %rbx, %rdi
callq 0x3460