// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movq %rcx, 0x80(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rdx), %rsi
leaq 0x88(%rsp), %rdi
callq 0x2ab02
movq 0x18(%r15), %rax
movq 0x8(%rax), %rdx
subq (%rax), %rdx
shrq $0x3, %rdx
xorl %edi, %edi
movq %rdi, 0x10(%rbx)
xorps %xmm0, %xmm0
movq %rbx, 0x50(%rsp)
movups %xmm0, (%rbx)
movq %rdi, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x2, %edx
jl 0x2742f
movq %r15, 0xa0(%rsp)
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %eax
movq %rax, 0x8(%rsp)
leaq 0x30(%rsp), %r15
movq %rdx, 0xa8(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x1, %eax
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq 0x78(%rsp), %r13
cmpq %r13, %rdx
jbe 0x270e1
movq (%rax,%r13,8), %r9
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdi
movq %rdi, %r10
subq %rsi, %r10
movq %r10, %r11
sarq $0x5, %r11
testq %r11, %r11
jle 0x26d95
movl (%r9), %ebx
andq $-0x20, %r10
movq %r10, %r8
addq %rsi, %r8
incq %r11
leaq 0x10(%rsi), %r10
movq -0x10(%r10), %r12
cmpl %ebx, (%r12)
je 0x26db3
movq -0x8(%r10), %r12
cmpl %ebx, (%r12)
je 0x26db9
movq (%r10), %r12
cmpl %ebx, (%r12)
je 0x26df7
movq 0x8(%r10), %r12
cmpl %ebx, (%r12)
je 0x26de0
decq %r11
addq $0x20, %r10
cmpq $0x1, %r11
jg 0x26d55
movq %rdi, %r10
subq %r8, %r10
jmp 0x26d98
movq %rsi, %r8
sarq $0x3, %r10
cmpq $0x3, %r10
je 0x26dc4
cmpq $0x2, %r10
je 0x26dbf
cmpq $0x1, %r10
jne 0x26df4
movl (%r9), %r9d
jmp 0x26dea
addq $-0x10, %r10
jmp 0x26df7
addq $-0x8, %r10
jmp 0x26df7
movl (%r9), %r9d
jmp 0x26dd3
movl (%r9), %r9d
movq (%r8), %r10
cmpl %r9d, (%r10)
je 0x26ddb
addq $0x8, %r8
movq (%r8), %r10
cmpl %r9d, (%r10)
jne 0x26de6
movq %r8, %r10
jmp 0x26df7
addq $0x8, %r10
jmp 0x26df7
addq $0x8, %r8
movq (%r8), %r10
cmpl %r9d, (%r10)
cmoveq %r8, %rdi
movq %rdi, %r10
subq %rsi, %r10
shrq $0x3, %r10
movl %r10d, 0x4(%rsp)
movslq %r10d, %rsi
movq 0x88(%rsp), %rdi
leaq (%rsi,%rsi,2), %rsi
movq (%rdi,%rsi,8), %rsi
movq 0x8(%rsp), %rdi
movq (%rsi,%rdi,8), %rbx
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rsi
cmpq %rbp, %rsi
je 0x26e36
movq %rbp, 0x18(%rsp)
movq %rbp, %rsi
incq %r13
movq %r13, %r8
movq 0x70(%rsp), %r13
movq %r8, 0x78(%rsp)
cmpq %r8, %rdx
jbe 0x26f78
movq (%rax,%r13,8), %rdi
movq 0x20(%r14), %rdx
movq 0x28(%r14), %rsi
movq %rsi, %r9
subq %rdx, %r9
movq %r9, %r10
sarq $0x5, %r10
testq %r10, %r10
jle 0x26eaa
andq $-0x20, %r9
movq %r9, %r8
addq %rdx, %r8
incq %r10
leaq 0x10(%rdx), %r9
cmpq %rdi, -0x10(%r9)
je 0x26ee1
cmpq %rdi, -0x8(%r9)
je 0x26ee7
cmpq %rdi, (%r9)
je 0x26ef6
cmpq %rdi, 0x8(%r9)
je 0x26ef2
decq %r10
addq $0x20, %r9
cmpq $0x1, %r10
jg 0x26e7e
movq %rsi, %r9
subq %r8, %r9
jmp 0x26ead
movq %rdx, %r8
sarq $0x3, %r9
cmpq $0x1, %r9
je 0x26ed5
cmpq $0x2, %r9
je 0x26ecc
cmpq $0x3, %r9
jne 0x26edc
cmpq %rdi, (%r8)
je 0x26eed
addq $0x8, %r8
cmpq %rdi, (%r8)
je 0x26eed
addq $0x8, %r8
cmpq %rdi, (%r8)
cmoveq %r8, %rsi
movq %rsi, %r9
jmp 0x26ef6
addq $-0x10, %r9
jmp 0x26ef6
addq $-0x8, %r9
jmp 0x26ef6
movq %r8, %r9
jmp 0x26ef6
addq $0x8, %r9
subq %rdx, %r9
shrq $0x3, %r9
movl %r9d, 0x2c(%rsp)
movslq %r9d, %rdx
movq 0x88(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
movq (%rsi,%rdx,8), %rdx
movq 0x8(%rsp), %rsi
cmpq %rbx, (%rdx,%rsi,8)
jne 0x26f58
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x26f3a
movl %r9d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x26f58
leaq 0x10(%rsp), %rdi
leaq 0x2c(%rsp), %rdx
callq 0x21698
movq 0x80(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
incq %r13
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
ja 0x26e4f
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rsi
cmpq %rsi, %rbp
jne 0x27104
movq 0x88(%rsp), %rax
movq 0x90(%rsp), %rbx
movslq 0x4(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x18(%rax,%rcx,8), %r13
movq 0x8(%rsp), %rdx
movl %edx, 0x30(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rsi, 0x38(%rsp)
movq %rbx, %r12
subq %r13, %r12
movq %r12, %rbp
sarq $0x3, %rbp
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rbp
sarq $0x2, %rbp
testq %rbp, %rbp
jle 0x2706c
movq %rbx, 0xb0(%rsp)
incq %rbp
leaq (%rax,%rcx,8), %rbx
addq $0x30, %rbx
leaq -0x18(%rbx), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
jne 0x270cc
movq %r15, %rdi
movq %rbx, %rsi
callq 0x29e60
testb %al, %al
jne 0x270c9
leaq 0x18(%rbx), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
jne 0x270cc
leaq 0x30(%rbx), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
jne 0x270cc
decq %rbp
addq $0x60, %rbx
addq $-0x60, %r12
cmpq $0x1, %rbp
jg 0x26ff4
addq $-0x18, %rbx
movq %rbx, %r13
movq 0xb0(%rsp), %rbx
sarq $0x3, %r12
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r12
cmpq $0x1, %r12
je 0x270b6
cmpq $0x2, %r12
je 0x270a3
cmpq $0x3, %r12
jne 0x270c9
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
jne 0x270cc
addq $0x18, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
jne 0x270cc
addq $0x18, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x29e60
testb %al, %al
cmoveq %rbx, %r13
jmp 0x270cc
movq %rbx, %r13
incq 0x70(%rsp)
cmpq 0x90(%rsp), %r13
je 0x26cfc
jmp 0x27123
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
movq 0xa8(%rsp), %rdx
cmpq %rdx, %rcx
jne 0x26ce9
jmp 0x2742a
cmpq 0x20(%rsp), %rsi
je 0x272ef
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x27308
leaq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rdx
callq 0x28500
movq %r13, %rax
subq 0x88(%rsp), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl %eax, 0x2c(%rsp)
movl $0x48, %edi
callq 0x6370
movq %rax, %r15
movslq 0x4(%rsp), %rax
movq 0x20(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, (%r15)
movq 0x8(%rsp), %rdx
movl %edx, 0x8(%r15)
movq 0xb8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rdx,8), %rcx
movq %rcx, 0x10(%r15)
movq %rdx, %rcx
shlq $0x20, %rcx
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rbx
movq %rbx, %rcx
sarq $0x1d, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x18(%r15)
movb $0x0, 0x20(%r15)
leaq 0x28(%r15), %rdi
movq %r15, %rax
addq $0x38, %rax
movq %rax, 0x28(%r15)
leaq 0x2139f(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb8a6
movl $0x48, %edi
callq 0x6370
movq %rax, %r12
sarq $0x20, %rbx
movslq 0x2c(%rsp), %rax
movq 0x20(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, (%r12)
movq 0x8(%rsp), %rcx
movl %ecx, 0x8(%r12)
movq (%r13), %rax
movq (%rax,%rcx,8), %rcx
movq %rcx, 0x10(%r12)
movq (%rax,%rbx,8), %rax
movq %rax, 0x18(%r12)
movb $0x0, 0x20(%r12)
leaq 0x28(%r12), %rdi
movq %r12, %rax
addq $0x38, %rax
movq %rax, 0x28(%r12)
leaq 0x21337(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb8a6
movq %r15, %rsi
callq 0x27dde
movq %r12, %rsi
callq 0x27dde
leaq 0xc0(%rsp), %rsi
movq %r15, (%rsi)
leaq 0x58(%rsp), %rdi
leaq 0x3(%rsp), %rcx
movl $0x1, %edx
callq 0x2ad66
leaq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x2be66
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2728a
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
leaq 0xc0(%rsp), %rsi
movq %r12, (%rsi)
leaq 0x58(%rsp), %rdi
leaq 0x3(%rsp), %rcx
movl $0x1, %edx
callq 0x2ad66
leaq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x2be66
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x272cf
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2742a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x2742a
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x21698
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rsi
cmpq %rbp, %rsi
je 0x2742a
xorl %r12d, %r12d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
cmpq %rbp, %rsi
je 0x273e4
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x273ce
movl $0x48, %edi
callq 0x6370
movq %rax, %r13
movslq (%rbp,%r15,4), %rax
movq 0x20(%r14), %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 0x211e0(%rip), %rdx     # 0x48564
movq %rdx, %rsi
callq 0xb8a6
movq %r13, 0x58(%rsp)
movq %r13, %rsi
callq 0x27dde
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x273b5
movq 0x58(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x38(%rsp)
jmp 0x273c4
leaq 0x30(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2bb60
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rsi
incq %r15
movq %rsi, %rax
subq %rbp, %rax
sarq $0x2, %rax
cmpq %r15, %rax
ja 0x27331
movq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2ad3a
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2740a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
incq %r12
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rsi
movq %rsi, %rax
subq %rbp, %rax
sarq $0x2, %rax
cmpq %r12, %rax
ja 0x27314
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27441
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
leaq 0x88(%rsp), %rdi
callq 0xb508
movq 0x50(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x274d8
jmp 0x2746b
jmp 0x274bc
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x274bf
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
jmp 0x274b5
jmp 0x274bc
movq %rax, %rbx
movl $0x48, %esi
movq %r12, %rdi
jmp 0x274b5
movq %rax, %rbx
movl $0x48, %esi
movq %r15, %rdi
jmp 0x274b5
jmp 0x274bc
jmp 0x274d8
jmp 0x274bc
jmp 0x274d8
jmp 0x274bc
jmp 0x274d8
movq %rax, %rbx
movl $0x48, %esi
movq %r13, %rdi
callq 0x6380
jmp 0x274bf
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x274db
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x274db
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x274f2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x50(%rsp), %rdi
callq 0x2aa2e
leaq 0x88(%rsp), %rdi
callq 0xb508
movq %rbx, %rdi
callq 0x6620
nop