// File: Kei18[P]pibt/./src/solver/cbs.cpp
// Function: CBS::valid(CTNode*, std::vector<Agent*, std::allocator<Agent*>>&)
Constraints CBS::valid(CTNode* node, Agents& block) {
  Paths paths = node->paths;
  int maxLength = node->paths[0].size();
  Constraints constraints = {};
  std::vector<int> ids;
  Node* v;
  Agent *a, *b;
  int i, j;

  for (int t = 1; t < maxLength; ++t) {
    for (int _i = 0; _i < block.size(); ++_i) {
      a = block[_i];
      auto itr1 = std::find_if(A.begin(), A.end(),
                               [a](Agent* _a)
                               { return a->getId() == _a->getId(); });
      i = std::distance(A.begin(), itr1);
      v = paths[i][t];

      // check collision
      ids.clear();
      for (int _j = _i + 1; _j < block.size(); ++_j) {
        b = block[_j];
        auto itr2 = std::find_if(A.begin(), A.end(),
                                 [b](Agent* _b) { return b == _b; });
        j = std::distance(A.begin(), itr2);
        if (paths[j][t] == v) ids.push_back(j);
      }

      if (!ids.empty()) {  // detect collision
        ids.push_back(i);
        for (int k = 0; k < ids.size(); ++k) {
          Constraint constraint;
          for (int l = 0; l < ids.size(); ++l) {
            if (k == l) continue;
            Conflict* c = new Conflict { A[ids[l]], t, v, v, true, "" };
            setCKey(c);
            constraint.push_back(c);
          }
          constraints.push_back(constraint);
        }
        return constraints;
      }

      // check intersection
      auto itr3 = paths.begin() + i;
      auto itr4 = std::find_if(itr3 + 1, paths.end(),
                               [t, itr3](Nodes path) {
                                 if (path.empty()) return false;
                                 return (path[t] == (*itr3)[t-1])
                                   && (path[t-1] == (*itr3)[t]); });
      if (itr4 != paths.end()) {  // detect intersection

        Constraint knownConstraint = getConstraints(node);

        j = std::distance(paths.begin(), itr4);
        Conflict* c1 = new Conflict { A[i], t, (*itr3)[t], (*itr3)[t-1], false, "" };
        Conflict* c2 = new Conflict { A[j], t, (*itr4)[t], (*itr4)[t-1], false, "" };
        setCKey(c1);
        setCKey(c2);
        constraints.push_back({ c1 });
        constraints.push_back({ c2 });
        return constraints;
      }
    }
  }

  return constraints;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x230(%rbp)
movq %rdi, %rax
movq %rax, -0x240(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0x38(%rbp), %rdi
callq 0x62db0
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xda70
movq %rax, %rdi
callq 0x3b0e0
movq -0x230(%rbp), %rdi
movl %eax, -0x3c(%rbp)
movb $0x0, -0x3d(%rbp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x82c0
movq -0x230(%rbp), %rdi
callq 0x628f0
leaq -0x58(%rbp), %rdi
callq 0x4e800
movl $0x1, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x59d26
movl $0x0, -0x80(%rbp)
movslq -0x80(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x20(%rbp), %rdi
callq 0x383b0
movq %rax, %rcx
movq -0x248(%rbp), %rax
cmpq %rcx, %rax
jae 0x59d16
movq -0x20(%rbp), %rdi
movslq -0x80(%rbp), %rsi
callq 0x53720
movq -0x238(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x68(%rbp)
addq $0x20, %rdi
movq %rdi, -0x258(%rbp)
callq 0x39b60
movq -0x258(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0x399f0
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x5ac10
movq %rax, -0x250(%rbp)
jmp 0x59314
movq -0x238(%rbp), %rdi
movq -0x250(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0xb8(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x62750
movq %rax, -0x260(%rbp)
jmp 0x59363
movq -0x260(%rbp), %rax
movl %eax, -0x74(%rbp)
movslq -0x74(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xda70
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x63350
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
movslq -0xc4(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x20(%rbp), %rdi
callq 0x383b0
movq %rax, %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
jae 0x594fb
movq -0x20(%rbp), %rdi
movslq -0xc4(%rbp), %rsi
callq 0x53720
movq -0x238(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x70(%rbp)
addq $0x20, %rdi
movq %rdi, -0x278(%rbp)
callq 0x39b60
movq -0x278(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0x399f0
movq %rax, -0xe0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
callq 0x5ac70
movq %rax, -0x270(%rbp)
jmp 0x59442
movq -0x238(%rbp), %rdi
movq -0x270(%rbp), %rax
movq %rax, -0xd0(%rbp)
addq $0x20, %rdi
callq 0x39b60
movq %rax, -0xf0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x62750
movq %rax, -0x280(%rbp)
jmp 0x59491
movq -0x280(%rbp), %rax
movl %eax, -0x78(%rbp)
movslq -0x78(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xda70
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0xda90
movq (%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x594e5
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4e820
jmp 0x594cc
jmp 0x594e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x59d45
jmp 0x594e7
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x593a2
leaq -0x58(%rbp), %rdi
callq 0x63370
testb $0x1, %al
jne 0x5975b
leaq -0x58(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x4e820
jmp 0x5951b
movl $0x0, -0xfc(%rbp)
movslq -0xfc(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4fab0
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
jae 0x59748
leaq -0x118(%rbp), %rdi
callq 0x62930
movl $0x0, -0x11c(%rbp)
movslq -0x11c(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4fab0
movq %rax, %rcx
movq -0x290(%rbp), %rax
cmpq %rcx, %rax
jae 0x59702
movl -0xfc(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jne 0x595a2
jmp 0x5969e
movl $0x48, %edi
callq 0x84e0
movq %rax, -0x298(%rbp)
jmp 0x595b5
movq -0x238(%rbp), %rax
movb $0x1, -0x12a(%rbp)
addq $0x20, %rax
movq %rax, -0x2b0(%rbp)
movslq -0x11c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x4ea00
movq -0x2b0(%rbp), %rdi
movslq (%rax), %rsi
callq 0x53720
movq %rax, %rcx
movq -0x298(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, (%rax)
movl -0x7c(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x18(%rax)
movb $0x1, 0x20(%rax)
addq $0x28, %rax
movq %rax, -0x2a8(%rbp)
leaq -0x129(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x8890
movq -0x2a8(%rbp), %rdi
movq -0x2a0(%rbp), %rdx
leaq 0x59f6e(%rip), %rsi     # 0xb35b8
callq 0xd8c0
jmp 0x59651
movb $0x0, -0x12a(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x8540
movq -0x298(%rbp), %rax
movq -0x238(%rbp), %rdi
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rsi
callq 0x5acd0
jmp 0x59687
leaq -0x118(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x633b0
jmp 0x5969c
jmp 0x5969e
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x59565
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x59737
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x8540
testb $0x1, -0x12a(%rbp)
jne 0x596ef
jmp 0x59700
movq -0x298(%rbp), %rdi
movl $0x48, %esi
callq 0x84f0
jmp 0x59737
movq -0x230(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x63420
jmp 0x59717
leaq -0x118(%rbp), %rdi
callq 0x62ea0
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x59525
leaq -0x118(%rbp), %rdi
callq 0x62ea0
jmp 0x59d45
movb $0x1, -0x3d(%rbp)
movl $0x1, -0x130(%rbp)
jmp 0x59d34
leaq -0x38(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x377e0
movq %rax, -0x140(%rbp)
movslq -0x74(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x4ec90
movq %rax, -0x138(%rbp)
leaq -0x138(%rbp), %rdi
movl $0x1, %esi
callq 0x4ec90
movq -0x2c0(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x37500
movq %rax, -0x158(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
movl -0x168(%rbp), %edx
movq -0x160(%rbp), %rcx
callq 0x5afc0
movq %rax, -0x2b8(%rbp)
jmp 0x597f4
movq -0x2b8(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x37500
movq %rax, -0x170(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x4e640
testb $0x1, %al
jne 0x5982e
jmp 0x59d06
movq -0x238(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0x5b030
jmp 0x59847
leaq -0x38(%rbp), %rdi
callq 0x377e0
movq %rax, -0x190(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x190(%rbp), %rdi
movq -0x198(%rbp), %rsi
callq 0x63490
movq %rax, -0x2c8(%rbp)
jmp 0x59881
movq -0x2c8(%rbp), %rax
movl %eax, -0x78(%rbp)
movl $0x48, %edi
callq 0x84e0
movq %rax, -0x2d0(%rbp)
jmp 0x5989e
movq -0x238(%rbp), %rdi
movb $0x1, -0x1a2(%rbp)
addq $0x20, %rdi
movslq -0x74(%rbp), %rsi
callq 0x53720
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, (%rax)
movl -0x7c(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq -0x138(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x37d00
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0xda90
movq -0x2e8(%rbp), %rdi
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
callq 0x37d00
movq %rax, %rdi
movl -0x7c(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0xda90
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
addq $0x28, %rax
movq %rax, -0x2e0(%rbp)
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x8890
movq -0x2e0(%rbp), %rdi
movq -0x2d8(%rbp), %rdx
leaq 0x59c55(%rip), %rsi     # 0xb35b8
callq 0xd8c0
jmp 0x5996a
movb $0x0, -0x1a2(%rbp)
leaq -0x1a1(%rbp), %rdi
callq 0x8540
movq -0x2d0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl $0x48, %edi
callq 0x84e0
movq %rax, -0x2f0(%rbp)
jmp 0x5999e
movq -0x238(%rbp), %rdi
movb $0x1, -0x1b2(%rbp)
addq $0x20, %rdi
movslq -0x78(%rbp), %rsi
callq 0x53720
movq %rax, %rcx
movq -0x2f0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, (%rax)
movl -0x7c(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq -0x148(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x37d00
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0xda90
movq -0x308(%rbp), %rdi
movq %rax, %rcx
movq -0x2f0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
callq 0x37d00
movq %rax, %rdi
movl -0x7c(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0xda90
movq %rax, %rcx
movq -0x2f0(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
addq $0x28, %rax
movq %rax, -0x300(%rbp)
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x8890
movq -0x300(%rbp), %rdi
movq -0x2f8(%rbp), %rdx
leaq 0x59b55(%rip), %rsi     # 0xb35b8
callq 0xd8c0
jmp 0x59a6a
movb $0x0, -0x1b2(%rbp)
leaq -0x1b1(%rbp), %rdi
callq 0x8540
movq -0x2f0(%rbp), %rax
movq -0x238(%rbp), %rdi
movq %rax, -0x1b0(%rbp)
movq -0x1a0(%rbp), %rsi
callq 0x5acd0
jmp 0x59aa0
movq -0x238(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x5acd0
jmp 0x59ab5
movq -0x1a0(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x1e8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq $0x1, -0x1d8(%rbp)
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x63500
movq -0x310(%rbp), %rcx
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x1d0(%rbp), %rdi
callq 0x63520
jmp 0x59b12
movq -0x230(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x634d0
jmp 0x59b27
leaq -0x1d0(%rbp), %rdi
callq 0x62ea0
leaq -0x1e9(%rbp), %rdi
callq 0x635a0
movq -0x1b0(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x220(%rbp), %rax
movq %rax, -0x218(%rbp)
movq $0x1, -0x210(%rbp)
leaq -0x221(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x63500
movq -0x318(%rbp), %rcx
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0x208(%rbp), %rdi
callq 0x63520
jmp 0x59b9c
movq -0x230(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x634d0
jmp 0x59bb1
leaq -0x208(%rbp), %rdi
callq 0x62ea0
leaq -0x221(%rbp), %rdi
callq 0x635a0
movb $0x1, -0x3d(%rbp)
movl $0x1, -0x130(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x62ea0
jmp 0x59d34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x59cf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x1a1(%rbp), %rdi
callq 0x8540
testb $0x1, -0x1a2(%rbp)
jne 0x59c28
jmp 0x59c39
movq -0x2d0(%rbp), %rdi
movl $0x48, %esi
callq 0x84f0
jmp 0x59cf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x1b1(%rbp), %rdi
callq 0x8540
testb $0x1, -0x1b2(%rbp)
jne 0x59c67
jmp 0x59c78
movq -0x2f0(%rbp), %rdi
movl $0x48, %esi
callq 0x84f0
jmp 0x59cf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x59cac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x62ea0
leaq -0x1e9(%rbp), %rdi
callq 0x635a0
jmp 0x59cf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x59cec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x62ea0
leaq -0x221(%rbp), %rdi
callq 0x635a0
leaq -0x188(%rbp), %rdi
callq 0x62ea0
jmp 0x59d45
jmp 0x59d08
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x5927a
jmp 0x59d18
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x59267
movb $0x1, -0x3d(%rbp)
movl $0x1, -0x130(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4e960
testb $0x1, -0x3d(%rbp)
jne 0x59d71
jmp 0x59d65
leaq -0x58(%rbp), %rdi
callq 0x4e960
movq -0x230(%rbp), %rdi
callq 0x62ab0
leaq -0x38(%rbp), %rdi
callq 0xda10
jmp 0x59d8a
movq -0x230(%rbp), %rdi
callq 0x62ab0
leaq -0x38(%rbp), %rdi
callq 0xda10
movq -0x240(%rbp), %rax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x8880
nopw %cs:(%rax,%rax)