// File: Kei18[P]pibt/./src/solver/tp.cpp
// Function: TP::updatePath2(Agent*, int)
void TP::updatePath2(Agent* a, int startTime) {
  Nodes candidates;
  std::vector<Task*> T = P->getT();
  bool contained;

  // create candidates
  for (auto v : endpoints) {
    contained = std::any_of(T.begin(), T.end(),
                             [v](Task* tau) {
                               return tau->getG()[tau->getG().size() - 1] == v; });
    if (contained) continue;
    contained = std::any_of(paths.begin(), paths.end(),
                            [v](Nodes path) {
                              return path[path.size() - 1] == v; });
    if (contained) continue;
    candidates.push_back(v);
  }

  if (candidates.empty()) {  // failed
    std::cout << "updatePath2, candidates are empty" << a->getId() << "\n";
    status = false;
    return;
  }

  // choose candidates
  Node* u = a->getNode();
  Graph* _G = G;
  auto itr1 = std::min_element(candidates.begin(), candidates.end(),
                               [u, _G](Node* v1, Node* v2) {
                                 return _G->dist(u, v1) < _G->dist(u, v2); });
  a->setGoal(*itr1);
  Nodes path = getPath(a, startTime);

  if (path.empty()) {
    std::cout << "updatePath2, path is empty" << a->getId() << "\n";
    status = false;
    return;
  }

  auto itr2 = std::find(A.begin(), A.end(), a);
  int i = std::distance(A.begin(), itr2);
  paths[i].insert(paths[i].end(), path.begin() + 1, path.end());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3e880
movq -0x168(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x8bb10
jmp 0xa1920
movq -0x168(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x3b730
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0x3b760
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3b790
testb $0x1, %al
jne 0xa195f
jmp 0xa1a8b
leaq -0x68(%rbp), %rdi
callq 0x3bb00
movq (%rax), %rax
movq %rax, -0x78(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x3a140
movq -0x178(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x39fd0
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0xa3b80
movb %al, -0x169(%rbp)
jmp 0xa19c0
movb -0x169(%rbp), %al
andb $0x1, %al
movb %al, -0x55(%rbp)
testb $0x1, -0x55(%rbp)
je 0xa19f8
jmp 0xa1a7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xa1e75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xa1e6c
movq -0x168(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0x188(%rbp)
callq 0x377e0
movq -0x188(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x37500
movq %rax, -0xa0(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0xa3bd0
movb %al, -0x179(%rbp)
jmp 0xa1a59
movb -0x179(%rbp), %al
andb $0x1, %al
movb %al, -0x55(%rbp)
testb $0x1, -0x55(%rbp)
je 0xa1a6c
jmp 0xa1a7d
leaq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3f490
jmp 0xa1a7b
jmp 0xa1a7d
leaq -0x68(%rbp), %rdi
callq 0x3bad0
jmp 0xa1949
leaq -0x30(%rbp), %rdi
callq 0x3ec00
testb $0x1, %al
jne 0xa1a9a
jmp 0xa1b14
movq 0x5f4f7(%rip), %rdi     # 0x100f98
leaq 0x15dc0(%rip), %rsi     # 0xb7868
callq 0x84d0
movq %rax, -0x190(%rbp)
jmp 0xa1ab6
movq -0x10(%rbp), %rdi
callq 0x63b50
movl %eax, -0x194(%rbp)
jmp 0xa1ac7
movl -0x194(%rbp), %esi
movq -0x190(%rbp), %rdi
callq 0x8860
movq %rax, -0x1a0(%rbp)
jmp 0xa1ae2
movq -0x1a0(%rbp), %rdi
leaq 0x11ac7(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0xa1af7
movq -0x168(%rbp), %rax
movb $0x0, 0xa0(%rax)
movl $0x1, -0xac(%rbp)
jmp 0xa1e51
movq -0x10(%rbp), %rdi
callq 0x51cb0
movq %rax, -0x1a8(%rbp)
jmp 0xa1b26
movq -0x168(%rbp), %rax
movq -0x1a8(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x3b730
movq -0x1b8(%rbp), %rdi
movq %rax, -0xd0(%rbp)
callq 0x3b760
movq %rax, -0xd8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
callq 0xa3c20
movq %rax, -0x1b0(%rbp)
jmp 0xa1bb6
movq -0x1b0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3bb00
movq -0x1c0(%rbp), %rdi
movq (%rax), %rsi
callq 0x51d10
jmp 0xa1bec
movq -0x168(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
leaq -0x100(%rbp), %rdi
callq 0xa3c90
jmp 0xa1c08
leaq -0x100(%rbp), %rdi
callq 0x3ec00
testb $0x1, %al
jne 0xa1c1d
jmp 0xa1cb4
movq 0x5f374(%rip), %rdi     # 0x100f98
leaq 0x15c5f(%rip), %rsi     # 0xb788a
callq 0x84d0
movq %rax, -0x1c8(%rbp)
jmp 0xa1c39
movq -0x10(%rbp), %rdi
callq 0x63b50
movl %eax, -0x1cc(%rbp)
jmp 0xa1c4a
movl -0x1cc(%rbp), %esi
movq -0x1c8(%rbp), %rdi
callq 0x8860
movq %rax, -0x1d8(%rbp)
jmp 0xa1c65
movq -0x1d8(%rbp), %rdi
leaq 0x11944(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0xa1c7a
movq -0x168(%rbp), %rax
movb $0x0, 0xa0(%rax)
movl $0x1, -0xac(%rbp)
jmp 0xa1e45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xd7d0
jmp 0xa1e6c
movq -0x168(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x39b60
movq -0x1e8(%rbp), %rdi
movq %rax, -0x110(%rbp)
callq 0x399f0
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
movq -0x118(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0x8be30
movq %rax, -0x1e0(%rbp)
jmp 0xa1d05
movq -0x168(%rbp), %rdi
movq -0x1e0(%rbp), %rax
movq %rax, -0x108(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0x128(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x62750
movq %rax, -0x1f0(%rbp)
jmp 0xa1d54
movq -0x168(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, -0x11c(%rbp)
addq $0x88, %rdi
movq %rdi, -0x210(%rbp)
movslq -0x11c(%rbp), %rsi
callq 0xda70
movq -0x210(%rbp), %rdi
movq %rax, -0x200(%rbp)
movslq -0x11c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
callq 0x3b760
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3f680
leaq -0x100(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3b730
movq %rax, -0x150(%rbp)
leaq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x413f0
movq -0x208(%rbp), %rdi
movq %rax, -0x148(%rbp)
callq 0x3b760
movq -0x200(%rbp), %rdi
movq %rax, -0x158(%rbp)
movq -0x138(%rbp), %rsi
movq -0x148(%rbp), %rdx
movq -0x158(%rbp), %rcx
callq 0xa54a0
movq %rax, -0x1f8(%rbp)
jmp 0xa1e2d
movq -0x1f8(%rbp), %rax
movq %rax, -0x160(%rbp)
movl $0x0, -0xac(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xd7d0
leaq -0x48(%rbp), %rdi
callq 0xdd90
leaq -0x30(%rbp), %rdi
callq 0xd7d0
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0xdd90
leaq -0x30(%rbp), %rdi
callq 0xd7d0
movq -0x50(%rbp), %rdi
callq 0x8880
nopw (%rax,%rax)