// File: /workspace/github_cpp_makefile_star2_O2/adamnovak[P]rlcsa/bits/array.cpp
// Function: CSA::Array::Array(CSA::ArrayEncoder&)
Array::Array(Encoder& encoder) :
  items(encoder.items),
  delete_array(true),
  block_size(encoder.block_size),
  number_of_blocks(encoder.blocks),
  item_index(0)
{
  usint* array_buffer = new usint[this->block_size * this->number_of_blocks];
  this->array = array_buffer;
  this->buffer = new ReadBuffer(this->array, this->block_size);

  this->integer_bits = length(this->items);
  WriteBuffer sample_buffer(this->number_of_blocks + 1, this->integer_bits);

  // Copy & linearize the array.
  usint pos = 0;
  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.block_size * encoder.blocks_in_superblock;
  }
  memcpy(array_buffer + pos, encoder.array, encoder.current_blocks * encoder.block_size * sizeof(usint));

  // 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 < encoder.samples_in_superblock; i++)
    {
      sample_buffer.writeItem(buf[i]);
    }
  }
  for(usint i = 0; i < encoder.current_samples; i++)
  {
    sample_buffer.writeItem(encoder.samples[i]);
  }
  sample_buffer.writeItem(this->items);

  this->samples = sample_buffer.getReadBuffer();

  this->buildIndex();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl (%rsi), %eax
movl %eax, (%rdi)
movb $0x1, 0x18(%rdi)
movl 0x8(%rsi), %ebp
movl %ebp, 0x1c(%rdi)
movl 0x4(%rsi), %edi
movl %edi, 0x20(%rbx)
andq $0x0, 0x38(%rbx)
imull %ebp, %edi
shlq $0x2, %rdi
callq 0x3030
movq %rax, %r15
movq %rax, 0x10(%rbx)
pushq $0x28
popq %rdi
callq 0x3220
movq %rax, %r12
movq %rax, %rdi
movq %r15, 0x18(%rsp)
movq %r15, %rsi
movl %ebp, %edx
callq 0xe746
movq %r12, 0x8(%rbx)
movl (%rbx), %edi
callq 0xab34
movl %eax, 0x30(%rbx)
movq %rbx, 0x8(%rsp)
movl 0x20(%rbx), %esi
incl %esi
leaq 0x20(%rsp), %rdi
movl %eax, %edx
callq 0xe8b6
leaq 0x18(%r14), %r15
movl 0x8(%r14), %eax
movl 0xc(%r14), %r13d
movl 0x38(%r14), %ebx
movq %rax, 0x10(%rsp)
imull %eax, %ebx
xorl %r12d, %r12d
movq %r15, %rbp
movq (%rbp), %rbp
movl %r12d, %eax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
cmpq %r15, %rbp
je 0xdcd9
movq 0x10(%rbp), %rsi
movq %r13, %rdx
callq 0x31c0
addl %ebx, %r12d
jmp 0xdcb3
movq 0x30(%r14), %rsi
movq 0x10(%rsp), %rdx
imull 0x3c(%r14), %edx
shlq $0x2, %rdx
callq 0x31c0
leaq 0x40(%r14), %r12
leaq 0x20(%rsp), %r15
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0xdd24
movq 0x10(%r13), %rbx
xorl %ebp, %ebp
movl 0x60(%r14), %eax
cmpq %rax, %rbp
jae 0xdcfc
movl (%rbx,%rbp,4), %esi
movq %r15, %rdi
callq 0xab42
incq %rbp
jmp 0xdd0b
xorl %ebx, %ebx
leaq 0x20(%rsp), %r15
movl 0x64(%r14), %eax
cmpq %rax, %rbx
jae 0xdd48
movq 0x58(%r14), %rax
movl (%rax,%rbx,4), %esi
movq %r15, %rdi
callq 0xab42
incq %rbx
jmp 0xdd2b
movq 0x8(%rsp), %rbx
movl (%rbx), %esi
leaq 0x20(%rsp), %rdi
callq 0xab42
leaq 0x20(%rsp), %rdi
callq 0xe972
movq %rax, 0x28(%rbx)
movq %rbx, %rdi
callq 0xd9ea
leaq 0x20(%rsp), %rdi
callq 0xe95e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r12, %rdi
callq 0x3230
jmp 0xdda9
jmp 0xdd9c
jmp 0xdd9c
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xe95e
movq %rbx, %rdi
callq 0x3410
nop