// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, 0x2c(%rsp)
movq %rdi, %rbx
movq %rsi, 0x20(%rsp)
andq $0x0, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x10(%rdi), %rsi
addq $0x30, %rsi
leaq 0x70(%rsp), %rdi
callq 0x9398
movq 0x70(%rbx), %rax
movq %rbx, 0x8(%rsp)
movq 0x78(%rbx), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x30(%rsp), %r14
cmpq 0x10(%rsp), %rax
je 0x34346
movq %rax, 0x18(%rsp)
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x70(%rsp), %r13
movq 0x78(%rsp), %rbx
movq %rax, 0x30(%rsp)
movq %rbx, %r12
subq %r13, %r12
movq %r12, %rbp
sarq $0x5, %rbp
testq %rbp, %rbp
jle 0x341da
movq %r14, %rdi
movq %r13, %rsi
callq 0x3545a
testb %al, %al
jne 0x34227
leaq 0x8(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3545a
testb %al, %al
jne 0x3422a
leaq 0x10(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3545a
testb %al, %al
jne 0x3422a
leaq 0x18(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3545a
testb %al, %al
jne 0x3422a
addq $0x20, %r13
decq %rbp
addq $-0x20, %r12
jmp 0x34178
sarq $0x3, %r12
cmpq $0x1, %r12
je 0x34216
cmpq $0x2, %r12
je 0x34203
cmpq $0x3, %r12
jne 0x34233
movq %r14, %rdi
movq %r13, %rsi
callq 0x3545a
testb %al, %al
jne 0x34227
addq $0x8, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x3545a
testb %al, %al
jne 0x34227
addq $0x8, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x3545a
testb %al, %al
cmoveq %rbx, %r13
movq %r13, %r15
cmpq %rbx, %r15
jne 0x34338
movq 0x8(%rsp), %rax
movq 0x88(%rax), %r12
movq 0x90(%rax), %rbx
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbx, %rbp
subq %r12, %rbp
movq %rbp, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %r15
sarq $0x2, %r15
testq %r15, %r15
jle 0x342cd
movq %r14, %rdi
movq %r12, %rsi
callq 0x354cc
testb %al, %al
jne 0x34321
leaq 0x18(%r12), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x354cc
testb %al, %al
jne 0x34324
leaq 0x30(%r12), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x354cc
testb %al, %al
jne 0x34324
leaq 0x48(%r12), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x354cc
testb %al, %al
jne 0x34324
addq $0x60, %r12
decq %r15
addq $-0x60, %rbp
jmp 0x34268
movq %rbp, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq $0x1, %rax
je 0x34310
cmpq $0x2, %rax
je 0x342fd
cmpq $0x3, %rax
jne 0x34329
movq %r14, %rdi
movq %r12, %rsi
callq 0x354cc
testb %al, %al
jne 0x34321
addq $0x18, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x354cc
testb %al, %al
jne 0x34321
addq $0x18, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x354cc
testb %al, %al
cmoveq %rbx, %r12
movq %r12, %r13
cmpq %rbx, %r13
jne 0x34338
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x171da
movq 0x18(%rsp), %rax
addq $0x8, %rax
jmp 0x34144
movq 0x50(%rsp), %r14
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq %rax, %r14
je 0x34432
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rax), %r15
movq 0x8(%rsp), %rax
movq 0x38(%rax), %r12
leaq 0x8(%r14), %rbx
cmpq 0x18(%rsp), %rbx
je 0x343b8
movq (%rbx), %rdx
movq (%r14), %r13
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x10(%rax)
movl %eax, %ebp
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq *0x10(%rax)
movq %rbx, %rcx
cmpl %eax, %ebp
jl 0x343af
movq %r14, %rcx
addq $0x8, %rbx
movq %rcx, %r14
jmp 0x34379
movq (%r14), %rax
movq 0x10(%rsp), %r14
movq %rax, 0x10(%r14)
leaq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
movl 0x2c(%rsp), %ecx
callq 0x3538c
movq 0x30(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x34471
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2dcba
subq 0x20(%rbx), %rax
shrq $0x3, %rax
cltq
movq 0x88(%rbx), %rcx
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rdi
movq 0x8(%rcx,%rax), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
addq $0x8, %rdx
callq 0x35502
jmp 0x344a5
movq 0x25b5f(%rip), %rdi     # 0x59f98
leaq 0x9e98(%rip), %rsi      # 0x3e2d8
callq 0x63a0
movq 0x20(%rsp), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x6630
leaq 0x6108(%rip), %rsi      # 0x3a563
movq %rax, %rdi
callq 0x63a0
movq 0x8(%rsp), %rax
movb $0x0, 0xa0(%rax)
jmp 0x344af
movq 0x25b20(%rip), %rdi     # 0x59f98
leaq 0x9e7b(%rip), %rsi      # 0x3e2fa
callq 0x63a0
movl (%r14), %esi
movq %rax, %rdi
callq 0x6630
leaq 0x60cd(%rip), %rsi      # 0x3a563
movq %rax, %rdi
callq 0x63a0
movb $0x0, 0xa0(%rbx)
leaq 0x30(%rsp), %rdi
callq 0x990e
leaq 0x70(%rsp), %rdi
callq 0x154b6
leaq 0x50(%rsp), %rdi
callq 0x990e
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x344db
jmp 0x344db
jmp 0x344f7
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x990e
jmp 0x344fa
movq %rax, %rbx
jmp 0x34504
jmp 0x344f7
jmp 0x344f7
jmp 0x344f7
jmp 0x344f7
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x154b6
leaq 0x50(%rsp), %rdi
callq 0x990e
movq %rbx, %rdi
callq 0x6650