// File: /workspace/github_cpp_makefile_star2_O1/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, 0x6c(%rsp)
movq %rdi, %rbx
movq %rsi, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x10(%rdi), %rsi
addq $0x30, %rsi
leaq 0x70(%rsp), %rdi
callq 0xb59c
movq 0x70(%rbx), %r12
movq %rbx, 0x18(%rsp)
movq 0x78(%rbx), %rax
movq %rax, 0x40(%rsp)
cmpq %rax, %r12
je 0x40f0f
leaq 0x48(%rsp), %r14
movq (%r12), %rax
movq %rax, 0x60(%rsp)
movq 0x70(%rsp), %r15
movq 0x78(%rsp), %rbx
movq %rax, 0x48(%rsp)
movq %rbx, %rbp
subq %r15, %rbp
sarq $0x5, %rbp
testq %rbp, %rbp
jle 0x40d65
incq %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbb
leaq 0x8(%r15), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbe
leaq 0x10(%r15), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbe
leaq 0x18(%r15), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbe
addq $0x20, %r15
decq %rbp
cmpq $0x1, %rbp
jg 0x40d08
movq %rbx, %rax
subq %r15, %rax
sarq $0x3, %rax
cmpq $0x1, %rax
je 0x40daa
cmpq $0x2, %rax
je 0x40d97
movq %rbx, %r13
cmpq $0x3, %rax
jne 0x40dbe
movq %r14, %rdi
movq %r15, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbb
addq $0x8, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x42848
testb %al, %al
jne 0x40dbb
addq $0x8, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x42848
testb %al, %al
cmoveq %rbx, %r15
movq %r15, %r13
cmpq %rbx, %r13
jne 0x40f00
movq 0x18(%rsp), %rax
movq 0x88(%rax), %r13
movq 0x90(%rax), %rbp
movq 0x60(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbp, %rbx
subq %r13, %rbx
sarq $0x3, %rbx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rbx
sarq $0x2, %rbx
testq %rbx, %rbx
jle 0x40e69
incq %rbx
movq %r14, %rdi
movq %r13, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ecd
leaq 0x18(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ed0
leaq 0x30(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ed0
leaq 0x48(%r13), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ed0
addq $0x60, %r13
decq %rbx
cmpq $0x1, %rbx
jg 0x40e08
movq %rbp, %rax
subq %r13, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq $0x1, %rax
je 0x40ebc
cmpq $0x2, %rax
je 0x40ea9
movq %rbp, %r15
cmpq $0x3, %rax
jne 0x40ed0
movq %r14, %rdi
movq %r13, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ecd
addq $0x18, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x428e2
testb %al, %al
jne 0x40ecd
addq $0x18, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x428e2
testb %al, %al
cmoveq %rbp, %r13
movq %r13, %r15
cmpq %rbp, %r15
jne 0x40f00
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x40ef1
movq 0x60(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0x40f00
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x1c69a
addq $0x8, %r12
cmpq 0x40(%rsp), %r12
jne 0x40cde
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r14
cmpq %r14, %rsi
je 0x40f83
leaq 0x8(%rsi), %rbx
cmpq %r14, %rbx
je 0x40fd3
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r15
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rbp
movq (%rbx), %rdx
movq %rsi, 0x40(%rsp)
movq (%rsi), %r12
movq (%rbp), %rax
movq %rbp, %rdi
movq %r15, %rsi
callq *0x10(%rax)
movl %eax, %r13d
movq (%rbp), %rax
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x10(%rax)
movq %rbx, %rcx
cmpl %eax, %r13d
jl 0x40f75
movq 0x40(%rsp), %rcx
addq $0x8, %rbx
movq %rcx, %rsi
cmpq %r14, %rbx
jne 0x40f3d
jmp 0x40fd6
movq 0x2101e(%rip), %rdi     # 0x61fa8
leaq 0xadd7(%rip), %rsi      # 0x4bd68
movl $0x21, %edx
callq 0x63f0
movq 0x10(%rsp), %rax
movl (%rax), %esi
movq 0x20fff(%rip), %rdi     # 0x61fa8
callq 0x6610
leaq 0x75ae(%rip), %rsi      # 0x48563
movl $0x1, %edx
movq %rax, %rdi
callq 0x63f0
movq 0x18(%rsp), %rax
movb $0x0, 0xa0(%rax)
jmp 0x410b5
movq %rsi, %rcx
movq 0x10(%rsp), %rdx
movq (%rcx), %rax
movq %rax, 0x10(%rdx)
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %r8
movl $0x1, (%rsp)
leaq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
movl 0x6c(%rsp), %r9d
callq 0x41c8e
movq 0x48(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x41058
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rsi
leaq 0x10(%rsp), %rdx
callq 0x38b4d
subq 0x20(%rbx), %rax
shrq $0x3, %rax
cltq
movq 0x88(%rbx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
addq $0x8, %rdx
callq 0x42a62
jmp 0x4109e
movq 0x20f49(%rip), %rdi     # 0x61fa8
leaq 0xad24(%rip), %rsi      # 0x4bd8a
movl $0x1a, %edx
callq 0x63f0
movq 0x10(%rsp), %rax
movl (%rax), %esi
movq 0x20f2a(%rip), %rdi     # 0x61fa8
callq 0x6610
leaq 0x74d9(%rip), %rsi      # 0x48563
movl $0x1, %edx
movq %rax, %rdi
callq 0x63f0
movb $0x0, 0xa0(%rbx)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x410b5
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x410cf
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x410e6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x410fe
jmp 0x410fe
jmp 0x41127
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x4112a
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x4112a
movq %rax, %rbx
jmp 0x41144
jmp 0x41127
jmp 0x41127
jmp 0x41127
jmp 0x41127
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x41144
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4115b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %rbx, %rdi
callq 0x6620
nop