// File: /workspace/github_cpp_makefile_star2_O1/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 0x1a19d
movq %r14, %rdi
callq 0x16c96
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 0x16d92
movq 0x28(%rbx), %rsi
movl 0xc(%rsi), %eax
movl %eax, %edi
shrl $0x5, %edi
movl %edi, 0x18(%rsi)
movl %eax, %ecx
andl $0x1f, %ecx
movl $0x20, %r8d
subl %ecx, %r8d
movl %r8d, 0x1c(%rsi)
movl $0x2, 0x20(%rsi)
movl %eax, %edx
subl %r8d, %edx
jb 0x1a21f
movq (%rsi), %rax
movl (%rax,%rdi,4), %ebp
shll %cl, %ebp
shrl %cl, %ebp
movl %edx, %ecx
shll %cl, %ebp
incl %edi
movl %edi, 0x18(%rsi)
movl $0x20, 0x1c(%rsi)
movl %edx, %eax
testl %eax, %eax
je 0x1a240
movl 0x1c(%rsi), %ecx
subl %eax, %ecx
movl %ecx, 0x1c(%rsi)
movq (%rsi), %rdx
movl 0x18(%rsi), %edi
movl (%rdx,%rdi,4), %edx
shrl %cl, %edx
negb %al
movl %eax, %ecx
shll %cl, %edx
shrl %cl, %edx
orl %edx, %ebp
cmpl $0x0, 0x4(%rbx)
je 0x1a33e
xorl %edi, %edi
movq 0x8(%rsp), %r8
xorl %r9d, %r9d
cmpl %edi, %ebp
ja 0x1a2d2
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 0x1a278
movl %r10d, %edx
jmp 0x1a2a2
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 0x1a2c8
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 0x1a266
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x1a308
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 %eax, %ecx
testl %ecx, %ecx
je 0x1a32e
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %eax
subl %ecx, %eax
negb %cl
movl %r9d, %r10d
shll %cl, %r10d
shrl %cl, %r10d
movl %eax, %ecx
shll %cl, %r10d
movl %eax, 0x24(%rsp)
orl %r10d, (%r8,%rdx,4)
incl 0x28(%rsp)
addl 0x40(%rbx), %edi
cmpl 0x4(%rbx), %edi
jb 0x1a254
movl 0x14(%rbx), %esi
decl %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x1a379
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 %eax, %ecx
testl %ecx, %ecx
je 0x1a39d
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
negb %cl
shll %cl, %esi
shrl %cl, %esi
movl %eax, %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 0x16e56
movq %rax, 0x38(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x16e42
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x16e42
movq %rbx, %rdi
callq 0x3460