// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/bits/bitvector.cpp
// Function: CSA::BitVector::BitVector(CSA::VectorEncoder&, unsigned int)
BitVector::BitVector(VectorEncoder& encoder, usint universe_size) :
  size(universe_size), items(encoder.items),
  block_size(encoder.block_size),
  number_of_blocks(encoder.blocks),
  rank_index(0), select_index(0)
{
  if(this->items == 0)
  {
    std::cerr << "BitVector: Cannot create a bit vector with no 1-bits!" << std::endl;
    return;
  }
  this->copyArray(encoder);

  this->integer_bits = length(this->size);
  WriteBuffer sample_buffer(2 * (this->number_of_blocks + 1), this->integer_bits);

  // Compress the samples.
  for(std::list<usint*>::iterator iter = encoder.sample_blocks.begin(); iter != encoder.sample_blocks.end(); iter++)
  {
    usint* buf = *iter;
    for(usint i = 0; i < 2 * encoder.samples_in_superblock; i++)
    {
      sample_buffer.writeItem(buf[i]);
    }
  }
  for(usint i = 0; i < 2 * encoder.current_samples; i++)
  {
    sample_buffer.writeItem(encoder.samples[i]);
  }
  sample_buffer.writeItem(this->items);
  sample_buffer.writeItem(this->size);

  this->samples = sample_buffer.getReadBuffer();

  this->indexForRank();
  this->indexForSelect();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movl %edx, (%rdi)
movl 0x4(%rsi), %eax
movl %eax, 0x4(%rdi)
movl 0xc(%rsi), %ecx
movl %ecx, 0x10(%rdi)
movl 0x8(%rsi), %ecx
movl %ecx, 0x14(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x28(%rdi)
movq %rcx, 0x38(%rdi)
testl %eax, %eax
je 0x11c45
movq %rsi, %r14
movq %rdi, %rbx
xorl %edx, %edx
callq 0x11ca4
movl (%rbx), %eax
bsrl %eax, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %eax, %eax
cmovel %eax, %edx
movl %edx, 0x20(%rbx)
movl 0x14(%rbx), %eax
leal 0x2(,%rax,2), %esi
leaq 0x8(%rsp), %rdi
callq 0x11092
leaq 0x48(%r14), %rsi
movq 0x48(%r14), %rdi
cmpq %rsi, %rdi
je 0x11acf
testl $0x7fffffff, 0x68(%r14) # imm = 0x7FFFFFFF
je 0x11ac7
movq 0x10(%rdi), %r8
movq 0x8(%rsp), %r9
xorl %r10d, %r10d
movl (%r8,%r10,4), %r11d
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x11a92
movl %r11d, %ebp
movl %eax, %ecx
shrl %cl, %ebp
negb %dl
movl %edx, %ecx
shll %cl, %ebp
shrl %cl, %ebp
movl 0x20(%rsp), %ecx
orl %ebp, (%r9,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0x11ab5
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %eax
subl %ecx, %eax
negb %cl
shll %cl, %r11d
shrl %cl, %r11d
movl %eax, %ecx
shll %cl, %r11d
movl %eax, 0x24(%rsp)
orl %r11d, (%r9,%rdx,4)
incl 0x28(%rsp)
incq %r10
movl 0x68(%r14), %eax
addl %eax, %eax
cmpq %rax, %r10
jb 0x11a5b
movq (%rdi), %rdi
jmp 0x11a3c
testl $0x7fffffff, 0x6c(%r14) # imm = 0x7FFFFFFF
je 0x11b54
movq 0x60(%r14), %rsi
movq 0x8(%rsp), %rdi
xorl %r8d, %r8d
movl (%rsi,%r8,4), %r9d
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x11b1f
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, (%rdi,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0x11b42
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %eax
subl %ecx, %eax
negb %cl
shll %cl, %r9d
shrl %cl, %r9d
movl %eax, %ecx
shll %cl, %r9d
movl %eax, 0x24(%rsp)
orl %r9d, (%rdi,%rdx,4)
incl 0x28(%rsp)
incq %r8
movl 0x6c(%r14), %eax
addl %eax, %eax
cmpq %rax, %r8
jb 0x11ae5
movl 0x4(%rbx), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x11b8d
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 0x11bb1
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)
incl 0x28(%rsp)
movl (%rbx), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x11bed
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 0x11c11
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 0x11156
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
callq 0x113aa
movq %rbx, %rdi
callq 0x115fe
leaq 0x8(%rsp), %rdi
callq 0x11142
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0xd3a4(%rip), %rbx      # 0x1eff0
leaq 0x5c2e(%rip), %rsi      # 0x17881
movl $0x35, %edx
movq %rbx, %rdi
callq 0x32b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x3190
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11142
movq %rbx, %rdi
callq 0x3460