// File: /workspace/github_cpp_makefile_star2_O3/Kei18[P]pibt/./src/solver/tp.cpp
// Function: TP::getPickDelivPath(Agent*, Node*, Node*, Node*, int, bool)
Nodes TP::getPickDelivPath(Agent* a,
                           Node* s,
                           Node* g1,
                           Node* g2,
                           int startTime,
                           bool futureCollision)
{
  Nodes path;
  Nodes C;
  AN2 *l, *n;
  int t, f, cost;
  std::string key;
  bool prohibited, goalCheck;

  Nodes pathends;
  Node* v;
  for (auto p : paths) {
    v = p[p.size() - 1];
    if (v != s && v != a->getNode()) pathends.push_back(v);
  }
  int cost_g1tog2 = pathDist(g1, g2, pathends);

  std::unordered_set<std::string> OPEN;
  std::unordered_map<std::string, AN2*> table;

  t = startTime - 1;
  l = new AN2 { s, g1, true, startTime - 1,
                pathDist(s, g1) + cost_g1tog2,
                nullptr };
  key = getKey(t, s);
  table.emplace(key, l);
  OPEN = { key };

  while (!OPEN.empty()) {
    // argmin
    auto itr1 = std::min_element(OPEN.begin(), OPEN.end(),
                                 [&table] (std::string a, std::string b)
                                 { auto eleA = table.at(a);
                                   auto eleB = table.at(b);
                                   if (eleA->f == eleB->f) {
                                     return eleA->t > eleB->t;
                                   }
                                   return eleA->f < eleB->f;
                                 });
    key = *itr1;
    n = table.at(key);
    t = n->t;

    // check goal
    if (n->v == n->g && n->g == g2) {
      goalCheck = true;

      if (futureCollision) {
        for (auto p : paths) {
          if (t + 1 >= p.size()) continue;

          for (auto itr = p.begin() + t + 1; itr < p.end(); ++itr) {
            if ((*itr) == n->v) {  // collision in future
              goalCheck = false;
              break;
            }
          }
          if (!goalCheck) break;
        }
      }

      if (goalCheck) break;

    } else if (n->v == n->g && n->g == g1) {
      n->g = g2;  // next target
    }

    // update list
    n->open = false;
    OPEN.erase(itr1);

    // search neighbor
    C = { n->v };
    for (auto u : G->neighbor(n->v)) {
      if (!inArray(u, pathends)) C.push_back(u);
    }

    for (auto m : C) {
      t = n->t + 1;

      if (t > 0) {
        prohibited = false;

        for (auto p : paths) {
          if (t + 1 > p.size()) continue;
          if (p[t] == m) { // collision
            prohibited = true;
            break;
          }
          if (p[t] == n->v && p[t-1] == m) {  // intersection
            prohibited = true;
            break;
          }
        }

        if (prohibited) continue;
      }

      key = getKey(t, m);
      auto itr2 = table.find(key);
      if (itr2 == table.end()) {
        table.emplace(key, new AN2 { m, n->g, true, t, 100000, n });
      }
      l = table.at(key);
      if (!l->open) continue;

      // cost = pathDist(m, n->g, pathends);
      cost = pathDist(m, n->g);
      f = t + cost;
      if (n->g == g1) f += cost_g1tog2;

      if (l->f > f) {
        l->t = t;
        l->f = f;
        l->p = n;
      }

      OPEN.insert(key);
    }
  }

  // back tracking
  if (n->v == g2) {  // check failed or not
    while (n->p) {
      path.push_back(n->v);
      n = n->p;
    }
    path.push_back(s);
    std::reverse(path.begin(), path.end());
  }

  return path;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %r9, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, %rbx
movq %rcx, 0xc8(%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movq %rdi, 0x30(%rsp)
movups %xmm0, (%rdi)
movq %rax, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movq %rax, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq 0x88(%rsi), %r15
movq %rsi, 0x28(%rsp)
movq 0x90(%rsi), %r13
cmpq %r13, %r15
je 0x4110b
movq %rdx, %r14
leaq 0xf0(%rsp), %r12
leaq 0x138(%rsp), %rbp
movq %r12, %rdi
movq %r15, %rsi
callq 0x19aae
movq 0xf8(%rsp), %rax
movq -0x8(%rax), %rax
movq %rax, 0x138(%rsp)
cmpq %rbx, %rax
je 0x410e5
cmpq 0x8(%r14), %rax
je 0x410e5
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x410d8
movq %rax, (%rsi)
addq $0x8, 0x68(%rsp)
jmp 0x410e5
leaq 0x60(%rsp), %rdi
movq %rbp, %rdx
callq 0x1c5cc
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x41102
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %r15
cmpq %r13, %r15
jne 0x41097
leaq 0x60(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x3f284
movl %eax, 0x44(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0x170(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movl $0x28, %edi
callq 0x6370
movq %rax, %r14
movl 0x1b0(%rsp), %ebp
decl %ebp
movq %rbx, (%rax)
movq 0x50(%rsp), %rdx
movq %rdx, 0x8(%rax)
movb $0x1, 0x10(%rax)
movl %ebp, 0x14(%rax)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x3efbe
addl 0x44(%rsp), %eax
movl %eax, 0x18(%r14)
movq $0x0, 0x20(%r14)
movq %r14, 0xb8(%rsp)
movq %rsp, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x3f2d8
leaq 0x80(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x6460
movq (%rbx), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x411f3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6380
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x4340c
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
callq 0xb810
leaq 0xf0(%rsp), %rdi
movq %rsp, %rsi
movl $0x1, %edx
callq 0x42da4
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x41263
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6380
cmpq $0x0, 0x108(%rsp)
je 0x41808
movq %rsp, %r13
movq 0x100(%rsp), %r14
testq %r14, %r14
je 0x4138b
movq (%r14), %rbx
testq %rbx, %rbx
je 0x41390
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xb810
leaq 0xe0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq 0xd0(%rsp), %rdi
callq 0xb810
leaq 0x140(%rsp), %rdi
movq %r13, %rsi
callq 0x437f8
testq %rax, %rax
je 0x4195a
movq 0x28(%rax), %r15
leaq 0x140(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x437f8
testq %rax, %rax
je 0x4195a
movq 0x28(%rax), %rax
movl 0x18(%rax), %ecx
cmpl %ecx, 0x18(%r15)
jne 0x4132b
movl 0x14(%r15), %ecx
cmpl 0x14(%rax), %ecx
setg %bpl
jmp 0x4132f
setl %bpl
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x41354
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x6380
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4136f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6380
movq %rbx, %r12
testb %bpl, %bpl
jne 0x4137a
movq %r14, %r12
movq (%rbx), %rbx
movq %r12, %r14
testq %rbx, %rbx
jne 0x41292
jmp 0x41393
xorl %r12d, %r12d
jmp 0x41393
movq %r14, %r12
leaq 0x8(%r12), %rsi
leaq 0x80(%rsp), %rdi
callq 0x6200
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x437f8
testq %rax, %rax
je 0x41972
movq 0x28(%rax), %r15
movq 0x8(%r15), %rax
movq (%r15), %rcx
xorq %rax, %rcx
movq %rax, %rdx
xorq 0x48(%rsp), %rdx
orq %rcx, %rdx
movq %r15, 0x38(%rsp)
jne 0x414cd
cmpb $0x0, 0x1b8(%rsp)
je 0x41808
movq 0x28(%rsp), %rax
movq 0x88(%rax), %rbp
movq 0x90(%rax), %rbx
cmpq %rbx, %rbp
je 0x41808
movslq 0x14(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
shlq $0x3, %rax
movq %rax, 0x58(%rsp)
movb $0x1, %r14b
movq %r13, %rdi
movq %rbp, %rsi
callq 0x19aae
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
movl $0x7, %r15d
cmpq 0x20(%rsp), %rcx
jbe 0x41493
movq 0x58(%rsp), %rcx
addq %rdi, %rcx
addq $0x8, %rcx
movq 0x38(%rsp), %rsi
movl %r14d, %r8d
cmpq %rax, %rcx
jae 0x4147d
movq (%rcx), %rdx
addq $0x8, %rcx
cmpq (%rsi), %rdx
jne 0x41469
xorl %r8d, %r8d
movl %r8d, %r14d
testb $0x1, %r8b
movl $0x6, %r15d
movl $0x0, %eax
cmovnel %eax, %r15d
testq %rdi, %rdi
je 0x414a5
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
cmpl $0x7, %r15d
je 0x414b0
testl %r15d, %r15d
jne 0x414bd
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x4142a
testb $0x1, %r14b
movq 0x38(%rsp), %r15
je 0x414e0
jmp 0x41808
xorq 0x50(%rsp), %rax
orq %rax, %rcx
jne 0x414e0
movq 0x48(%rsp), %rax
movq %rax, 0x8(%r15)
movb $0x0, 0x10(%r15)
leaq 0xf0(%rsp), %rdi
movq %r12, %rsi
callq 0x43170
movq (%r15), %rax
movq %rax, (%rsp)
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
leaq 0x8(%rsp), %rdx
callq 0x3dd40
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rsi
movq (%r15), %rdx
movq %r13, %rdi
callq 0x1a38a
movq (%rsp), %r14
movq 0x8(%rsp), %rbx
cmpq %rbx, %r14
je 0x415ae
movq (%r14), %rax
movq %rax, 0xc0(%rsp)
movq %rax, 0xd0(%rsp)
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x19b2e
cmpq 0x68(%rsp), %rax
jne 0x415a1
movq 0xa8(%rsp), %rsi
cmpq 0xb0(%rsp), %rsi
je 0x4158c
movq 0xc0(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0xa8(%rsp)
jmp 0x415a1
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x1c5cc
addq $0x8, %r14
cmpq %rbx, %r14
jne 0x41533
movq (%rsp), %r14
testq %r14, %r14
je 0x415c3
movq 0x10(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x6380
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rcx, 0x128(%rsp)
cmpq %rcx, %rax
je 0x417f7
movq %r13, %r12
movq %rax, 0x130(%rsp)
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movl 0x14(%r15), %r15d
leal 0x1(%r15), %eax
movl %eax, 0x58(%rsp)
testl %r15d, %r15d
js 0x41691
movq 0x28(%rsp), %rax
movq 0x88(%rax), %r14
movq 0x90(%rax), %rbp
cmpq %rbp, %r14
je 0x41691
leaq 0x2(%r15), %r13
movl 0x58(%rsp), %ebx
movq %r12, %rdi
movq %r14, %rsi
callq 0x19aae
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
cmpq %r13, %rax
jae 0x41653
testq %rdi, %rdi
jne 0x4167b
jmp 0x41688
movq (%rdi,%rbx,8), %rax
cmpq 0x20(%rsp), %rax
je 0x417c8
movq 0x38(%rsp), %rcx
cmpq (%rcx), %rax
jne 0x4167b
movq 0x20(%rsp), %rax
cmpq %rax, (%rdi,%r15,8)
je 0x417c8
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %r14
cmpq %rbp, %r14
jne 0x4162c
movq %r12, %r13
movq %r12, %rdi
movl 0x58(%rsp), %ebx
movl %ebx, %esi
movq 0x20(%rsp), %rdx
callq 0x3f2d8
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x6460
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x416d2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6380
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x437f8
movq 0x38(%rsp), %r15
testq %rax, %rax
jne 0x41739
movl $0x28, %edi
callq 0x6370
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x8(%r15), %rcx
movq %rcx, 0x8(%rax)
movb $0x1, 0x10(%rax)
movl %ebx, 0x14(%rax)
movl $0x186a0, 0x18(%rax)    # imm = 0x186A0
movq %r15, 0x20(%rax)
movq %rax, (%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
callq 0x43832
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x437f8
testq %rax, %rax
je 0x41966
movq 0x28(%rax), %rax
movq %rax, 0xb8(%rsp)
cmpb $0x1, 0x10(%rax)
jne 0x417dd
movq 0x8(%r15), %rdx
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3efbe
addl %ebx, %eax
movq 0x50(%rsp), %rcx
cmpq %rcx, 0x8(%r15)
movl $0x0, %ecx
cmovel 0x44(%rsp), %ecx
addl %eax, %ecx
movq 0xb8(%rsp), %rax
cmpl %ecx, 0x18(%rax)
jle 0x417aa
movl %ebx, 0x14(%rax)
movl %ecx, 0x18(%rax)
movq %r15, 0x20(%rax)
leaq 0xf0(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
callq 0x43356
jmp 0x417dd
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %r12, %r13
movq 0x38(%rsp), %r15
movq 0x130(%rsp), %rax
addq $0x8, %rax
cmpq 0x128(%rsp), %rax
jne 0x415e4
cmpq $0x0, 0x108(%rsp)
jne 0x41275
jmp 0x41808
movq 0x48(%rsp), %rax
cmpq %rax, (%r15)
jne 0x418d0
cmpq $0x0, 0x20(%r15)
je 0x41853
leaq 0x20(%r15), %rbx
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4183d
movq (%r15), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x41845
movq %r15, %rdx
callq 0x1c5cc
movq (%rbx), %r15
leaq 0x20(%r15), %rbx
cmpq $0x0, 0x20(%r15)
jne 0x41821
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4187b
movq 0xc8(%rsp), %rax
movq %rax, (%rsi)
movq 0x8(%rdi), %rax
addq $0x8, %rax
movq %rax, 0x8(%rdi)
jmp 0x41891
leaq 0xc8(%rsp), %rdx
callq 0x1c5cc
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rax
movq (%rdi), %rcx
cmpq %rax, %rcx
setne %dl
addq $-0x8, %rax
cmpq %rcx, %rax
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x418d0
addq $0x8, %rcx
movq -0x8(%rcx), %rdx
movq (%rax), %rsi
movq %rsi, -0x8(%rcx)
movq %rdx, (%rax)
addq $-0x8, %rax
leaq 0x8(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x418b2
leaq 0x140(%rsp), %rdi
callq 0x4275e
leaq 0xf0(%rsp), %rdi
callq 0x2ae7e
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x41901
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x41926
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6380
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x41943
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x30(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8bba(%rip), %rdi      # 0x4a51b
callq 0x6520
leaq 0x8bae(%rip), %rdi      # 0x4a51b
callq 0x6520
leaq 0x8ba2(%rip), %rdi      # 0x4a51b
callq 0x6520
jmp 0x419e5
jmp 0x41a4d
jmp 0x41a4d
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
jmp 0x41a44
jmp 0x419d5
jmp 0x41a4d
jmp 0x41a4d
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x41a6a
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x41a6a
jmp 0x41a4d
jmp 0x41a4d
jmp 0x41a4d
movq %rax, %rbx
jmp 0x41a6a
jmp 0x41a4d
jmp 0x41a4d
jmp 0x41a4d
jmp 0x41a4d
movq %rax, %rbx
jmp 0x41a2e
jmp 0x41a4d
jmp 0x41a4d
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x41a50
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
jmp 0x41a44
jmp 0x41a06
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x41a2e
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x6380
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x41a50
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6380
jmp 0x41a50
jmp 0x41a4d
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x4275e
leaq 0xf0(%rsp), %rdi
callq 0x2ae7e
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x41a81
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x41aa6
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6380
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x41ac3
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x41adc
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x6380
movq %rbx, %rdi
callq 0x6620