// File: /workspace/github_cpp_makefile_star2_O3/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)
movq 0x8(%rsi), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x10(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x28(%rdi)
movq %rcx, 0x38(%rdi)
testl %eax, %eax
je 0x11ecc
movq %rsi, %r14
movq %rdi, %rbx
xorl %edx, %edx
callq 0x12012
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 0x113b2
leaq 0x48(%r14), %rsi
movq 0x48(%r14), %rdi
cmpq %rsi, %rdi
je 0x11e29
movl 0x68(%r14), %eax
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x11e1d
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
jae 0x11dc1
movl %ecx, %eax
jmp 0x11de9
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 $0x20, %edx
testl %eax, %eax
je 0x11e0a
subl %eax, %edx
movl %edx, 0x24(%rsp)
negb %al
movl %eax, %ecx
shll %cl, %r11d
shrl %cl, %r11d
movl %edx, %ecx
shll %cl, %r11d
movl 0x20(%rsp), %eax
orl %r11d, (%r9,%rax,4)
incl 0x28(%rsp)
incq %r10
movl 0x68(%r14), %eax
leal (%rax,%rax), %ecx
cmpq %rcx, %r10
jb 0x11dab
movq (%rdi), %rdi
cmpq %rsi, %rdi
jne 0x11d98
testl $0x7fffffff, 0x6c(%r14) # imm = 0x7FFFFFFF
je 0x11eb7
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
jae 0x11e59
movl %ecx, %eax
jmp 0x11e84
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 $0x20, %edx
testl %eax, %eax
je 0x11ea5
subl %eax, %edx
movl %edx, 0x24(%rsp)
negb %al
movl %eax, %ecx
shll %cl, %r9d
shrl %cl, %r9d
movl %edx, %ecx
shll %cl, %r9d
movl 0x20(%rsp), %eax
orl %r9d, (%rdi,%rax,4)
incl 0x28(%rsp)
incq %r8
movl 0x6c(%r14), %eax
addl %eax, %eax
cmpq %rax, %r8
jb 0x11e43
movl 0x4(%rbx), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %eax
movl %ecx, %edx
subl %eax, %edx
jae 0x11f16
movl %ecx, %edx
jmp 0x11f41
movq 0xe11d(%rip), %rbx      # 0x1fff0
leaq 0x69f4(%rip), %rsi      # 0x188ce
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
movl %esi, %edi
movl %edx, %ecx
shrl %cl, %edi
negb %al
movl %eax, %ecx
shll %cl, %edi
shrl %cl, %edi
movq 0x8(%rsp), %rax
movl 0x20(%rsp), %ecx
orl %edi, (%rax,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %eax
testl %edx, %edx
je 0x11f67
subl %edx, %eax
negb %dl
movl %edx, %ecx
shll %cl, %esi
shrl %cl, %esi
movl %eax, %ecx
shll %cl, %esi
movl %eax, 0x24(%rsp)
movq 0x8(%rsp), %rax
movl 0x20(%rsp), %ecx
orl %esi, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
incl 0x28(%rsp)
movl (%rbx), %esi
movl 0x14(%rsp), %ecx
movl %ecx, %edx
subl %eax, %edx
jae 0x11f7b
movl %ecx, %edx
jmp 0x11fa6
movl %esi, %edi
movl %edx, %ecx
shrl %cl, %edi
negb %al
movl %eax, %ecx
shll %cl, %edi
shrl %cl, %edi
movq 0x8(%rsp), %rax
movl 0x20(%rsp), %ecx
orl %edi, (%rax,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %eax
testl %edx, %edx
je 0x11fc8
subl %edx, %eax
movl %eax, 0x24(%rsp)
negb %dl
movl %edx, %ecx
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 0x11476
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
callq 0x116ca
movq %rbx, %rdi
callq 0x11936
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
nop