// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/sampler.cpp
// Function: CSA::WeightedSampler::calculateEdges(unsigned int*)
void
WeightedSampler::calculateEdges(weight_type* weights)
{
  // Build nodes only for text positions with a positive weight.
  this->nodes = 2;
  for(uint i = 1; i < this->size; i++) { if(weights[i] > 0) { this->nodes++; } }
  this->node_positions = new uint[this->nodes];
  this->node_positions[0] = 0; this->node_positions[this->nodes - 1] = this->size;

  this->edge_totals  = new sum_type[this->nodes];
  this->edge_totals[0] = (this->use_psi ? 0 : weights[0]);
  for(uint i = 1, j = 1; i < this->size; i++)
  {
    if(weights[i] > 0) { this->edge_totals[j] = weights[i]; this->node_positions[j] = i; j++; }
  }
  this->edge_totals[this->nodes - 1] = 0;
  delete[] weights;
  this->edge_weights = new sum_type[this->nodes];


  if(this->use_psi)
  {
    this->edge_weights[0] = 0;
    for(uint i = 1; i < this->nodes; i++)
    {
      this->edge_weights[i] = this->edge_weights[i - 1] + this->getDistance(i - 1, i) * this->edge_totals[i - 1];
      this->edge_totals[i] += this->edge_totals[i - 1];
    }
  }
  else
  {
    this->edge_weights[this->nodes - 1] = 0;
    for(uint i = this->nodes - 1; i > 0; i--)
    {
      this->edge_weights[i - 1] = this->edge_weights[i] + this->getDistance(i - 1, i) * this->edge_totals[i];
      this->edge_totals[i - 1] += this->edge_totals[i];
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x2, 0x48(%rdi)
movl 0x8(%rdi), %ebp
movl $0x2, %r13d
cmpq $0x2, %rbp
jb 0xd382
movl $0x2, %r13d
movl $0x1, %eax
cmpl $0x0, (%r14,%rax,4)
je 0xd37a
incl %r13d
movl %r13d, 0x48(%rbx)
incq %rax
cmpq %rax, %rbp
jne 0xd36c
movl %r13d, %r12d
shlq $0x2, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %r15
movq %rax, 0x50(%rbx)
movl $0x0, (%rax)
leal -0x1(%r13), %eax
movq %rax, (%rsp)
movl %ebp, (%r15,%rax,4)
movq %r12, %rdi
callq 0x3030
movq %rax, 0x40(%rbx)
movb 0x1c(%rbx), %sil
xorl %ecx, %ecx
movl %esi, %edx
testb %sil, %sil
jne 0xd3c6
movl (%r14), %ecx
movl %ecx, (%rax)
cmpl $0x2, %ebp
jb 0xd3ff
movl $0x1, %ecx
movl $0x1, %edx
movl (%r14,%rdx,4), %esi
testl %esi, %esi
je 0xd3ea
movl %ecx, %edi
movl %esi, (%rax,%rdi,4)
movl %edx, (%r15,%rdi,4)
incl %ecx
incq %rdx
cmpq %rdx, %rbp
jne 0xd3d7
movq (%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0xd411
movq (%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
testq %r14, %r14
movl %edx, %ebp
je 0xd428
movq %r14, %rdi
callq 0x3300
movl 0x48(%rbx), %r13d
movb 0x1c(%rbx), %bpl
movq %r13, %r12
shlq $0x2, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, 0x38(%rbx)
testb $0x1, %bpl
je 0xd487
movl $0x0, (%rax)
cmpl $0x2, %r13d
jb 0xd4d5
movq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rdx
movl (%rcx), %edi
movl $0x1, %esi
movl (%rdx,%rsi,4), %r8d
subl -0x4(%rdx,%rsi,4), %r8d
imull %edi, %r8d
addl -0x4(%rax,%rsi,4), %r8d
movl %r8d, (%rax,%rsi,4)
movl (%rcx,%rsi,4), %edi
addl -0x4(%rcx,%rsi,4), %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
movl 0x48(%rbx), %r8d
cmpq %r8, %rsi
jb 0xd459
jmp 0xd4d5
decl %r13d
movl $0x0, (%rax,%r13,4)
je 0xd4d5
movq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rdx
decq %r13
movq %r13, %rsi
movl 0x4(%rdx,%r13,4), %edi
movl %r13d, %r8d
shlq $0x2, %r8
subl (%rdx,%r8), %edi
imull 0x4(%rcx,%r13,4), %edi
addl 0x4(%rax,%r13,4), %edi
movl %edi, (%rax,%r8)
movl 0x4(%rcx,%r13,4), %edi
addl %edi, (%rcx,%r8)
decq %rsi
testl %r13d, %r13d
movq %rsi, %r13
jne 0xd4a2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq