// File: adamnovak[P]rlcsa/sasamples.cpp
// Function: CSA::SASamples::SASamples(_IO_FILE*, unsigned int, bool)
SASamples::SASamples(FILE* sample_file, usint sample_rate, bool _weighted) :
  weighted(_weighted)
{
  if(sample_file == 0) { return; }

  if(this->weighted)
  {
    this->rate = 1;
    if(!std::fread(&(this->size), sizeof(this->size), 1, sample_file)) { return; }
    if(!std::fread(&(this->items), sizeof(this->items), 1, sample_file)) { return; }

    pair_type* sample_pairs = new pair_type[this->items];
    if(!std::fread(sample_pairs, this->items * sizeof(pair_type), 1, sample_file)) { return; }
    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)
cmpq $0x0, -0x10(%rbp)
jne 0x13579
jmp 0x137e6
movq -0x38(%rbp), %rax
testb $0x1, (%rax)
je 0x136ec
movq -0x38(%rbp), %rdi
movl $0x1, 0x4(%rdi)
addq $0x8, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x3460
cmpq $0x0, %rax
jne 0x135b3
jmp 0x137e6
movq -0x38(%rbp), %rdi
addq $0xc, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x3460
cmpq $0x0, %rax
jne 0x135d9
jmp 0x137e6
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 0x13658
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 0x13643
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rax
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x58(%rbp)
jne 0x13634
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl 0xc(%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
movq -0x10(%rbp), %rcx
movl $0x1, %edx
callq 0x3460
cmpq $0x0, %rax
jne 0x136a8
jmp 0x137e6
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 0x137ef
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 0x136e7
movq -0x70(%rbp), %rdi
callq 0x33e0
jmp 0x137e6
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 0x1fff0
jmp 0x13715
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 0x1377a
movl -0x7c(%rbp), %ecx
movl -0x80(%rbp), %edx
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x1e060
jmp 0x13795
movq -0x38(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, 0x18(%rdi)
callq 0x13450
jmp 0x137e6
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x48, %esi
callq 0x32d0
jmp 0x137ef
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x32d0
jmp 0x137ef
addq $0x90, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x3530
nopl (%rax,%rax)