// File: adamnovak[P]rlcsa/sasamples.cpp
// Function: CSA::SASamples::SASamples(std::basic_ifstream<char, std::char_traits<char>>&, unsigned int, bool)
SASamples::SASamples(std::ifstream& sample_file, usint sample_rate, bool _weighted) :
  weighted(_weighted)
{
  if(this->weighted)
  {
    this->rate = 1;
    sample_file.read((char*)&(this->size), sizeof(this->size));
    sample_file.read((char*)&(this->items), sizeof(this->items));

    pair_type* sample_pairs = new pair_type[this->items];
    sample_file.read((char*)sample_pairs, this->items * sizeof(pair_type));
    this->buildSamples(sample_pairs, false, 1);
    this->buildSamples(sample_pairs, true, 1);
    delete[] sample_pairs;
  }
  else
  {
    this->rate = sample_rate;
    this->indexes = new SAVector(sample_file);
    this->size = indexes->getSize();
    this->items = indexes->getNumberOfItems();
    this->samples = new ReadBuffer(sample_file, this->items, length(this->items - 1));
    this->buildInverseSamples();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x15(%rbp), %cl
andb $0x1, %cl
movb %cl, (%rax)
testb $0x1, (%rax)
je 0x1304c
movq -0x38(%rbp), %rsi
movl $0x1, 0x4(%rsi)
movq -0x10(%rbp), %rdi
addq $0x8, %rsi
movl $0x4, %edx
callq 0x33c0
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rdi
addq $0xc, %rsi
movl $0x4, %edx
callq 0x33c0
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x48(%rbp)
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x50(%rbp)
callq 0x3030
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x40(%rbp)
cmpq $0x0, %rax
je 0x12fc8
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0xe530
jmp 0x12fb3
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rax
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x58(%rbp)
jne 0x12fa4
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl 0xc(%rax), %eax
movl %eax, %edx
shlq $0x3, %rdx
callq 0x33c0
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x13160
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x13160
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x13029
movq -0x70(%rbp), %rdi
callq 0x33e0
jmp 0x13146
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x3590
jmp 0x1314f
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl $0x48, %edi
callq 0x32c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rsi
callq 0x1ffc0
jmp 0x13075
movq -0x38(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rdi
callq 0xe860
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x10(%rax), %rdi
callq 0xd4a0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x28, %edi
callq 0x32c0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x90(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movl 0xc(%rax), %edi
movl %edi, -0x80(%rbp)
decl %edi
callq 0x14da0
movl %eax, -0x7c(%rbp)
jmp 0x130da
movl -0x7c(%rbp), %ecx
movl -0x80(%rbp), %edx
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x1dfa0
jmp 0x130f5
movq -0x38(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, 0x18(%rdi)
callq 0x13450
jmp 0x13146
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x48, %esi
callq 0x32d0
jmp 0x1314f
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x32d0
jmp 0x1314f
addq $0x90, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x3530
nopl (%rax,%rax)