// File: adamnovak[P]rlcsa/bits/bitvector.cpp
// Function: CSA::BitVector::copyArray(CSA::VectorEncoder&, bool)
void
BitVector::copyArray(VectorEncoder& encoder, bool use_directly)
{
  if(use_directly && encoder.array_blocks.size() == 0)
  {
    this->array = encoder.array; encoder.array = 0;
    return;
  }

  usint* array_buffer = new usint[this->block_size * this->number_of_blocks];
  usint pos = 0, total_words = this->block_size * this->number_of_blocks;

  for(std::list<usint*>::iterator iter = encoder.array_blocks.begin(); iter != encoder.array_blocks.end(); iter++)
  {
    memcpy(array_buffer + pos, *iter, encoder.superblock_bytes);
    pos += encoder.superblock_bytes / sizeof(usint);
  }

  usint remainder = std::min(total_words - pos, (usint)(encoder.superblock_bytes / sizeof(usint)));
  memcpy(array_buffer + pos, encoder.array, remainder * sizeof(usint));
  pos += remainder;
  if(pos < total_words) { memset(array_buffer + pos, 0, (total_words - pos) * sizeof(usint)); }

  this->array = array_buffer;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
testb $0x1, -0x11(%rbp)
je 0x1f229
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x1fec0
cmpq $0x0, %rax
jne 0x1f229
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x1f389
movq -0x58(%rbp), %rcx
movl 0x10(%rcx), %eax
imull 0x14(%rcx), %eax
movl %eax, %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq -0x58(%rbp), %rcx
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl 0x10(%rcx), %eax
imull 0x14(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x1d4e0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x1d540
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1d510
testb $0x1, %al
jne 0x1f2a5
jmp 0x1f2fc
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1d570
movq -0x60(%rbp), %rdi
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x3240
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
shrq $0x2, %rcx
movl -0x24(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x1d590
movq %rax, -0x40(%rbp)
jmp 0x1f281
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
shrq $0x2, %rax
movl %eax, -0x4c(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x63a0
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x44(%rbp), %eax
movl %eax, %edx
shlq $0x2, %rdx
callq 0x3240
movl -0x44(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x1f37d
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3190
movq -0x58(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
addq $0x60, %rsp
popq %rbp
retq
nop