// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %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, %rbx
movq %rax, 0x10(%r15)
movl $0x28, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
movl %ebp, %edx
callq 0x10f0c
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
movq %rsp, %rdi
callq 0x11092
leaq 0x18(%r14), %rbp
movq 0x18(%r14), %rbx
xorl %r13d, %r13d
cmpq %rbp, %rbx
je 0x10066
movq %r15, 0x30(%rsp)
movl 0xc(%r14), %r12d
movl 0x38(%r14), %r15d
imull 0x8(%r14), %r15d
movq 0x28(%rsp), %rcx
movl %r13d, %eax
leaq (%rcx,%rax,4), %rdi
movq 0x10(%rbx), %rsi
movq %r12, %rdx
callq 0x31f0
movq 0x28(%rsp), %rcx
movq (%rbx), %rbx
addl %r15d, %r13d
cmpq %rbp, %rbx
jne 0x10039
movl %r13d, %r13d
movq 0x30(%rsp), %r15
jmp 0x1006b
movq 0x28(%rsp), %rcx
leaq (%rcx,%r13,4), %rdi
movq 0x30(%r14), %rsi
movl 0x8(%r14), %edx
imull 0x3c(%r14), %edx
shlq $0x2, %rdx
callq 0x31f0
leaq 0x40(%r14), %rsi
movq 0x40(%r14), %rdi
cmpq %rsi, %rdi
je 0x1011a
cmpl $0x0, 0x60(%r14)
je 0x10112
movq 0x10(%rdi), %r8
movq (%rsp), %r9
xorl %r10d, %r10d
movl (%r8,%r10,4), %r11d
movl 0xc(%rsp), %ecx
movl 0x1c(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x100df
movl %r11d, %ebx
movl %eax, %ecx
shrl %cl, %ebx
negb %dl
movl %edx, %ecx
shll %cl, %ebx
shrl %cl, %ebx
movl 0x18(%rsp), %ecx
orl %ebx, (%r9,%rcx,4)
incl 0x18(%rsp)
movl $0x20, 0x1c(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0x10102
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
negb %cl
shll %cl, %r11d
shrl %cl, %r11d
movl %eax, %ecx
shll %cl, %r11d
movl %eax, 0x1c(%rsp)
orl %r11d, (%r9,%rdx,4)
incl 0x20(%rsp)
incq %r10
movl 0x60(%r14), %eax
cmpq %rax, %r10
jb 0x100a8
movq (%rdi), %rdi
jmp 0x1008d
cmpl $0x0, 0x64(%r14)
je 0x10199
movq 0x58(%r14), %rsi
movq (%rsp), %rdi
xorl %r8d, %r8d
movl (%rsi,%r8,4), %r9d
movl 0xc(%rsp), %ecx
movl 0x1c(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x10166
movl %r9d, %r10d
movl %eax, %ecx
shrl %cl, %r10d
negb %dl
movl %edx, %ecx
shll %cl, %r10d
shrl %cl, %r10d
movl 0x18(%rsp), %ecx
orl %r10d, (%rdi,%rcx,4)
incl 0x18(%rsp)
movl $0x20, 0x1c(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0x10189
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
negb %cl
shll %cl, %r9d
shrl %cl, %r9d
movl %eax, %ecx
shll %cl, %r9d
movl %eax, 0x1c(%rsp)
orl %r9d, (%rdi,%rdx,4)
incl 0x20(%rsp)
incq %r8
movl 0x64(%r14), %eax
cmpq %rax, %r8
jb 0x1012c
movl (%r15), %esi
movl 0xc(%rsp), %ecx
movl 0x1c(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x101d1
movl %esi, %edi
movl %eax, %ecx
shrl %cl, %edi
negb %dl
movl %edx, %ecx
shll %cl, %edi
shrl %cl, %edi
movq (%rsp), %rcx
movl 0x18(%rsp), %edx
orl %edi, (%rcx,%rdx,4)
incl 0x18(%rsp)
movl $0x20, 0x1c(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0x101f4
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x1c(%rsp)
negb %cl
shll %cl, %esi
shrl %cl, %esi
movl %eax, %ecx
shll %cl, %esi
movq (%rsp), %rax
movl 0x18(%rsp), %ecx
orl %esi, (%rax,%rcx,4)
movq %rsp, %rdi
incl 0x20(%rdi)
callq 0x11156
movq %rax, 0x28(%r15)
movq %r15, %rdi
callq 0xfc34
movq %rsp, %rdi
callq 0x11142
addq $0x38, %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 0x1023f
movq %rax, %rbx
movq %rsp, %rdi
callq 0x11142
movq %rbx, %rdi
callq 0x3460
nop