// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, 0x60(%rsp)
movq %rdi, %rbx
leaq 0x18(%rdx), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x2abfc
movq %r14, 0xc0(%rsp)
movq 0x18(%r14), %rax
movq 0x8(%rax), %rbp
subq (%rax), %rbp
shrq $0x3, %rbp
xorl %eax, %eax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movq %rbx, 0x58(%rsp)
movups %xmm0, (%rbx)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x2, %ebp
jl 0x2753f
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x1, %eax
movq %rax, 0x8(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x10(%rsp), %r14
movq %r15, 0xd0(%rsp)
movq $0x0, 0xa0(%rsp)
movl $0x1, %eax
movq %rax, 0x90(%rsp)
movq 0xa0(%rsp), %rcx
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq %rdx, 0xe0(%rsp)
cmpq %rcx, %rdx
movq %rcx, 0x98(%rsp)
jbe 0x27517
movq (%rax,%rcx,8), %rdx
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rax
movq 0x28(%rcx), %rcx
movq %rcx, %rdi
subq %rax, %rdi
movq %rdi, %r8
sarq $0x5, %r8
movq %rax, %rsi
testq %r8, %r8
jle 0x26e64
movl (%rdx), %r9d
andq $-0x20, %rdi
movq %rdi, %rsi
addq %rax, %rsi
incq %r8
leaq 0x10(%rax), %rdi
movq -0x10(%rdi), %r10
cmpl (%r10), %r9d
je 0x26e9f
movq -0x8(%rdi), %r10
cmpl (%r10), %r9d
je 0x26ea5
movq (%rdi), %r10
cmpl (%r10), %r9d
je 0x26ec3
movq 0x8(%rdi), %r10
cmpl (%r10), %r9d
je 0x26eab
decq %r8
addq $0x20, %rdi
cmpq $0x1, %r8
jg 0x26e34
movq %rcx, %rdi
subq %rsi, %rdi
sarq $0x3, %rdi
cmpq $0x1, %rdi
je 0x26eb5
cmpq $0x2, %rdi
je 0x26e8f
cmpq $0x3, %rdi
jne 0x26ec0
movq (%rsi), %rdi
movl (%rdx), %r8d
cmpl (%rdi), %r8d
je 0x26e9a
addq $0x8, %rsi
movq (%rsi), %rdi
movl (%rdx), %r8d
cmpl (%rdi), %r8d
jne 0x26eb1
movq %rsi, %rdi
jmp 0x26ec3
addq $-0x10, %rdi
jmp 0x26ec3
addq $-0x8, %rdi
jmp 0x26ec3
addq $0x8, %rdi
jmp 0x26ec3
addq $0x8, %rsi
movq (%rsi), %rdi
movl (%rdx), %edx
cmpl (%rdi), %edx
cmoveq %rsi, %rcx
movq %rcx, %rdi
subq %rax, %rdi
shrq $0x3, %rdi
movl %edi, 0x4(%rsp)
movslq %edi, %rax
movq 0xa8(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x26efb
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rax
leaq 0x1(%rax), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x90(%rsp), %r13
movq %rsi, 0xa0(%rsp)
cmpq %rsi, %rcx
jbe 0x27041
movq (%rax,%r13,8), %rdx
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rax
movq 0x28(%rcx), %rcx
movq %rcx, %rdi
subq %rax, %rdi
movq %rdi, %r8
sarq $0x5, %r8
movq %rax, %rsi
testq %r8, %r8
jle 0x26f89
andq $-0x20, %rdi
movq %rdi, %rsi
addq %rax, %rsi
incq %r8
leaq 0x10(%rax), %rdi
cmpq %rdx, -0x10(%rdi)
je 0x26fc3
cmpq %rdx, -0x8(%rdi)
je 0x26fc9
cmpq %rdx, (%rdi)
je 0x26fd8
cmpq %rdx, 0x8(%rdi)
je 0x26fd4
decq %r8
addq $0x20, %rdi
cmpq $0x1, %r8
jg 0x26f65
movq %rcx, %rdi
subq %rsi, %rdi
sarq $0x3, %rdi
cmpq $0x1, %rdi
je 0x26fb7
cmpq $0x2, %rdi
je 0x26fae
cmpq $0x3, %rdi
jne 0x26fbe
cmpq %rdx, (%rsi)
je 0x26fcf
addq $0x8, %rsi
cmpq %rdx, (%rsi)
je 0x26fcf
addq $0x8, %rsi
cmpq %rdx, (%rsi)
cmoveq %rsi, %rcx
movq %rcx, %rdi
jmp 0x26fd8
addq $-0x10, %rdi
jmp 0x26fd8
addq $-0x8, %rdi
jmp 0x26fd8
movq %rsi, %rdi
jmp 0x26fd8
addq $0x8, %rdi
subq %rax, %rdi
shrq $0x3, %rdi
movl %edi, 0x54(%rsp)
movslq %edi, %rax
movq 0xa8(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
movq 0x8(%rsp), %rcx
cmpq %rbx, (%rax,%rcx,8)
jne 0x27027
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2701a
movl %edi, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x27027
movq %r14, %rdi
leaq 0x54(%rsp), %rdx
callq 0x2171e
incq %r13
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
ja 0x26f2e
movq 0x18(%rsp), %rsi
cmpq %rsi, 0x10(%rsp)
je 0x2706c
cmpq 0x20(%rsp), %rsi
je 0x271d0
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x271dd
movq 0xa8(%rsp), %rax
movq 0xb0(%rsp), %r13
movslq 0x4(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x18(%rax,%rcx,8), %rbx
movq 0x8(%rsp), %rdx
movl %edx, 0x30(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rsi, 0x38(%rsp)
movq %r13, %r14
subq %rbx, %r14
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %r14
sarq $0x2, %r14
testq %r14, %r14
jle 0x27162
movq %r13, 0xc8(%rsp)
incq %r14
leaq (%rax,%rcx,8), %r13
addq $0x30, %r13
leaq -0x18(%r13), %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
jne 0x27332
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x29f24
testb %al, %al
jne 0x2732f
leaq 0x18(%r13), %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
jne 0x27332
leaq 0x30(%r13), %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
jne 0x27332
decq %r14
addq $0x60, %r13
cmpq $0x1, %r14
jg 0x270dc
addq $-0x18, %r13
movq %r13, %rbx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
movq 0xc8(%rsp), %r13
movq %r13, %rax
subq %rbx, %rax
sarq $0x3, %rax
imulq %rdx, %rax
cmpq $0x1, %rax
je 0x271b8
cmpq $0x2, %rax
je 0x2719f
cmpq $0x3, %rax
jne 0x2732f
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
jne 0x27332
addq $0x18, %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
jne 0x27332
addq $0x18, %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29f24
testb %al, %al
cmoveq %r13, %rbx
jmp 0x27332
movq %r14, %rdi
leaq 0x4(%rsp), %rdx
callq 0x2171e
movq 0x18(%rsp), %rax
movb $0x1, %cl
movq %rcx, 0x80(%rsp)
cmpq 0x10(%rsp), %rax
je 0x27327
xorl %r14d, %r14d
movq %rbp, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %r15
cmpq %r15, 0x18(%rsp)
je 0x272d4
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x272b7
movl $0x48, %edi
callq 0x6370
movq %rax, %r13
movslq (%r15,%rbp,4), %rax
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, (%r13)
movq 0x8(%rsp), %rax
movl %eax, 0x8(%r13)
movq %rbx, 0x10(%r13)
movq %rbx, 0x18(%r13)
movb $0x1, 0x20(%r13)
leaq 0x28(%r13), %rdi
movq %r13, %rax
addq $0x38, %rax
movq %rax, 0x28(%r13)
leaq 0x212ed(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb860
movq %r13, 0x68(%rsp)
movq %r13, %rsi
callq 0x27e9e
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x272a8
movq 0x68(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x38(%rsp)
jmp 0x272b7
leaq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x2bca6
incq %rbp
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
subq %r15, %rax
sarq $0x2, %rax
cmpq %rbp, %rax
ja 0x27220
movq 0x58(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2ae0e
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
movq %r12, %rbp
je 0x272fd
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
incq %r14
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x2, %rax
cmpq %r14, %rax
ja 0x271fa
xorl %r14d, %r14d
movq 0xd0(%rsp), %r15
jmp 0x27501
xorl %r14d, %r14d
jmp 0x27501
movq %r13, %rbx
cmpq 0xb0(%rsp), %rbx
sete %r14b
je 0x27501
leaq 0x30(%rsp), %rdi
movq 0xc0(%rsp), %rdx
callq 0x285c2
movq %rbx, %rax
subq 0xa8(%rsp), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl %eax, 0x54(%rsp)
movl $0x48, %edi
callq 0x6370
movq %rax, %r13
movslq 0x4(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, (%r13)
movq 0x8(%rsp), %rdx
movl %edx, 0x8(%r13)
movq 0xd8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rdx,8), %rcx
movq %rcx, 0x10(%r13)
movq -0x8(%rax,%rdx,8), %rax
movq %rax, 0x18(%r13)
movb $0x0, 0x20(%r13)
leaq 0x28(%r13), %rdi
movq %r13, %rax
addq $0x38, %rax
movq %rax, 0x28(%r13)
leaq 0x21192(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb860
movl $0x48, %edi
callq 0x6370
movslq 0x54(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
movq %rcx, (%rax)
movq 0x8(%rsp), %rdx
movl %edx, 0x8(%rax)
movq (%rbx), %rsi
movq (%rsi,%rdx,8), %rcx
movq %rcx, 0x10(%rax)
movq -0x8(%rsi,%rdx,8), %rcx
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
leaq 0x28(%rax), %rdi
movq %rax, %rcx
addq $0x38, %rcx
movq %rax, %r12
movq %rcx, 0x28(%rax)
leaq 0x21132(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb860
movq %r13, %rsi
callq 0x27e9e
movq %r12, %rsi
callq 0x27e9e
movq %r13, 0x88(%rsp)
movl $0x1, %edx
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x3(%rsp), %rcx
callq 0x2ae3a
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x2bfca
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x27495
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %r12, 0x88(%rsp)
movl $0x1, %edx
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x3(%rsp), %rcx
callq 0x2ae3a
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x2bfca
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x274e0
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x274f7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movb $0x1, %al
movq %rax, 0x80(%rsp)
incq 0x90(%rsp)
testb %r14b, %r14b
leaq 0x10(%rsp), %r14
jne 0x26dcb
movq 0xe0(%rsp), %rax
cmpq 0x98(%rsp), %rax
ja 0x27543
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq %rbp, %rcx
jne 0x26db2
movb $0x1, %bl
jmp 0x2754d
movq 0x80(%rsp), %rax
movl %eax, %ebx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27564
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
testb $0x1, %bl
jne 0x27573
movq 0x58(%rsp), %rdi
callq 0x2ab2e
leaq 0xa8(%rsp), %rdi
callq 0xb4ce
movq 0x58(%rsp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x275cf
movq %rax, %rbx
movl $0x48, %esi
movq %r12, %rdi
jmp 0x275e1
jmp 0x275d6
jmp 0x275e8
jmp 0x275cf
jmp 0x275cf
jmp 0x275b4
jmp 0x275e8
jmp 0x275e8
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x275eb
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
jmp 0x275e1
jmp 0x275e8
jmp 0x275cf
movq %rax, %rbx
jmp 0x27602
jmp 0x275e8
movq %rax, %rbx
movl $0x48, %esi
movq %r13, %rdi
callq 0x6380
jmp 0x275eb
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x27602
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27619
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x58(%rsp), %rdi
callq 0x2ab2e
leaq 0xa8(%rsp), %rdi
callq 0xb4ce
movq %rbx, %rdi
callq 0x6620