// File: 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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x60(%rsp)
movw %r8w, %ax
movq %rdi, %r8
movq %r8, 0x68(%rsp)
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq %rdx, 0x1c0(%rsp)
movw %cx, 0x1be(%rsp)
movw %ax, 0x1bc(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x15cb0
leaq 0x188(%rsp), %rdi
callq 0x15cc0
movq 0x1c0(%rsp), %rdi
leaq 0x1bc(%rsp), %rsi
callq 0x15cd0
movq %rax, 0x78(%rsp)
jmp 0x14aa3
movq 0x78(%rsp), %rsi
leaq 0x160(%rsp), %rdi
movl $0x28, %edx
callq 0x21b0
movzwl 0x160(%rsp), %eax
movzwl 0x1be(%rsp), %ecx
cmpl %ecx, %eax
je 0x14b90
movq 0x70(%rsp), %rax
movq (%rax), %rdi
movzwl 0x160(%rsp), %eax
movl %eax, %esi
callq 0x101a0
movq %rax, 0x58(%rsp)
jmp 0x14af0
movq 0x58(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x15d00
jmp 0x14b04
movq 0x170(%rsp), %rdi
callq 0x15da0
movsd %xmm0, 0x50(%rsp)
jmp 0x14b19
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
leaq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x15d70
jmp 0x14b3f
movq 0x1c0(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x15cd0
movq %rax, 0x48(%rsp)
jmp 0x14b5b
movq 0x48(%rsp), %rsi
leaq 0x160(%rsp), %rdi
movl $0x22, %edx
callq 0x21b0
jmp 0x14aba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x14ef3
leaq 0x188(%rsp), %rdi
callq 0x15de0
movq 0x70(%rsp), %rax
movb $0x0, 0x147(%rsp)
movq (%rax), %rdi
movzwl 0x1be(%rsp), %eax
movl %eax, %esi
callq 0x101a0
movq %rax, 0x40(%rsp)
jmp 0x14bc3
movq 0x40(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0x20d0
jmp 0x14bd4
leaq 0x138(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x15e00
leaq 0x130(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x15e50
leaq 0x128(%rsp), %rdi
movq %rdi, 0x30(%rsp)
leaq 0x1a0(%rsp), %rsi
callq 0x15ed0
movq 0x30(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x15ea0
movb %al, 0x3f(%rsp)
jmp 0x14c30
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x14c3d
jmp 0x14ea6
leaq 0x120(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x188(%rsp), %rsi
callq 0x15f70
movq 0x20(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x15f20
movb %al, 0x2f(%rsp)
jmp 0x14c6f
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x14c7c
jmp 0x14d10
leaq 0x130(%rsp), %rdi
callq 0x160f0
movq %rax, 0x18(%rsp)
jmp 0x14c90
movq 0x18(%rsp), %rdx
leaq 0xa415(%rip), %rsi      # 0x1f0b1
leaq 0x100(%rsp), %rdi
callq 0x15fc0
jmp 0x14cab
movq 0x60(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x2280
jmp 0x14cbf
leaq 0x100(%rsp), %rdi
callq 0x2140
jmp 0x14e90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x14ee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x2140
jmp 0x14ee9
leaq 0x130(%rsp), %rdi
callq 0x160f0
movq %rax, 0x10(%rsp)
jmp 0x14d24
movq 0x10(%rsp), %rdx
leaq 0xa381(%rip), %rsi      # 0x1f0b1
leaq 0xa0(%rsp), %rdi
callq 0x15fc0
jmp 0x14d3f
leaq 0xa36b(%rip), %rdx      # 0x1f0b1
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x16210
jmp 0x14d5d
leaq 0x138(%rsp), %rdi
callq 0x162b0
movq %rax, 0x8(%rsp)
jmp 0x14d71
movq 0x8(%rsp), %rax
movsd (%rax), %xmm0
leaq 0x80(%rsp), %rdi
callq 0x16260
jmp 0x14d89
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x16120
jmp 0x14da8
movq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2280
jmp 0x14dbc
leaq 0xe0(%rsp), %rdi
callq 0x2140
leaq 0x80(%rsp), %rdi
callq 0x2140
leaq 0xc0(%rsp), %rdi
callq 0x2140
leaq 0xa0(%rsp), %rdi
callq 0x2140
leaq 0x138(%rsp), %rdi
callq 0x162e0
jmp 0x14dff
jmp 0x14e90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x14e81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x14e74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x14e67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x2140
leaq 0x80(%rsp), %rdi
callq 0x2140
leaq 0xc0(%rsp), %rdi
callq 0x2140
leaq 0xa0(%rsp), %rdi
callq 0x2140
jmp 0x14ee9
jmp 0x14e92
leaq 0x130(%rsp), %rdi
callq 0x16310
jmp 0x14ea1
jmp 0x14bfe
movb $0x1, 0x147(%rsp)
testb $0x1, 0x147(%rsp)
jne 0x14ec2
movq 0x60(%rsp), %rdi
callq 0x2140
leaq 0x188(%rsp), %rdi
callq 0x16340
leaq 0x1a0(%rsp), %rdi
callq 0x163a0
movq 0x68(%rsp), %rax
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x60(%rsp), %rdi
callq 0x2140
leaq 0x188(%rsp), %rdi
callq 0x16340
leaq 0x1a0(%rsp), %rdi
callq 0x163a0
movq 0x158(%rsp), %rdi
callq 0x2370
nopw (%rax,%rax)