// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq $0x2, %rbp
jb 0xd255
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x0, (%r14,%rcx,4)
je 0xd24d
incl %eax
movl %eax, 0x48(%rbx)
incq %rcx
cmpq %rcx, %rbp
jne 0xd241
movl 0x48(%rbx), %r13d
movq %r13, %r12
shlq $0x2, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %r15
movq %rax, 0x50(%rbx)
movl $0x0, (%rax)
decl %r13d
movl %ebp, (%rax,%r13,4)
movq %r12, %rdi
callq 0x3030
movq %rax, 0x40(%rbx)
xorl %ecx, %ecx
cmpb $0x0, 0x1c(%rbx)
jne 0xd293
movl (%r14), %ecx
movl %ecx, (%rax)
movl 0x8(%rbx), %ecx
cmpq $0x2, %rcx
jb 0xd2c5
movl $0x1, %edx
movl $0x1, %esi
movl (%r14,%rsi,4), %edi
testl %edi, %edi
je 0xd2bd
movl %edx, %r8d
movl %edi, (%rax,%r8,4)
movl %esi, (%r15,%r8,4)
incl %edx
incq %rsi
cmpq %rsi, %rcx
jne 0xd2a8
movl $0x0, (%rax,%r13,4)
testq %r14, %r14
je 0xd2da
movq %r14, %rdi
callq 0x3300
movl 0x48(%rbx), %r14d
leaq (,%r14,4), %rdi
callq 0x3030
movq %rax, 0x38(%rbx)
cmpb $0x1, 0x1c(%rbx)
jne 0xd339
movl $0x0, (%rax)
cmpl $0x2, 0x48(%rbx)
jb 0xd389
movq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rdx
movl $0x1, %esi
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), %edi
cmpq %rdi, %rsi
jb 0xd312
jmp 0xd389
decl %r14d
movl $0x0, (%rax,%r14,4)
je 0xd389
movq 0x40(%rbx), %rcx
movq 0x50(%rbx), %rdx
movl %r14d, %esi
decq %rsi
movq %rsi, %rdi
movl 0x4(%rdx,%rsi,4), %r8d
movl %esi, %r9d
shlq $0x2, %r9
subl (%rdx,%r9), %r8d
imull 0x4(%rcx,%rsi,4), %r8d
addl 0x4(%rax,%rsi,4), %r8d
movl %r8d, (%rax,%r9)
movl 0x4(%rcx,%rsi,4), %r8d
addl %r8d, (%rcx,%r9)
decq %rdi
testl %esi, %esi
movq %rdi, %rsi
jne 0xd357
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq