// File: /workspace/github_cpp_makefile_star2_O3/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, %r13d
testl %edx, %edx
movq %rdi, 0x8(%rsp)
movl 0x48(%rdi), %ecx
cmovel %ecx, %r14d
xorl %eax, %eax
movq %rax, 0x20(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movq %rax, 0xa0(%rsp)
movdqa %xmm0, 0x90(%rsp)
movl $0x0, 0x40(%rsp)
cmpl $0x1, %ecx
jne 0xda03
movl $0x0, 0x40(%rsp)
xorl %r14d, %r14d
jmp 0xda68
leaq 0x10(%rsp), %r15
leaq 0x40(%rsp), %r12
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xda26
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xda31
movq %r15, %rdi
movq %r12, %rdx
callq 0xaa8a
movl 0x40(%rsp), %eax
addl %r14d, %eax
movl %eax, 0x40(%rsp)
movq 0x8(%rsp), %rcx
movl 0x48(%rcx), %ecx
decl %ecx
cmpl %ecx, %eax
jb 0xda0d
movq 0x18(%rsp), %r14
movl %ecx, 0x40(%rsp)
cmpq 0x20(%rsp), %r14
je 0xda68
movl %ecx, (%r14)
addq $0x4, %r14
movq %r14, 0x18(%rsp)
jmp 0xda7f
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0xeaa8
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rax
subq %rax, %r14
je 0xdae6
movl $0x1, %ebx
xorl %ebp, %ebp
leaq 0x90(%rsp), %r15
leaq 0x40(%rsp), %r12
xorl %ecx, %ecx
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rdx
movl (%rax,%rcx,4), %esi
movl %ebp, (%rdx,%rsi,4)
movq 0x30(%rdi), %rdx
movl (%rax,%rcx,4), %eax
movl %ebp, (%rdx,%rax,4)
movq $0x0, 0x40(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xc7da
movl %ebx, %ecx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %ebx
cmpq %rcx, %rdx
ja 0xda9f
shrq $0x2, %r14
decl %r14d
movl %r14d, %eax
movq %rax, 0xa8(%rsp)
je 0xdfb0
xorl %r14d, %r14d
leaq 0x40(%rsp), %r15
movzbl %r13b, %eax
movl %eax, 0x38(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x80(%rsp)
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm0, 0x60(%rsp)
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0xe932
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x34(%rsp)
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0xebdc
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %ecx
movl 0x4(%rax,%r14,4), %edx
incq %r14
movq %rcx, 0x28(%rsp)
leal 0x1(%rcx), %eax
cmpl %edx, %eax
jae 0xdf7d
movl %eax, %ebx
movq %r14, 0xb8(%rsp)
movq %rbx, 0xb0(%rsp)
movq 0x28(%rsp), %rax
movl %eax, 0x3c(%rsp)
movl %ebx, %r12d
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
movl 0x38(%rsp), %ecx
callq 0xe140
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rbp
movq 0x60(%rsp), %rdi
movl (%rbp), %ecx
movq 0x30(%rbx), %rax
movq 0xb0(%rsp), %rbx
cmpl (%rax,%rbx,4), %ecx
jae 0xdc2c
leaq -0x8(%rdi), %rcx
cmpq %rcx, %rbp
je 0xdbe7
addq $0x8, %rbp
jmp 0xdc22
movq 0x58(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x3270
movq 0x68(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x68(%rsp)
movq 0x8(%rax), %rbp
movq %rbp, 0x58(%rsp)
leaq 0x200(%rbp), %rdi
movq %rdi, 0x60(%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rbp, 0x50(%rsp)
movl (%rbp), %ecx
jmp 0xdbd3
movq %r12, 0x28(%rsp)
addl $0x2, 0x3c(%rsp)
movq 0x68(%rsp), %r8
movq 0x88(%rsp), %rbx
movq %rbx, %r15
subq %r8, %r15
shrq $0x3, %r15
cmpq $0x1, %rbx
movq %r15, %rax
adcq $-0x1, %rax
shlq $0x6, %rax
movq 0x70(%rsp), %r12
movq 0x78(%rsp), %r14
movq %r12, %rcx
subq %r14, %rcx
sarq $0x3, %rcx
movq %rdi, %r13
subq %rbp, %r13
sarq $0x3, %r13
addq %rcx, %r13
addq %r13, %rax
cmpq $0x2, %rax
jb 0xdda5
movq 0x58(%rsp), %rax
movq %rbp, %rdx
movq %rax, 0xc0(%rsp)
subq %rax, %rdx
movq %rdx, %rax
sarq $0x3, %rax
leaq 0x1(%rax), %rcx
cmpq $-0x1, %rax
movq %rdi, 0xd0(%rsp)
movq %r14, 0xc8(%rsp)
jl 0xdccd
cmpq $0x3f, %rcx
ja 0xdcd6
movq %rbx, %r14
leaq 0x8(%rbp), %rcx
jmp 0xdcf2
movq %rcx, %rsi
sarq $0x6, %rsi
jmp 0xdcdd
movq %rcx, %rsi
shrq $0x6, %rsi
movq %rbx, %r14
movq %rsi, %rdi
shlq $0x6, %rdi
subq %rdi, %rcx
shlq $0x3, %rcx
addq (%r8,%rsi,8), %rcx
movq %r12, %rbx
testq %rax, %rax
js 0xdd0c
movq %rbp, %rdx
cmpq $0x40, %rax
jb 0xdd25
movq %rax, %rdx
shrq $0x6, %rdx
jmp 0xdd10
sarq $0x9, %rdx
movq %rdx, %rsi
shlq $0x6, %rsi
subq %rsi, %rax
shlq $0x3, %rax
addq (%r8,%rdx,8), %rax
movq %rax, %rdx
movl (%rcx), %esi
movl (%rdx), %edx
movq 0x8(%rsp), %rdi
movl 0x3c(%rsp), %ecx
movq %r8, %r12
callq 0xe246
movq %r12, %r8
testb %al, %al
movq 0xd0(%rsp), %rdi
movq %rbx, %r12
movq %r14, %rbx
movq 0xc8(%rsp), %r14
je 0xdda5
leaq -0x8(%rdi), %rax
cmpq %rax, %rbp
je 0xdd66
addq $0x8, %rbp
jmp 0xdd9b
movl $0x200, %esi            # imm = 0x200
movq 0xc0(%rsp), %rdi
callq 0x3270
movq 0x68(%rsp), %rax
leaq 0x8(%rax), %r8
movq %r8, 0x68(%rsp)
movq 0x8(%rax), %rbp
movq %rbp, 0x58(%rsp)
leaq 0x200(%rbp), %rdi
movq %rdi, 0x60(%rsp)
movq %rbp, 0x50(%rsp)
jmp 0xdc3b
cmpq $0x1, %rbx
adcq $-0x1, %r15
shlq $0x6, %r15
addq %r13, %r15
cmpq $0x2, %r15
jb 0xdefa
movq %rbp, %rax
addq $-0x2, %r15
subq 0x58(%rsp), %rax
sarq $0x3, %rax
addq %r15, %rax
js 0xdde6
cmpq $0x3f, %rax
ja 0xddef
leaq (,%r15,8), %rax
addq %rbp, %rax
jmp 0xde08
movq %rax, %rcx
sarq $0x6, %rcx
jmp 0xddf6
movq %rax, %rcx
shrq $0x6, %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
subq %rdx, %rax
shlq $0x3, %rax
addq (%r8,%rcx,8), %rax
movl (%rax), %esi
cmpq %r14, %r12
je 0xde43
movq %r14, %r13
movq %r8, %r15
movq %rdi, %r14
movl -0x8(%r12), %edx
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rcx
callq 0xe2c6
testb %al, %al
je 0xdef7
addq $-0x8, %r12
movq %r14, %rdi
movq %r15, %r8
movq %r13, %r14
jmp 0xdeb3
movq -0x8(%rbx), %rax
movl 0x1f8(%rax), %edx
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rcx
callq 0xe2c6
testb %al, %al
je 0xdefa
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0x3270
movq 0x88(%rsp), %rax
leaq -0x8(%rax), %rbx
movq %rbx, 0x88(%rsp)
movq -0x8(%rax), %r14
movq %r14, 0x78(%rsp)
leaq 0x200(%r14), %rax
movq %rax, 0x80(%rsp)
leaq 0x1f8(%r14), %r12
movq 0x68(%rsp), %r8
movq 0x50(%rsp), %rbp
movq 0x60(%rsp), %rdi
movq %rbx, %rax
subq %r8, %rax
shrq $0x3, %rax
cmpq $0x1, %rbx
adcq $-0x1, %rax
movq %r12, 0x70(%rsp)
shlq $0x6, %rax
movq %r12, %rcx
subq %r14, %rcx
sarq $0x3, %rcx
movq %rdi, %r15
subq %rbp, %r15
sarq $0x3, %r15
addq %rcx, %r15
addq %rax, %r15
movq %rbp, %rax
cmpq $0x1, %r15
ja 0xddc1
jmp 0xdefa
movq %r13, %r14
movq %r12, %rax
cmpq %r14, %r12
jne 0xdf0e
movq -0x8(%rbx), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movl -0x8(%rax), %edx
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0xe358
testb %al, %al
leaq 0x40(%rsp), %r15
movq 0xb0(%rsp), %rbx
je 0xdf60
movq 0x80(%rsp), %rax
addq $-0x8, %rax
cmpq %rax, %r12
je 0xdf53
movq 0x30(%rsp), %rax
movq %rax, (%r12)
addq $0x8, 0x70(%rsp)
jmp 0xdf60
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0xee3e
incq %rbx
movq 0x10(%rsp), %rax
movq 0xb8(%rsp), %r14
movl (%rax,%r14,4), %edx
cmpq %rdx, %rbx
jb 0xdb8a
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movl 0x38(%rsp), %ecx
callq 0xe3d6
movq 0x90(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq %r15, %rdi
callq 0xeb84
cmpq 0xa8(%rsp), %r14
jne 0xdb0e
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
cmpq $0x2, %rax
jb 0xdff2
movl $0x1, %edx
xorl %ecx, %ecx
movq (%rdi,%rcx,8), %xmm0
movq (%rdi,%rdx,8), %xmm1
paddd %xmm0, %xmm1
movq %xmm1, (%rdi,%rdx,8)
leal 0x2(%rcx), %edx
incq %rcx
cmpq %rdx, %rax
ja 0xdfd4
movq 0xa8(%rsp), %rsi
movl 0x4(%rdi,%rsi,8), %eax
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rcx
movl 0x48(%rdx), %edx
decl %edx
movl %eax, (%rcx,%rdx,4)
movl (%rdi,%rsi,8), %ebx
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xe039
movq 0x20(%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 0xe055
jmp 0xe055
jmp 0xe055
jmp 0xe05a
movq %rax, %rbx
jmp 0xe067
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xeb84
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xe084
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xe09b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3460
nop