// File: Kei18[P]pibt/./src/solver/ecbs.cpp
// Function: ECBS::invoke(CTNode*, std::vector<Agent*, std::allocator<Agent*>>&)
void ECBS::invoke(CTNode* node, Agents& block) {
  int d;
  // calc path
  if (node->c.empty()) {  // initail
    Paths paths;
    for (int i = 0; i < A.size(); ++i) {
      paths.push_back({});
      node->fmins.push_back(0);
    }
    for (auto a : block) {
      auto itr = std::find_if(A.begin(), A.end(),
                              [a](Agent* b) { return a == b; });
      int d = std::distance(A.begin(), itr);
      paths[d] = AstarSearch(a, node);
      node->fmins[d] = table_fmin.at(a->getId());
    }
    node->paths = paths;
    node->LB = 0;
  } else {
    Agent* a;
    // error check
    if (node->paths.size() != A.size()) {
      std::cout << "error@ECBS@invoke, "
                << "path size is not equal to the size of agents" << "\n";
      std::exit(1);
    }

    for (auto c : node->c) {
      a = c->a;
      auto itr = std::find_if(A.begin(), A.end(),
                              [a](Agent* b) { return a == b; });
      if (itr == A.end()) {
        std::cout << "error@ECBS@invoke, cannot find1 agent" << "\n";
        std::exit(1);
      }
      d = std::distance(A.begin(), itr);
      node->paths[d].clear();
    }

    for (auto c : node->c) {
      a = c->a;
      auto itr = std::find_if(A.begin(), A.end(),
                              [a](Agent* b) { return a == b; });
      if (itr == A.end()) {
        std::cout << "error@ECBS@invoke, cannot find2 agent" << "\n";
        std::exit(1);
      }
      d = std::distance(A.begin(), itr);
      node->paths[d] = AstarSearch(a, node);
      node->fmins[d] = table_fmin.at(a->getId());
    }
  }
  for (auto i : node->fmins) node->LB += i;

  if (!node->valid) return;
  calcCost(node, block);
  formalizePathAgents(node, block);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x62fa0
testb $0x1, %al
jne 0x707e4
jmp 0x70ad9
leaq -0x38(%rbp), %rdi
callq 0xd9c0
movl $0x0, -0x3c(%rbp)
movq -0x1e8(%rbp), %rdi
movslq -0x3c(%rbp), %rax
movq %rax, -0x1f0(%rbp)
addq $0x20, %rdi
callq 0x383b0
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
jae 0x708b1
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x3e880
movq -0x1f8(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xd700
jmp 0x70853
leaq -0x60(%rbp), %rdi
callq 0xd7d0
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movl $0x0, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x536f0
jmp 0x70876
jmp 0x70878
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x707f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd7d0
jmp 0x70acb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x70acb
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x39b60
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x399f0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x51bd0
testb $0x1, %al
jne 0x708ef
jmp 0x70a9f
leaq -0x80(%rbp), %rdi
callq 0x51c10
movq -0x1e8(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x90(%rbp)
addq $0x20, %rdi
movq %rdi, -0x208(%rbp)
callq 0x39b60
movq -0x208(%rbp), %rdi
movq %rax, -0xa0(%rbp)
callq 0x399f0
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x70fc0
movq %rax, -0x200(%rbp)
jmp 0x70964
movq -0x1e8(%rbp), %rdi
movq -0x200(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0xc0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x62750
movq %rax, -0x210(%rbp)
jmp 0x709b3
movq -0x1e8(%rbp), %rsi
movq -0x210(%rbp), %rax
movl %eax, -0xb4(%rbp)
movq -0x90(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq (%rsi), %rax
movq 0x28(%rax), %rax
leaq -0xe0(%rbp), %rdi
callq *%rax
jmp 0x709e4
movslq -0xb4(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xda70
movq %rax, %rdi
leaq -0xe0(%rbp), %rsi
movq %rsi, -0x228(%rbp)
callq 0x3f230
movq -0x228(%rbp), %rdi
callq 0xd7d0
movq -0x1e8(%rbp), %rax
addq $0xb0, %rax
movq %rax, -0x220(%rbp)
movq -0x90(%rbp), %rdi
callq 0x63b50
movl %eax, -0x214(%rbp)
jmp 0x70a3e
movq -0x220(%rbp), %rdi
movl -0x214(%rbp), %eax
movl %eax, -0xe4(%rbp)
leaq -0xe4(%rbp), %rsi
callq 0x74640
movq %rax, -0x230(%rbp)
jmp 0x70a66
movq -0x230(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x234(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0x4ea00
movl -0x234(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x80(%rbp), %rdi
callq 0x51c30
jmp 0x708d6
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x38(%rbp), %rsi
callq 0x62fe0
jmp 0x70ab2
movq -0x10(%rbp), %rax
movl $0x0, 0x60(%rax)
leaq -0x38(%rbp), %rdi
callq 0xda10
jmp 0x70ef9
leaq -0x38(%rbp), %rdi
callq 0xda10
jmp 0x70fb6
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x37930
movq -0x1e8(%rbp), %rdi
movq %rax, -0x240(%rbp)
addq $0x20, %rdi
callq 0x383b0
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
je 0x70b47
movq 0x90485(%rip), %rdi     # 0x100f98
leaq 0x44da8(%rip), %rsi     # 0xb58c2
callq 0x84d0
movq %rax, %rdi
leaq 0x44dad(%rip), %rsi     # 0xb58d6
callq 0x84d0
movq %rax, %rdi
leaq 0x42a7f(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x63230
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x63260
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x63290
testb $0x1, %al
jne 0x70b94
jmp 0x70cd9
leaq -0x100(%rbp), %rdi
callq 0x632d0
movq -0x1e8(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq -0x1e8(%rbp), %rdi
movq %rax, -0x120(%rbp)
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0x128(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
movq -0x130(%rbp), %rdx
callq 0x71020
movq -0x1e8(%rbp), %rdi
movq %rax, -0x118(%rbp)
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0x138(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x55800
testb $0x1, %al
jne 0x70c48
jmp 0x70c74
movq 0x90349(%rip), %rdi     # 0x100f98
leaq 0x44cad(%rip), %rsi     # 0xb5903
callq 0x84d0
movq %rax, %rdi
leaq 0x42952(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x1e8(%rbp), %rdi
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0x140(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x140(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x62750
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movslq -0x1c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
callq 0x3e9f0
leaq -0x100(%rbp), %rdi
callq 0x632f0
jmp 0x70b78
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x63230
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
callq 0x63260
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x63290
testb $0x1, %al
jne 0x70d26
jmp 0x70ef7
leaq -0x158(%rbp), %rdi
callq 0x632d0
movq -0x1e8(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq -0x1e8(%rbp), %rdi
movq %rax, -0x178(%rbp)
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0x180(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x178(%rbp), %rdi
movq -0x180(%rbp), %rsi
movq -0x188(%rbp), %rdx
callq 0x71080
movq -0x1e8(%rbp), %rdi
movq %rax, -0x170(%rbp)
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0x190(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x55800
testb $0x1, %al
jne 0x70dda
jmp 0x70e06
movq 0x901b7(%rip), %rdi     # 0x100f98
leaq 0x44b41(%rip), %rsi     # 0xb5929
callq 0x84d0
movq %rax, %rdi
leaq 0x427c0(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x1e8(%rbp), %rdi
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0x198(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x198(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
callq 0x62750
movq -0x1e8(%rbp), %rsi
movl %eax, -0x1c(%rbp)
movq -0xf0(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq (%rsi), %rax
leaq -0x1b8(%rbp), %rdi
callq *0x28(%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movslq -0x1c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x3f230
leaq -0x1b8(%rbp), %rdi
callq 0xd7d0
movq -0x1e8(%rbp), %rax
addq $0xb0, %rax
movq %rax, -0x250(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x63b50
movq -0x250(%rbp), %rdi
movl %eax, -0x1bc(%rbp)
leaq -0x1bc(%rbp), %rsi
callq 0x74640
movl (%rax), %eax
movl %eax, -0x244(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x4ea00
movl -0x244(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x158(%rbp), %rdi
callq 0x632f0
jmp 0x70d0a
jmp 0x70ef9
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x4f9b0
movq %rax, -0x1d0(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x4f840
movq %rax, -0x1d8(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x53740
testb $0x1, %al
jne 0x70f47
jmp 0x70f79
leaq -0x1d0(%rbp), %rdi
callq 0x53a50
movl (%rax), %eax
movl %eax, -0x1dc(%rbp)
movl -0x1dc(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x60(%rax), %ecx
movl %ecx, 0x60(%rax)
leaq -0x1d0(%rbp), %rdi
callq 0x53a80
jmp 0x70f2e
movq -0x10(%rbp), %rax
testb $0x1, 0x40(%rax)
jne 0x70f85
jmp 0x70fad
movq -0x1e8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x5a7c0
movq -0x1e8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x5aa20
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x8880
nop