// File: Kei18[P]pibt/./src/solver/cbs.cpp
// Function: CBS::checkAgents(std::vector<std::vector<Node*, std::allocator<Node*>>, std::allocator<std::vector<Node*, std::allocator<Node*>>>>&, std::vector<std::vector<Agent*, std::allocator<Agent*>>, std::allocator<std::vector<Agent*, std::allocator<Agent*>>>>&)
bool CBS::checkAgents(Paths& paths, std::vector<Agents>& whole) {
  int maxLength = getMaxLengthPaths(paths);
  std::vector<Agents> OPEN = whole;
  std::vector<Agents> CLOSE, TMP;
  Agents block1, block2;
  int i, j;
  bool checkAll = true;
  bool checkPart, checkFrac;
  whole.clear();

  while (!OPEN.empty()) {
    block1 = OPEN[0];
    openToClose(block1, OPEN, CLOSE);

    checkFrac = true;
    for (auto block2 : OPEN) {

      checkPart = true;
      for (auto a : block1) {
        if (!checkPart) break;

        auto itrA = std::find_if(A.begin(), A.end(),
                                 [a](Agent* _a) { return a == _a; });
        i = std::distance(A.begin(), itrA);

        for (auto b : block2) {
          if (!checkPart) break;

          auto itrB = std::find_if(A.begin(), A.end(),
                                   [b](Agent* _b) { return b == _b; });
          j = std::distance(A.begin(), itrB);

          for (int t = 0; t < maxLength; ++t) {
            // detect collision
            if (paths[j][t] == paths[i][t]) {
              checkPart = false;
              break;
            }
            // intersection
            if (t == 0) continue;
            if (paths[j][t] == paths[i][t-1] && paths[j][t-1] == paths[i][t]) {
              checkPart = false;
              break;
            }
          }
        }
      }

      // merge
      if (!checkPart) {
        TMP.push_back(block2);
        checkFrac = false;
      }
    }

    if (!checkFrac) checkAll = false;
    Agents newAgents;
    newAgents.insert(newAgents.end(), block1.begin(), block1.end());
    for (auto block2 : TMP) {
      openToClose(block2, OPEN, CLOSE);
      newAgents.insert(newAgents.end(), block2.begin(), block2.end());
    }
    TMP.clear();
    whole.push_back(newAgents);
  }

  OPEN.clear();
  CLOSE.clear();
  return checkAll;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movq -0x10(%rbp), %rsi
callq 0x9d280
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x62390
leaq -0x50(%rbp), %rdi
callq 0x62140
leaq -0x68(%rbp), %rdi
callq 0x62140
leaq -0x80(%rbp), %rdi
callq 0xd9a0
leaq -0x98(%rbp), %rdi
callq 0xd9a0
movb $0x1, -0xa1(%rbp)
movq -0x18(%rbp), %rdi
callq 0x62480
leaq -0x38(%rbp), %rdi
callq 0x624a0
xorb $-0x1, %al
testb $0x1, %al
jne 0x58126
jmp 0x588fa
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x624e0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x62500
jmp 0x58141
leaq -0xd0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xdbb0
jmp 0x58153
leaq -0xd0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x589a0
jmp 0x58169
leaq -0xd0(%rbp), %rdi
callq 0xddf0
movb $0x1, -0xa3(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x62210
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x62240
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x62270
testb $0x1, %al
jne 0x581c9
jmp 0x58671
leaq -0xe0(%rbp), %rdi
callq 0x622b0
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0xdbb0
jmp 0x581e6
movb $0x1, -0xa2(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
callq 0x39b60
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
callq 0x399f0
movq %rax, -0x118(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x51bd0
testb $0x1, %al
jne 0x5823a
jmp 0x58632
leaq -0x110(%rbp), %rdi
callq 0x51c10
movq (%rax), %rax
movq %rax, -0x120(%rbp)
testb $0x1, -0xa2(%rbp)
jne 0x58298
jmp 0x58632
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x58959
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xddf0
jmp 0x58959
movq -0x260(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x270(%rbp)
callq 0x39b60
movq -0x270(%rbp), %rdi
movq %rax, -0x130(%rbp)
callq 0x399f0
movq %rax, -0x138(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
movq -0x140(%rbp), %rdx
callq 0x58a50
movq %rax, -0x268(%rbp)
jmp 0x582fa
movq -0x260(%rbp), %rdi
movq -0x268(%rbp), %rax
movq %rax, -0x128(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0x148(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x62750
movq %rax, -0x278(%rbp)
jmp 0x58349
movq -0x278(%rbp), %rax
movl %eax, -0x9c(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
callq 0x39b60
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rdi
callq 0x399f0
movq %rax, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x51bd0
testb $0x1, %al
jne 0x583a6
jmp 0x5861f
leaq -0x160(%rbp), %rdi
callq 0x51c10
movq (%rax), %rax
movq %rax, -0x170(%rbp)
testb $0x1, -0xa2(%rbp)
jne 0x583ed
jmp 0x5861f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xddf0
jmp 0x58959
movq -0x260(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x288(%rbp)
callq 0x39b60
movq -0x288(%rbp), %rdi
movq %rax, -0x180(%rbp)
callq 0x399f0
movq %rax, -0x188(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x180(%rbp), %rdi
movq -0x188(%rbp), %rsi
movq -0x190(%rbp), %rdx
callq 0x58ab0
movq %rax, -0x280(%rbp)
jmp 0x5844f
movq -0x260(%rbp), %rdi
movq -0x280(%rbp), %rax
movq %rax, -0x178(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0x198(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x198(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
callq 0x62750
movq %rax, -0x290(%rbp)
jmp 0x5849e
movq -0x290(%rbp), %rax
movl %eax, -0xa0(%rbp)
movl $0x0, -0x1a4(%rbp)
movl -0x1a4(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x5860c
movq -0x10(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x1a4(%rbp), %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x298(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x9c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x1a4(%rbp), %rsi
callq 0xda90
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq (%rcx), %rax
jne 0x58527
movb $0x0, -0xa2(%rbp)
jmp 0x5860c
cmpl $0x0, -0x1a4(%rbp)
jne 0x58535
jmp 0x585f8
movq -0x10(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x1a4(%rbp), %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x2a0(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x9c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movl -0x1a4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xda90
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
cmpq (%rcx), %rax
jne 0x585f6
movq -0x10(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movl -0x1a4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x2a8(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x9c(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x1a4(%rbp), %rsi
callq 0xda90
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
cmpq (%rcx), %rax
jne 0x585f6
movb $0x0, -0xa2(%rbp)
jmp 0x5860c
jmp 0x585f8
movl -0x1a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a4(%rbp)
jmp 0x584b5
jmp 0x5860e
leaq -0x160(%rbp), %rdi
callq 0x51c30
jmp 0x5838a
jmp 0x58621
leaq -0x110(%rbp), %rdi
callq 0x51c30
jmp 0x5821e
testb $0x1, -0xa2(%rbp)
jne 0x58654
leaq -0x68(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x62790
jmp 0x5864d
movb $0x0, -0xa3(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xddf0
leaq -0xe0(%rbp), %rdi
callq 0x622d0
jmp 0x581ad
testb $0x1, -0xa3(%rbp)
jne 0x58681
movb $0x0, -0xa1(%rbp)
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0xd9a0
movq -0x2b8(%rbp), %rdi
callq 0x399f0
movq %rax, -0x1d0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x628b0
leaq -0x80(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x39b60
movq -0x2c0(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
callq 0x399f0
movq -0x2b8(%rbp), %rdi
movq %rax, -0x1e0(%rbp)
movq -0x1c8(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
movq -0x1e0(%rbp), %rcx
callq 0x62800
movq %rax, -0x2b0(%rbp)
jmp 0x5870e
movq -0x2b0(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rdi
callq 0x62210
movq %rax, -0x1f8(%rbp)
movq -0x1f0(%rbp), %rdi
callq 0x62240
movq %rax, -0x200(%rbp)
leaq -0x1f8(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x62270
testb $0x1, %al
jne 0x58769
jmp 0x588c0
leaq -0x1f8(%rbp), %rdi
callq 0x622b0
movq %rax, %rsi
leaq -0x218(%rbp), %rdi
callq 0xdbb0
jmp 0x58786
leaq -0x230(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0xdbb0
jmp 0x5879b
leaq -0x230(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x589a0
jmp 0x587b1
leaq -0x230(%rbp), %rdi
callq 0xddf0
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x399f0
movq %rax, -0x240(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x628b0
leaq -0x218(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x39b60
movq -0x2d8(%rbp), %rdi
movq %rax, -0x248(%rbp)
callq 0x399f0
movq -0x2d0(%rbp), %rdi
movq %rax, -0x250(%rbp)
movq -0x238(%rbp), %rsi
movq -0x248(%rbp), %rdx
movq -0x250(%rbp), %rcx
callq 0x62800
movq %rax, -0x2c8(%rbp)
jmp 0x58841
movq -0x2c8(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x218(%rbp), %rdi
callq 0xddf0
leaq -0x1f8(%rbp), %rdi
callq 0x622d0
jmp 0x5874d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x588ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x588b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x230(%rbp), %rdi
callq 0xddf0
leaq -0x218(%rbp), %rdi
callq 0xddf0
jmp 0x588ec
leaq -0x68(%rbp), %rdi
callq 0x62480
movq -0x18(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x62790
jmp 0x588db
leaq -0x1c0(%rbp), %rdi
callq 0xddf0
jmp 0x58112
leaq -0x1c0(%rbp), %rdi
callq 0xddf0
jmp 0x58959
leaq -0x38(%rbp), %rdi
callq 0x62480
leaq -0x50(%rbp), %rdi
callq 0x62480
movb -0xa1(%rbp), %al
movb %al, -0x2d9(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xddf0
leaq -0x80(%rbp), %rdi
callq 0xddf0
leaq -0x68(%rbp), %rdi
callq 0x62330
leaq -0x50(%rbp), %rdi
callq 0x62330
leaq -0x38(%rbp), %rdi
callq 0x62330
movb -0x2d9(%rbp), %al
andb $0x1, %al
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0xddf0
leaq -0x80(%rbp), %rdi
callq 0xddf0
leaq -0x68(%rbp), %rdi
callq 0x62330
leaq -0x50(%rbp), %rdi
callq 0x62330
leaq -0x38(%rbp), %rdi
callq 0x62330
movq -0xb0(%rbp), %rdi
callq 0x8880
nopw %cs:(%rax,%rax)