// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0xc(%rdi), %eax
testl %edx, %edx
je 0xb156
testl %eax, %eax
je 0xb154
xorl %ecx, %ecx
movq (%r14,%rcx,8), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, (%r14,%rcx,8)
incq %rcx
movl 0xc(%rbx), %eax
cmpq %rax, %rcx
jb 0xb136
jmp 0xb156
xorl %eax, %eax
movl %eax, %eax
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0xc79b
leaq 0x30(%rsp), %rdi
movl $0x10, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x134f2
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 0x113b2
cmpl $0x0, 0xc(%rbx)
je 0xb229
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movl (%r14,%r12,8), %esi
movq %r15, %rdi
callq 0x13502
movl 0x4(%r14,%r12,8), %esi
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jae 0xb1cd
movl %ecx, %eax
jmp 0xb1f8
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 0xb21a
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)
incl 0x28(%rsp)
incq %r12
movl 0xc(%rbx), %eax
cmpq %rax, %r12
jb 0xb1aa
testb %bpl, %bpl
je 0xb260
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
movl 0x8(%rbx), %edx
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x12aa8
movq %r14, 0x20(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11476
movl $0x28, %ecx
jmp 0xb290
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
movl 0x8(%rbx), %edx
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x12aa8
movq %r14, 0x10(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11476
movl $0x18, %ecx
movq %rax, (%rbx,%rcx)
leaq 0x8(%rsp), %rdi
callq 0x11462
leaq 0x30(%rsp), %rdi
callq 0x134fc
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb2ba
movq %rax, %rbx
movl $0x48, %esi
movq %r14, %rdi
callq 0x3270
jmp 0xb2d6
movq %rax, %rbx
jmp 0xb2e0
jmp 0xb2d3
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11462
leaq 0x30(%rsp), %rdi
callq 0x134fc
movq %rbx, %rdi
callq 0x3460