// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/sasamples.cpp
// Function: CSA::SASamples::buildSamples(std::pair<unsigned int, unsigned int>*, bool, unsigned int)
void
SASamples::buildSamples(pair_type* sample_pairs, bool inverse, usint threads)
{
  if(inverse)
  {
    for(usint i = 0; i < this->items; i++)
    {
      std::swap(sample_pairs[i].first, sample_pairs[i].second);
    }
  }
  #ifdef MULTITHREAD_SUPPORT
  omp_set_num_threads(threads);
  #endif
  parallelSort(sample_pairs, sample_pairs + this->items);

  SAVector::Encoder encoder(INDEX_BLOCK_SIZE);
  WriteBuffer sample_buffer(this->items, length(this->size - 1));
  for(usint i = 0; i < this->items; i++)
  {
    encoder.setBit(sample_pairs[i].first);
    sample_buffer.writeItem(sample_pairs[i].second);
/*    if(sample_pairs[i].first >= this->size || sample_pairs[i].second >= this->size)
    {
      std::cout << "Sample " << i << ": " << sample_pairs[i] << std::endl;
    }*/
  }

  if(inverse)
  {
    this->inverse_indexes = new SAVector(encoder, this->size);
    this->inverse_samples = sample_buffer.getReadBuffer();
  }
  else
  {
    this->indexes = new SAVector(encoder, this->size);
    this->samples = sample_buffer.getReadBuffer();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
testl %edx, %edx
je 0xb06d
cmpl $0x0, 0xc(%rbx)
je 0xb06d
xorl %eax, %eax
rolq $0x20, (%r14,%rax,8)
incq %rax
movl 0xc(%rbx), %ecx
cmpq %rcx, %rax
jb 0xb05d
movl 0xc(%rbx), %eax
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0xc667
leaq 0x30(%rsp), %rdi
movl $0x10, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x13026
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %esi
decl %eax
bsrl %eax, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %eax, %eax
cmovel %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x11092
cmpl $0x0, 0xc(%rbx)
je 0xb13c
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movl (%r14,%r12,8), %esi
movq %r15, %rdi
callq 0x13036
movl 0x4(%r14,%r12,8), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0xb109
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 %eax, %ecx
testl %ecx, %ecx
je 0xb12d
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
negb %cl
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)
incl 0x28(%rsp)
incq %r12
movl 0xc(%rbx), %eax
cmpq %rax, %r12
jb 0xb0c2
testb %bpl, %bpl
je 0xb173
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
movl 0x8(%rbx), %edx
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x1272c
movq %r14, 0x20(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11156
movl $0x28, %ecx
jmp 0xb1a3
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
movl 0x8(%rbx), %edx
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x1272c
movq %r14, 0x10(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11156
movl $0x18, %ecx
movq %rax, (%rbx,%rcx)
leaq 0x8(%rsp), %rdi
callq 0x11142
leaq 0x30(%rsp), %rdi
callq 0x13030
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb1cd
movq %rax, %rbx
movl $0x48, %esi
movq %r14, %rdi
callq 0x3270
jmp 0xb1e9
movq %rax, %rbx
jmp 0xb1f3
jmp 0xb1e6
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11142
leaq 0x30(%rsp), %rdi
callq 0x13030
movq %rbx, %rdi
callq 0x3460
nop