// File: /workspace/github_cpp_makefile_star2_O2/keyan[P]ev_routing_engine/router.cpp
// Function: Router::build_result_string[abi:cxx11](std::unordered_map<unsigned short, Label, std::hash<unsigned short>, std::equal_to<unsigned short>, std::allocator<std::pair<unsigned short const, Label>>> const&, unsigned short, unsigned short)
std::string Router::build_result_string(const NodeToLabelMap &shortest_path_tree,
                                        NodeID source_node_id, NodeID target_node_id) {
  std::vector<std::string> names;
  std::vector<double> charge_times;

  Label curr = shortest_path_tree.at(target_node_id);
  while (curr.node_id != source_node_id) {
    names.push_back(network_.at(curr.node_id).name);
    charge_times.push_back(ms_to_hours(curr.charge_time));
    curr = shortest_path_tree.at(curr.parent);
  }

  // The last charge time is how long we charged at the source, always 0.
  charge_times.pop_back();

  // Construct results in reverse because names/charge_times are currently
  // kept in target -> source order, but spec asks for source -> target.
  std::string result = network_.at(source_node_id).name;
  auto charge_it = charge_times.rbegin();
  for (auto name_it = names.rbegin(); name_it != names.rend(); ++name_it) {
    if (charge_it == charge_times.rend()) {
      result += ", " + *name_it;
    } else {
      result += ", " + *name_it + ", " + std::to_string(*charge_it);
      ++charge_it;
    }
  }

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, (%rsp)
leaq 0xe(%rsp), %rsi
movw %r8w, (%rsi)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %rdx, %rdi
callq 0xad34
movq 0x20(%rax), %rcx
leaq 0x90(%rsp), %r12
movq %rcx, (%r12)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movapd %xmm1, -0x10(%r12)
movapd %xmm0, -0x20(%r12)
leaq 0x10(%rsp), %rbx
leaq 0x50(%rsp), %r13
movzwl 0x70(%rsp), %esi
cmpw %bp, %si
je 0x9515
movq (%r14), %rdi
callq 0x814a
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x97b2
movsd 0x80(%rsp), %xmm0
unpcklps 0x3bcc(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3bd4(%rip), %xmm0     # 0xd090
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x3b78(%rip), %xmm1     # 0xd048
movsd %xmm1, 0x50(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xaf1c
movq %r15, %rdi
movq %r12, %rsi
callq 0xad34
movzwl 0x20(%rax), %ecx
movw %cx, 0x90(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movapd %xmm1, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
jmp 0x9481
addq $-0x8, 0x18(%rsp)
movq (%r14), %rdi
movzwl %bp, %esi
callq 0x814a
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x21c0
movq 0x18(%rsp), %rbx
movq 0x38(%rsp), %r14
leaq 0x3b5d(%rip), %r12      # 0xd0a0
leaq 0x50(%rsp), %r15
leaq 0xd8(%rsp), %rbp
cmpq 0x30(%rsp), %r14
je 0x961d
cmpq 0x10(%rsp), %rbx
je 0x95ea
leaq -0x20(%r14), %rdx
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x97de
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x98bb
movsd -0x8(%rbx), %xmm0
movq %rbp, %rdi
callq 0x98da
movq %r15, %rdi
leaq 0x98(%rsp), %rsi
movq %rbp, %rdx
callq 0x9854
leaq 0xb8(%rsp), %r12
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x22a0
addq $-0x8, %rbx
movq %r15, %rdi
callq 0x20c0
movq %rbp, %rdi
callq 0x20c0
leaq 0x98(%rsp), %rdi
callq 0x20c0
movq %r12, %rdi
jmp 0x9608
leaq -0x20(%r14), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x97de
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x22a0
movq %r15, %rdi
callq 0x20c0
addq $-0x20, %r14
leaq 0x3a88(%rip), %r12      # 0xd0a0
jmp 0x9550
leaq 0x10(%rsp), %rdi
callq 0xad26
leaq 0x30(%rsp), %rdi
callq 0x98fe
movq (%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x96aa
jmp 0x9655
movq %rax, %r14
leaq 0x50(%rsp), %rdi
jmp 0x9698
movq %rax, %r14
jmp 0x969d
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x20c0
jmp 0x9676
movq %rax, %r14
jmp 0x9690
movq %rax, %r14
jmp 0x9683
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x20c0
leaq 0x98(%rsp), %rdi
callq 0x20c0
leaq 0xb8(%rsp), %rdi
callq 0x20c0
movq (%rsp), %rdi
callq 0x20c0
jmp 0x96ad
jmp 0x96aa
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0xad26
leaq 0x30(%rsp), %rdi
callq 0x98fe
movq %r14, %rdi
callq 0x2260
nop