// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/sampler.cpp
// Function: CSA::WeightedSampler::minimumWeightPath(bool, unsigned int)
uint
WeightedSampler::minimumWeightPath(bool shortest, uint force)
{
  if(force == 0) { force = this->nodes; }
  std::vector<uint> end_points;
  std::vector<pair_type> partial_results;
  for(uint i = 0; i < this->nodes - 1; i += force)
  {
    end_points.push_back(i);
  }
  end_points.push_back(this->nodes - 1);
  uint parts = end_points.size() - 1;
  for(uint i = 0; i < end_points.size(); i++)
  {
    this->path_weights[end_points[i]] = 0;
    this->predecessors[end_points[i]] = 0;
    partial_results.push_back(pair_type(0, 0));
  }

  #pragma omp parallel for schedule(static)
  for(uint part = 0; part < parts; part++)
  {
    std::deque<node_type> active_nodes;
    active_nodes.push_back(node_type(end_points[part], 0));

    for(uint i = end_points[part] + 1; i < end_points[part + 1]; i++)
    {
      node_type current = this->link(active_nodes, i, shortest);

      // Retire the active nodes that are before the linked predecessor.
      while(active_nodes.front().first < this->predecessors[i])
      {
        active_nodes.pop_front();
      }

      // Retire the first active nodes, if the following ones are strictly better.
      while(active_nodes.size() > 1 &&
            this->isStrictlyBetter(active_nodes[1].first, active_nodes[0].first, i + 1))
      {
        active_nodes.pop_front();
      }

      // Retire the last active nodes, if the preceding node or the current node is always
      // strictly better.
      while(active_nodes.size() > 1 &&
            this->bridge(active_nodes[active_nodes.size() - 2].first, active_nodes.back().first, i))
      {
        active_nodes.pop_back();
      }

      // Add the current node to active nodes, if it is at least as good as the active nodes
      // for some future node.
      if(this->isAsGood(i, active_nodes.back().first))
      {
        active_nodes.push_back(current);
      }
    }

    partial_results[part + 1] = this->finalLink(active_nodes, end_points[part + 1], shortest);
  }

  for(uint i = 1; i < partial_results.size(); i++)
  {
    partial_results[i].first += partial_results[i - 1].first;
    partial_results[i].second += partial_results[i - 1].second;
  }
  this->path_weights[this->nodes - 1] = partial_results[parts].second;

  return partial_results[parts].first;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
testl %edx, %edx
jne 0xd873
movl 0x48(%rbx), %r14d
xorl %eax, %eax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq %rax, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x48(%rbx), %ecx
decl %ecx
je 0xd8e0
movq %rsp, %r15
leaq 0x30(%rsp), %r12
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0xd8c1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xd8cc
movq %r15, %rdi
movq %r12, %rdx
callq 0xa9a8
movl 0x30(%rsp), %eax
addl %r14d, %eax
movl %eax, 0x30(%rsp)
movl 0x48(%rbx), %ecx
decl %ecx
cmpl %ecx, %eax
jb 0xd8a8
movl %ecx, 0x30(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
movq %rbx, 0x18(%rsp)
je 0xd902
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xd90f
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0xe8e6
movq (%rsp), %rax
movq 0x8(%rsp), %rbx
subq %rax, %rbx
je 0xd97f
movl $0x1, %r12d
xorl %r13d, %r13d
leaq 0x90(%rsp), %r14
leaq 0x30(%rsp), %r15
xorl %ecx, %ecx
movq 0x18(%rsp), %rdi
movq 0x28(%rdi), %rdx
movl (%rax,%rcx,4), %esi
movl %r13d, (%rdx,%rsi,4)
movq 0x30(%rdi), %rdx
movl (%rax,%rcx,4), %eax
movl %r13d, (%rdx,%rax,4)
movq $0x0, 0x30(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xc6a6
movl %r12d, %ecx
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r12d
cmpq %rcx, %rdx
ja 0xd935
shrq $0x2, %rbx
decl %ebx
movl %ebx, %eax
movq %rax, 0xb0(%rsp)
movq 0x18(%rsp), %r13
je 0xde09
xorl %ebx, %ebx
leaq 0x30(%rsp), %r12
movzbl %bpl, %eax
movl %eax, 0x2c(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0xe770
movq (%rsp), %rax
movl (%rax,%rbx,4), %eax
movl %eax, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0xea12
movq (%rsp), %rax
movl (%rax,%rbx,4), %ecx
movl 0x4(%rax,%rbx,4), %edx
incq %rbx
movq %rcx, 0x88(%rsp)
leal 0x1(%rcx), %eax
cmpl %edx, %eax
jae 0xddd8
movl %eax, %ebp
movq %rbx, 0xb8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl 0x2c(%rsp), %ecx
callq 0xdf8a
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movl (%rax), %ecx
movq 0x30(%r13), %rdx
cmpl (%rdx,%rbp,4), %ecx
jae 0xda8d
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0xda54
addq $0x8, %rax
jmp 0xda86
movq 0x48(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x3270
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x40(%rsp)
jmp 0xda35
movq 0x88(%rsp), %rax
addl $0x2, %eax
movq %rax, 0x88(%rsp)
movq %rbp, 0xc0(%rsp)
movq 0x78(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcq $-0x1, %rdx
shlq $0x6, %rdx
movq 0x60(%rsp), %rcx
subq 0x68(%rsp), %rcx
sarq $0x3, %rcx
movq 0x40(%rsp), %r12
movq 0x50(%rsp), %rdi
movq %rdi, %rsi
subq %r12, %rsi
sarq $0x3, %rsi
addq %rcx, %rsi
addq %rdx, %rsi
cmpq $0x2, %rsi
jb 0xdc3f
movq 0x48(%rsp), %rdx
movq %r12, %rcx
movq %rdx, 0xc8(%rsp)
subq %rdx, %rcx
sarq $0x3, %rcx
leaq 0x1(%rcx), %rdx
cmpq $0x3f, %rdx
movq %rdi, 0xd0(%rsp)
ja 0xdb2a
leaq 0x8(%r12), %rdx
jmp 0xdb5a
movq %rdx, %rsi
shrq $0x6, %rsi
movq %rsi, %rdi
movabsq $-0x400000000000000, %r8 # imm = 0xFC00000000000000
orq %r8, %rdi
testq %rcx, %rcx
cmovnsq %rsi, %rdi
movq %rdi, %rsi
shlq $0x6, %rsi
subq %rsi, %rdx
shlq $0x3, %rdx
addq (%rax,%rdi,8), %rdx
movq %r12, %rdi
cmpq $0x40, %rcx
jb 0xdb96
movq %rcx, %rsi
shrq $0x6, %rsi
movq %rsi, %rdi
movabsq $-0x400000000000000, %r8 # imm = 0xFC00000000000000
orq %r8, %rdi
testq %rcx, %rcx
cmovgq %rsi, %rdi
movq %rdi, %rsi
shlq $0x6, %rsi
subq %rsi, %rcx
shlq $0x3, %rcx
addq (%rax,%rdi,8), %rcx
movq %rcx, %rdi
movl (%rdx), %esi
movl (%rdi), %r14d
movq 0x18(%rsp), %rax
movq 0x28(%rax), %r13
movl (%r13,%rsi,4), %r15d
movq 0x18(%rsp), %rdi
movq 0x88(%rsp), %rbx
movl %ebx, %edx
callq 0xe396
movl %eax, %ebp
addl %r15d, %ebp
movl (%r13,%r14,4), %r15d
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0xe396
addl %r15d, %eax
cmpl %eax, %ebp
movq 0xc0(%rsp), %rbp
movq 0xd0(%rsp), %rax
jae 0xdc3f
addq $-0x8, %rax
cmpq %rax, %r12
je 0xdbff
addq $0x8, %r12
jmp 0xdc35
movl $0x200, %esi            # imm = 0x200
movq 0xc8(%rsp), %rdi
callq 0x3270
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %r12
movq %r12, 0x48(%rsp)
leaq 0x200(%r12), %rax
movq %rax, 0x50(%rsp)
movq %r12, 0x40(%rsp)
jmp 0xdaa8
leaq 0x30(%rsp), %r12
movq 0x78(%rsp), %rbx
movq 0x58(%rsp), %rax
movq %rbx, %rcx
subq %rax, %rcx
shrq $0x3, %rcx
cmpq $0x1, %rbx
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x60(%rsp), %r14
movq 0x68(%rsp), %r15
movq %r14, %rdi
subq %r15, %rdi
sarq $0x3, %rdi
movq 0x40(%rsp), %rdx
movq 0x50(%rsp), %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
addq %rdi, %rsi
addq %rcx, %rsi
cmpq $0x2, %rsi
jb 0xdd5f
movq %rdx, %rcx
subq 0x48(%rsp), %rcx
sarq $0x3, %rcx
addq %rsi, %rcx
addq $-0x2, %rcx
cmpq $0x3f, %rcx
ja 0xdcbc
addq $-0x2, %rsi
leaq (%rdx,%rsi,8), %rcx
jmp 0xdcec
movq %rcx, %rdx
shrq $0x6, %rdx
movq %rdx, %rsi
movabsq $-0x400000000000000, %rdi # imm = 0xFC00000000000000
orq %rdi, %rsi
testq %rcx, %rcx
cmovgq %rdx, %rsi
movq %rsi, %rdx
shlq $0x6, %rdx
subq %rdx, %rcx
shlq $0x3, %rcx
addq (%rax,%rsi,8), %rcx
movq %r14, %rax
cmpq %r15, %r14
jne 0xdd00
movq -0x8(%rbx), %rax
movl $0x200, %edx            # imm = 0x200
addq %rdx, %rax
movl (%rcx), %esi
movl -0x8(%rax), %edx
movq %r13, %rdi
movl %ebp, %ecx
callq 0xe0de
testb %al, %al
je 0xdd5f
cmpq %r15, %r14
je 0xdd1e
addq $-0x8, %r14
jmp 0xdd55
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
callq 0x3270
movq 0x78(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x78(%rsp)
movq -0x8(%rax), %r14
movq %r14, 0x68(%rsp)
leaq 0x200(%r14), %rax
movq %rax, 0x70(%rsp)
addq $0x1f8, %r14            # imm = 0x1F8
movq %r14, 0x60(%rsp)
jmp 0xdc44
movq %r14, %rax
cmpq %r15, %r14
jne 0xdd73
movq -0x8(%rbx), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movl -0x8(%rax), %edx
movq %r13, %rdi
movl %ebp, %esi
callq 0xe1d8
testb %al, %al
movq 0xb8(%rsp), %rbx
je 0xddb7
movq 0x70(%rsp), %rax
addq $-0x8, %rax
cmpq %rax, %r14
je 0xddaa
movq 0x20(%rsp), %rax
movq %rax, (%r14)
addq $0x8, 0x60(%rsp)
jmp 0xddb7
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0xec6e
movl %ebp, %eax
movq %rax, 0x88(%rsp)
leaq 0x1(%rbp), %rax
movq (%rsp), %rcx
movl (%rcx,%rbx,4), %edx
movq %rax, %rbp
cmpq %rdx, %rax
jb 0xda1a
movq %r13, %rdi
movq %r12, %rsi
movl 0x2c(%rsp), %ecx
callq 0xe256
movq 0x90(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r12, %rdi
callq 0xe9c2
cmpq 0xb0(%rsp), %rbx
jne 0xd9a9
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
cmpq $0x2, %rax
jb 0xde46
movl $0x1, %edx
xorl %ecx, %ecx
movl (%rdi,%rcx,8), %esi
addl %esi, (%rdi,%rdx,8)
movl 0x4(%rdi,%rcx,8), %esi
addl %esi, 0x4(%rdi,%rdx,8)
leal 0x2(%rcx), %edx
incq %rcx
cmpq %rdx, %rax
ja 0xde2d
movq 0xb0(%rsp), %rsi
movl 0x4(%rdi,%rsi,8), %eax
movq 0x28(%r13), %rcx
movl 0x48(%r13), %edx
decl %edx
movl %eax, (%rcx,%rdx,4)
movl (%rdi,%rsi,8), %ebx
testq %rdi, %rdi
je 0xde77
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xde8d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdea9
jmp 0xdea9
jmp 0xdea9
jmp 0xdeae
movq %rax, %rbx
jmp 0xdebb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xe9c2
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xded8
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xdeee
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460