// File: /workspace/github_cpp_makefile_star2_O3/keyan[P]ev_routing_engine/router.cpp
// Function: Router::route(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string Router::route(std::string source_name, std::string target_name) {
  // All labels in the vector are non-dominating in respect to total_weight and state_of_charge.
  // That is, all labels for a node are Pareto optimal.
  std::unordered_map<NodeID, std::vector<Label>> label_map;
  // Once a NodeID is added to the spt, we know the best Label to use to get to it.
  NodeToLabelMap shortest_path_tree;

  int label_id = 0;
  MinHeapPriorityQueue label_queue;
  // Used to keep track of removed Labels in the pq, we can't issue deletes because
  // std::priority_queue doesn't provide pointers to allow arbitrary deletes of items.
  std::unordered_set<int> deleted_labels;

  NodeID source_node_id = node_name_map_[source_name];
  NodeID target_node_id = node_name_map_[target_name];

  label_queue.emplace(Label(source_node_id, label_id++, 0, 0, MAX_CHARGE, source_node_id));
  while (!label_queue.empty()) {
    Label curr_label = label_queue.top();
    label_queue.pop();

    const NodeID &curr_node_id = curr_label.node_id;

    // std::priority_queue has no decrease-weight operation, instead do a "lazy
    // deletion" by keeping the old node in the pq and just ignoring it when it
    // is eventually popped.
    if (deleted_labels.count(curr_label.label_id) == 1 ||
        shortest_path_tree.count(curr_node_id) == 1) {
      continue;
    }
    shortest_path_tree.emplace(curr_node_id, curr_label);

    // Search is done.
    if (curr_node_id == target_node_id) {
      break;
    }

    const Station &curr_station = network_.at(curr_node_id);

    // Update weights for all neighbors not in the spt.
    // This is the main departure from standard dijkstra's. Instead of relaxing edges between
    // neighbors, we construct "labels" up to 3 per neighbor, and try to merge them into the
    // LabelMap. Any non-dominated labels are also added to the priority queue.
    for (auto &edge : graph_.at(curr_node_id)) {
      const NodeID &adj_node_id = edge.first;
      const Kilometers &dist_to_neighbor = edge.second;

      if (shortest_path_tree.count(adj_node_id) == 1) {
        continue;
      }

      Weight direct_weight_to_neighbor = convert_km_to_ms_travel(dist_to_neighbor);

      // Three possible label cases.
      std::vector<Label> labels;
      // 1. Go to neighbor without any charging, if possible.
      if (dist_to_neighbor <= curr_label.state_of_charge) {
        labels.emplace_back(Label(adj_node_id, label_id++,
                                  curr_label.total_weight + direct_weight_to_neighbor, 0,
                                  curr_label.state_of_charge - dist_to_neighbor, curr_node_id));
      }
      // 2. Do a full recharge, if needed.
      if (curr_label.state_of_charge < MAX_CHARGE) {
        Weight addtl_charge_time =
            time_to_full_charge(curr_label.state_of_charge, curr_station.rate);
        labels.emplace_back(
            Label(adj_node_id, label_id++,
                  curr_label.total_weight + direct_weight_to_neighbor + addtl_charge_time,
                  addtl_charge_time, MAX_CHARGE - dist_to_neighbor, curr_node_id));
      }
      // 3. Only charge enough to get to neighbor.
      if (curr_label.state_of_charge < MAX_CHARGE &&
          curr_label.state_of_charge < dist_to_neighbor) {
        Weight addtl_charge_time =
            time_to_partial_charge(curr_label.state_of_charge, dist_to_neighbor, curr_station.rate);
        labels.emplace_back(
            Label(adj_node_id, label_id++,
                  curr_label.total_weight + direct_weight_to_neighbor + addtl_charge_time,
                  addtl_charge_time, 0, curr_node_id));
      }

      // Update this nodes label bag. This is similar to "relaxing" edges in standard Dijkstra's.
      auto search = label_map.find(adj_node_id);
      if (search == label_map.end()) {
        // No labels exist to dominate these ones, so add them all.
        for (auto &label : labels) {
          label_queue.push(label);
        }
        label_map[adj_node_id] = std::move(labels);
      } else {
        std::vector<Label> &bag = search->second;

        for (auto &label : labels) {
          auto search = std::find_if(bag.begin(), bag.end(),
                                     [&](const Label &other) { return other.dominates(label); });
          // This label is dominated, it can be ignored.
          if (search != bag.end()) {
            continue;
          }

          // Does this label dominate anything in the bag already? If so, remove those labels.
          auto d_it = std::partition(bag.begin(), bag.end(),
                                     [&](const Label &other) { return !label.dominates(other); });
          for (auto it = d_it; it != bag.end(); ++it) {
            deleted_labels.insert((*it).label_id);
          }
          bag.erase(d_it, bag.end());
          bag.push_back(label);
          label_queue.push(label);
        }
      }
    }
  }

  return build_result_string(shortest_path_tree, source_node_id, target_node_id);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x190(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, %esi       # imm = 0x3F800000
movl %esi, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
leaq 0x120(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movupd %xmm0, -0x20(%rax)
movl %esi, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
movapd %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
leaq 0x158(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movupd %xmm0, -0x20(%rax)
movl %esi, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
leaq 0x8(%r12), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x9944
movzwl (%rax), %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9944
movq %r12, 0xc8(%rsp)
movq %r15, 0xd8(%rsp)
movzwl (%rax), %eax
movw %ax, 0xc(%rsp)
leaq 0x30(%rsp), %rsi
movw %bp, (%rsi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x4(%rsi)
movl $0x0, 0x14(%rsi)
movabsq $0x4074000000000000, %rax # imm = 0x4074000000000000
movq %rax, 0x18(%rsi)
movw %bp, 0xe(%rsp)
movw %bp, 0x20(%rsi)
leaq 0xa0(%rsp), %rdi
callq 0xb25a
movq 0xa0(%rsp), %rax
cmpq 0xa8(%rsp), %rax
je 0xaaed
movl $0x1, %r13d
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
leaq 0x128(%rsp), %rbp
movq 0x20(%rax), %rcx
movq %rcx, 0x90(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movapd %xmm1, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xb348
movslq 0x74(%rsp), %rcx
movq 0x128(%rsp), %rdi
movq 0x130(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0xa3f9
movq %rdx, %rsi
movq (%rax), %r9
cmpl 0x8(%r9), %ecx
je 0xaad7
movq (%r9), %r9
testq %r9, %r9
je 0xa3f9
movslq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0xa3f9
cmpl %edi, %ecx
jne 0xa3d7
jmp 0xaad7
movzwl 0x70(%rsp), %ecx
movq 0xf0(%rsp), %rdi
movq 0xf8(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movl %esi, %eax
movq (%rdi,%rax,8), %rax
testq %rax, %rax
je 0xa456
movq (%rax), %r9
cmpw 0x8(%r9), %cx
je 0xaad7
movq (%r9), %r9
testq %r9, %r9
je 0xa456
movzwl 0x8(%r9), %edi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0xa456
cmpw %di, %cx
jne 0xa432
jmp 0xaad7
leaq 0xf0(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %rdx, %rsi
callq 0xb978
movzwl 0x70(%rsp), %esi
cmpw 0xc(%rsp), %si
je 0xaaed
movq 0xc8(%rsp), %rdi
movq (%rdi), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0xab66
movq 0x40(%rdi), %rcx
movq 0x48(%rdi), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rdx
cmpq %rsi, %rdx
jbe 0xab74
leaq (%rsi,%rsi,2), %rdx
movq (%rcx,%rdx,8), %r12
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, 0xe8(%rsp)
cmpq %rcx, %r12
je 0xaad7
imulq $0x38, %rsi, %rcx
addq %rcx, %rax
addq $0x30, %rax
movq %rax, 0xd0(%rsp)
leaq 0xf0(%rsp), %rdi
movq %r12, %rsi
callq 0xb916
testq %rax, %rax
jne 0xaac5
movsd 0x8(%r12), %xmm0
divsd 0x3b56(%rip), %xmm0     # 0xe080
mulsd 0x3b56(%rip), %xmm0     # 0xe088
addsd 0x3b56(%rip), %xmm0     # 0xe090
cvttsd2si %xmm0, %eax
movslq %eax, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movsd 0x8(%r12), %xmm1
movsd 0x88(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa5c0
movzwl (%r12), %eax
movq 0x78(%rsp), %rcx
addq %r15, %rcx
subsd %xmm1, %xmm0
movzwl 0x70(%rsp), %edx
movw %ax, 0x30(%rsp)
movl %r13d, 0x34(%rsp)
movq %rcx, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movsd %xmm0, 0x48(%rsp)
movw %dx, 0x50(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
leaq 0x30(%rsp), %rdx
callq 0xbc22
movsd 0x88(%rsp), %xmm0
incl %r13d
movsd 0x2a40(%rip), %xmm2     # 0xd008
ucomisd %xmm0, %xmm2
jbe 0xa68b
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movq 0xd0(%rsp), %rax
divsd (%rax), %xmm1
mulsd 0x3a9a(%rip), %xmm1     # 0xe088
addsd 0x3a9a(%rip), %xmm1     # 0xe090
cvttsd2si %xmm1, %eax
cltq
movzwl (%r12), %ecx
movq 0x78(%rsp), %rdx
addq %r15, %rdx
addq %rax, %rdx
movapd %xmm2, %xmm0
subsd 0x8(%r12), %xmm0
movzwl 0x70(%rsp), %esi
movw %cx, 0x30(%rsp)
movl %r13d, 0x34(%rsp)
movq %rdx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movsd %xmm0, 0x48(%rsp)
movw %si, 0x50(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xa670
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsi)
movupd 0x30(%rsp), %xmm0
movupd 0x40(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x28, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xa67f
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xbc22
incl %r13d
movsd 0x88(%rsp), %xmm0
movsd 0x2975(%rip), %xmm1     # 0xd008
ucomisd %xmm0, %xmm1
jbe 0xa74f
movsd 0x8(%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xa74f
subsd %xmm0, %xmm1
movq 0xd0(%rsp), %rax
divsd (%rax), %xmm1
mulsd 0x39c2(%rip), %xmm1     # 0xe088
addsd 0x39c2(%rip), %xmm1     # 0xe090
cvttsd2si %xmm1, %eax
cltq
addq 0x78(%rsp), %r15
movzwl (%r12), %ecx
addq %rax, %r15
movzwl 0x70(%rsp), %edx
movw %cx, 0x30(%rsp)
movl %r13d, 0x34(%rsp)
movq %r15, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movw %dx, 0x50(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xa73d
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsi)
movupd 0x30(%rsp), %xmm0
movupd 0x40(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x28, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xa74c
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xbc22
incl %r13d
leaq 0x160(%rsp), %rdi
movq %r12, 0x60(%rsp)
movq %r12, %rsi
callq 0xbdbc
movq %rax, %r12
testq %rax, %rax
movl %r13d, 0x6c(%rsp)
je 0xaa23
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rbx
cmpq %rbx, %r13
je 0xaaae
movq %r12, %rax
addq $0x10, %rax
movq %rax, 0xe0(%rsp)
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rax
movq 0x8(%r13), %rdx
movsd 0x18(%r13), %xmm0
movq %rax, %rdi
subq %rcx, %rdi
movq %rdi, %r8
sarq $0x3, %r8
imulq %r14, %r8
sarq $0x2, %r8
movq %rcx, %rsi
testq %r8, %r8
jle 0xa840
leaq (%r8,%r8,4), %rsi
shlq $0x5, %rsi
addq %rcx, %rsi
incq %r8
leaq 0x50(%rcx), %rdi
cmpq %rdx, -0x48(%rdi)
jae 0xa7ef
movsd -0x38(%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa885
cmpq %rdx, -0x20(%rdi)
jae 0xa804
movsd -0x10(%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa88b
cmpq %rdx, 0x8(%rdi)
jae 0xa819
movsd 0x18(%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa8b3
cmpq %rdx, 0x30(%rdi)
jae 0xa82a
movsd 0x40(%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa891
decq %r8
addq $0xa0, %rdi
cmpq $0x1, %r8
jg 0xa7da
movq %rax, %rdi
subq %rsi, %rdi
sarq $0x3, %rdi
imulq %r14, %rdi
cmpq $0x1, %rdi
je 0xa89b
cmpq $0x2, %rdi
je 0xa86f
cmpq $0x3, %rdi
jne 0xa8bc
cmpq %rdx, 0x8(%rsi)
jae 0xa86b
movsd 0x18(%rsi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa880
addq $0x28, %rsi
cmpq %rdx, 0x8(%rsi)
jae 0xa897
movsd 0x18(%rsi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xa897
movq %rsi, %rdi
jmp 0xa8b3
addq $-0x50, %rdi
jmp 0xa8b3
addq $-0x28, %rdi
jmp 0xa8b3
addq $0x28, %rdi
jmp 0xa8b3
addq $0x28, %rsi
movsd 0x18(%rsi), %xmm1
ucomisd %xmm0, %xmm1
movq %rax, %rdi
cmovaq %rsi, %rdi
cmpq %rdx, 0x8(%rsi)
cmovaeq %rax, %rdi
cmpq %rax, %rdi
jne 0xaa11
cmpq %rax, %rcx
je 0xa970
movq 0x8(%r13), %rdx
movsd 0x18(%r13), %xmm0
movq %rcx, %r14
cmpq 0x8(%r14), %rdx
jae 0xa8e0
ucomisd 0x18(%r14), %xmm0
ja 0xa8ee
addq $0x28, %r14
cmpq %rax, %r14
jne 0xa8d2
jmp 0xa973
movq %rax, %rcx
leaq -0x28(%rcx), %rax
cmpq %r14, %rax
je 0xa973
cmpq -0x20(%rcx), %rdx
jae 0xa90a
ucomisd -0x10(%rcx), %xmm0
movq %rax, %rcx
ja 0xa8f1
movq 0x20(%r14), %rcx
movq %rcx, 0x50(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movzwl 0x20(%rax), %ecx
movw %cx, 0x20(%r14)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
movzwl 0x50(%rsp), %ecx
movw %cx, 0x20(%rax)
movapd 0x30(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
movupd %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
leaq 0x28(%r14), %rcx
cmpq %rcx, %rax
jne 0xa8c5
addq $0x28, %r14
jmp 0xa973
movq %rcx, %r14
movq 0x18(%r12), %rsi
movq %r14, %r15
cmpq %rsi, %r14
je 0xa9a4
leaq 0x4(%r15), %rsi
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
leaq 0x30(%rsp), %rdx
callq 0xc0f6
addq $0x28, %r15
movq 0x18(%r12), %rsi
cmpq %rsi, %r15
jne 0xa980
cmpq %r15, %r14
je 0xa9b1
movq %r14, 0x18(%r12)
movq %r14, %rsi
cmpq 0x20(%r12), %rsi
je 0xa9e7
movq 0x20(%r13), %rax
movq %rax, 0x20(%rsi)
movupd (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x28, 0x18(%r12)
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
jmp 0xaa01
movq 0xe0(%rsp), %rdi
movq %r13, %rdx
callq 0xc376
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
callq 0xb3e4
addq $0x28, %r13
cmpq %rbx, %r13
jne 0xa797
jmp 0xaaa9
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq %r14, %r15
movq 0x60(%rsp), %r12
je 0xaa50
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0xb3e4
addq $0x28, %r15
cmpq %r14, %r15
jne 0xaa37
leaq 0x160(%rsp), %rdi
movq %r12, %rsi
callq 0xbe1e
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
movq (%rax), %rdi
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
movq 0x60(%rsp), %r12
je 0xaac0
callq 0x2150
movq 0x10(%rsp), %r13
testq %r13, %r13
movq 0x60(%rsp), %r12
je 0xaac0
movq %r13, %rdi
callq 0x2150
movl 0x6c(%rsp), %r13d
addq $0x10, %r12
cmpq 0xe8(%rsp), %r12
jne 0xa502
movq 0xa0(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jne 0xa370
movzwl 0xe(%rsp), %ecx
movzwl 0xc(%rsp), %r8d
leaq 0xf0(%rsp), %rdx
movq 0xd8(%rsp), %rbx
movq %rbx, %rdi
movq 0xc8(%rsp), %rsi
callq 0xabf4
leaq 0x128(%rsp), %rdi
callq 0xb5da
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0xab37
callq 0x2150
leaq 0xf0(%rsp), %rdi
callq 0xb63c
leaq 0x160(%rsp), %rdi
callq 0xb69e
movq %rbx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2554(%rip), %rdi      # 0xd0c1
xorl %eax, %eax
callq 0x21f0
leaq 0x2546(%rip), %rdi      # 0xd0c1
xorl %eax, %eax
callq 0x21f0
jmp 0xab98
jmp 0xab98
jmp 0xab98
jmp 0xaba1
jmp 0xab98
jmp 0xab98
jmp 0xab98
jmp 0xaba1
jmp 0xab98
jmp 0xaba1
jmp 0xaba1
movq %rax, %rbx
jmp 0xabb3
jmp 0xaba1
jmp 0xaba1
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xabb3
callq 0x2150
leaq 0x128(%rsp), %rdi
callq 0xb5da
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0xabd2
callq 0x2150
leaq 0xf0(%rsp), %rdi
callq 0xb63c
leaq 0x160(%rsp), %rdi
callq 0xb69e
movq %rbx, %rdi
callq 0x2250