// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
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(%r15)
movq $0x0, 0x38(%r15)
imull %ebp, %edi
shlq $0x2, %rdi
callq 0x3030
movq %rax, %r13
movq %rax, 0x10(%r15)
movl $0x28, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x11230
movq %r12, 0x8(%r15)
movl (%r15), %eax
bsrl %eax, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %eax, %eax
cmovel %eax, %edx
movl %edx, 0x30(%r15)
movl 0x20(%r15), %esi
incl %esi
leaq 0x8(%rsp), %rdi
callq 0x113b2
leaq 0x18(%r14), %rbx
movq 0x18(%r14), %r12
xorl %ebp, %ebp
movl 0x8(%r14), %edx
cmpq %rbx, %r12
je 0x1033a
movq %r15, 0x40(%rsp)
movq %r13, 0x30(%rsp)
movl 0xc(%r14), %r13d
movl 0x38(%r14), %r15d
movq %rdx, 0x38(%rsp)
imull %edx, %r15d
movl %ebp, %eax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movq 0x10(%r12), %rsi
movq %r13, %rdx
callq 0x31f0
movq (%r12), %r12
addl %r15d, %ebp
cmpq %rbx, %r12
jne 0x10305
movl %ebp, %ebp
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %r13
movq 0x38(%rsp), %rdx
leaq (,%rbp,4), %rdi
addq %r13, %rdi
movq 0x30(%r14), %rsi
imull 0x3c(%r14), %edx
shlq $0x2, %rdx
callq 0x31f0
leaq 0x40(%r14), %rsi
movq 0x40(%r14), %rdi
cmpq %rsi, %rdi
je 0x103fc
movl 0x60(%r14), %eax
testl %eax, %eax
movl $0x0, %eax
je 0x103f0
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 0x10397
movl %ecx, %eax
jmp 0x103bf
movl %r11d, %ebx
movl %eax, %ecx
shrl %cl, %ebx
negb %dl
movl %edx, %ecx
shll %cl, %ebx
shrl %cl, %ebx
movl 0x20(%rsp), %ecx
orl %ebx, (%r9,%rcx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl $0x20, %edx
testl %eax, %eax
je 0x103e0
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 0x60(%r14), %eax
cmpq %rax, %r10
jb 0x10381
movq (%rdi), %rdi
cmpq %rsi, %rdi
jne 0x1036c
cmpl $0x0, 0x64(%r14)
je 0x10481
movq 0x58(%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 0x10425
movl %ecx, %eax
jmp 0x10450
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 0x10471
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 0x64(%r14), %eax
cmpq %rax, %r8
jb 0x1040f
movl (%r15), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0x10496
movl %ecx, %eax
jmp 0x104c1
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 0x104e3
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, 0x28(%r15)
movq %r15, %rdi
callq 0xfee0
leaq 0x8(%rsp), %rdi
callq 0x11462
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x28, %esi
movq %r12, %rdi
callq 0x3270
jmp 0x10534
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11462
movq %rbx, %rdi
callq 0x3460