// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x2
popq %r13
pushq $0x1
popq %rax
cmpq %rbp, %rax
jae 0xb828
cmpl $0x0, (%r14,%rax,4)
je 0xb823
incl %r13d
movl %r13d, 0x48(%rbx)
incq %rax
jmp 0xb810
movl %r13d, %r15d
shlq $0x2, %r15
movq %r15, %rdi
callq 0x3030
movq %rax, %r12
movq %rax, 0x50(%rbx)
andl $0x0, (%rax)
leal -0x1(%r13), %eax
movq %rax, (%rsp)
movl %ebp, (%r12,%rax,4)
movq %r15, %rdi
callq 0x3030
movq %rax, 0x40(%rbx)
movb 0x1c(%rbx), %r8b
xorl %ecx, %ecx
testb %r8b, %r8b
jne 0xb867
movl (%r14), %ecx
movl %ecx, (%rax)
pushq $0x1
popq %rcx
pushq $0x1
popq %rdx
cmpq %rbp, %rdx
jae 0xb88c
movl (%r14,%rdx,4), %esi
testl %esi, %esi
je 0xb887
movl %ecx, %edi
movl %esi, (%rax,%rdi,4)
movl %edx, (%r12,%rdi,4)
incl %ecx
incq %rdx
jmp 0xb86f
movq (%rsp), %rcx
andl $0x0, (%rax,%rcx,4)
testq %r14, %r14
je 0xb8b0
movq %r14, %rdi
callq 0x32b0
movl 0x48(%rbx), %r13d
movb 0x1c(%rbx), %r8b
movq %r13, %r15
shlq $0x2, %r15
movq %r15, %rdi
movl %r8d, %ebp
callq 0x3030
movq %rax, 0x38(%rbx)
testb $0x1, %bpl
je 0xb8fe
andl $0x0, (%rax)
movq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rdx
pushq $0x1
popq %rsi
movl %r13d, %edi
cmpq %rdi, %rsi
jae 0xb93c
movl (%rdx,%rsi,4), %edi
subl -0x4(%rdx,%rsi,4), %edi
imull -0x4(%rcx,%rsi,4), %edi
addl -0x4(%rax,%rsi,4), %edi
movl %edi, (%rax,%rsi,4)
movl -0x4(%rcx,%rsi,4), %edi
addl %edi, (%rcx,%rsi,4)
incq %rsi
movl 0x48(%rbx), %r13d
jmp 0xb8d3
leal -0x1(%r13), %ecx
andl $0x0, (%rax,%rcx,4)
movq 0x40(%rbx), %rdx
movq 0x50(%rbx), %rsi
addl $-0x2, %r13d
cmpl $-0x1, %r13d
je 0xb93c
movl (%rsi,%rcx,4), %edi
movl %r13d, %r8d
subl (%rsi,%r8,4), %edi
imull (%rdx,%rcx,4), %edi
addl (%rax,%rcx,4), %edi
movl %edi, (%rax,%r8,4)
movl (%rdx,%rcx,4), %edi
addl %edi, (%rdx,%r8,4)
decl %r13d
decq %rcx
jmp 0xb912
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop