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

  usint index_samples = (this->number_of_blocks + BitVector::INDEX_RATE - 1) / BitVector::INDEX_RATE;
  this->select_rate = (this->items + index_samples - 1) / index_samples;
  index_samples = (this->items + this->select_rate - 1) / this->select_rate + 1;
  WriteBuffer index_buffer(index_samples, length(this->number_of_blocks - 1));

  // current is index, pointer is sample number.
  usint current = 0, pointer = 0;
  this->samples->goToItem(2);
  while(this->samples->hasNextItem())
  {
    usint limit = this->samples->readItem();  // Next sampled index.
    this->samples->skipItem();
    while(current < limit)
    {
      index_buffer.writeItem(pointer);
      current += this->select_rate;
    }
    pointer++;
  }
  index_buffer.writeItem(this->number_of_blocks - 1);

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

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x11952
movq %r14, %rdi
callq 0x112b6
movl $0x28, %esi
movq %r14, %rdi
callq 0x3270
movl 0x4(%rbx), %esi
movl 0x14(%rbx), %edi
leal 0x4(%rdi), %eax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rax, %rcx
shrq $0x22, %rcx
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
decl %edi
bsrl %edi, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %edi, %edi
cmovel %edi, %edx
leaq 0x8(%rsp), %rdi
callq 0x113b2
movq 0x18(%rbx), %rsi
movl 0xc(%rsi), %eax
movl 0x10(%rsi), %r9d
addl %eax, %eax
movl %eax, %ecx
shrl $0x5, %ecx
movl %ecx, 0x18(%rsi)
andl $0x1e, %eax
movl $0x20, %ecx
subl %eax, %ecx
movl %ecx, 0x1c(%rsi)
movl $0x2, 0x20(%rsi)
cmpl $0x3, %r9d
jb 0x11b11
movl $0x2, %r10d
xorl %edi, %edi
leal 0x1(%r10), %eax
movl %eax, 0x20(%rsi)
movl 0xc(%rsi), %r11d
movl 0x1c(%rsi), %eax
xorl %r8d, %r8d
movl %r11d, %edx
subl %eax, %edx
jae 0x11a03
movl %r11d, %edx
jmp 0x11a30
movq (%rsi), %rcx
movl 0x18(%rsi), %r14d
movl (%rcx,%r14,4), %r8d
negb %al
movl %eax, %ecx
shll %cl, %r8d
shrl %cl, %r8d
movl %edx, %ecx
shll %cl, %r8d
leal 0x1(%r14), %eax
movl %eax, 0x18(%rsi)
movl $0x20, 0x1c(%rsi)
movl $0x20, %eax
testl %edx, %edx
je 0x11a56
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, %r8d
movl %eax, %ecx
subl %r11d, %ecx
ja 0x11a7c
subl %eax, %r11d
movl %r11d, %eax
shrl $0x5, %eax
movl 0x18(%rsi), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x18(%rsi)
andl $0x1f, %r11d
movl $0x20, %ecx
subl %r11d, %ecx
movl %ecx, 0x1c(%rsi)
addl $0x2, %r10d
movl %r10d, 0x20(%rsi)
cmpl %r8d, %ebp
jae 0x11b06
movq 0x8(%rsp), %r9
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0x11aa3
movl %ecx, %eax
jmp 0x11ace
movl %edi, %r10d
movl %eax, %ecx
shrl %cl, %r10d
negb %dl
movl %edx, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl 0x20(%rsp), %ecx
orl %r10d, (%r9,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %edx
testl %eax, %eax
je 0x11af2
subl %eax, %edx
movl %edx, 0x24(%rsp)
negb %al
movl %edi, %r10d
movl %eax, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl %edx, %ecx
shll %cl, %r10d
movl 0x20(%rsp), %eax
orl %r10d, (%r9,%rax,4)
incl 0x28(%rsp)
addl 0x40(%rbx), %ebp
cmpl %r8d, %ebp
jb 0x11a91
movl 0x10(%rsi), %r9d
movl 0x20(%rsi), %r10d
incl %edi
cmpl %r9d, %r10d
jb 0x119e6
movl 0x14(%rbx), %esi
decl %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0x11b28
movl %ecx, %eax
jmp 0x11b53
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 0x11b75
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 0x11476
movq %rax, 0x38(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11462
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11462
movq %rbx, %rdi
callq 0x3460