// File: /workspace/github_cpp_makefile_star2_O3/Kei18[P]pibt/./src/solver/cbs.cpp
// Function: CBS::solvePart(std::vector<std::vector<Node*, std::allocator<Node*>>, std::allocator<std::vector<Node*, std::allocator<Node*>>>>&, std::vector<Agent*, std::allocator<Agent*>>&)
bool CBS::solvePart(Paths& paths, Agents& block) {
  CTNode* node;
  Constraints constraints;
  std::vector<CTNode*> OPEN, ALL;
  bool status = true;

  CTNode* root = new CTNode { {}, {}, 0, nullptr, true, {}, 0 };
  invoke(root, block);
  OPEN.push_back(root);
  ALL.push_back(root);
  bool CAT = std::any_of(paths.begin(), paths.end(),
                         [](Nodes p) { return !p.empty(); });

  while (!OPEN.empty()) {
    auto itr = std::min_element(OPEN.begin(), OPEN.end(),
                                [CAT, this, &paths]
                                (CTNode* n1, CTNode* n2) {
                                  if (CAT && n1->cost == n2->cost) {
                                    int c1 = this->countCollisions(n1, paths);
                                    int c2 = this->countCollisions(n2, paths);
                                    return c1 < c2;
                                  }
                                  return n1->cost < n2->cost;
                                });
    node = *itr;
    constraints = valid(node, block);
    if (constraints.empty()) break;
    OPEN.erase(itr);

    for (auto constraint : constraints) {
      CTNode* newNode = new CTNode { constraint, node->paths,
                                     0, node, true,
                                     {}, 0 };

      // it works, but it is late
      // if (isDuplicatedCTNode(newNode, ALL)) continue;

      invoke(newNode, block);
      if (newNode->valid) {
        OPEN.push_back(newNode);
        ALL.push_back(newNode);
      }
    }
    constraints.clear();
  }

  if (!OPEN.empty()) {  // sucssess
    for (int i = 0; i < paths.size(); ++i) {
      if (!node->paths[i].empty()) {
        paths[i] = node->paths[i];
      }
    }
    status = status && true;
  } else {
    status = false;
  }

  return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, 0x78(%rsp)
movq %rsi, %rbp
movq %rdi, 0x70(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movl $0x68, %edi
callq 0x6370
movq $0x0, 0x38(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movl $0x0, 0x30(%rax)
movb $0x1, 0x40(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x54(%rax)
movq %rax, 0x48(%rsp)
movq 0x70(%rsp), %rdi
movq (%rdi), %rcx
movq %rax, %rsi
movq 0x78(%rsp), %rdx
callq *0x20(%rcx)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2672e
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x2673d
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x2b89c
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x26759
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x58(%rsp)
jmp 0x26768
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x2b89c
movq (%rbp), %rbx
movq 0x8(%rbp), %r14
movq %r14, 0x68(%rsp)
subq %rbx, %r14
movq %r14, %r12
sarq $0x3, %r12
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r12
sarq $0x2, %r12
testq %r12, %r12
jle 0x267f8
incq %r12
movq %rbx, %rdi
callq 0x29e20
testb %al, %al
jne 0x26856
leaq 0x18(%rbx), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29e20
testb %al, %al
jne 0x2685b
leaq 0x30(%rbx), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29e20
testb %al, %al
jne 0x2685b
leaq 0x48(%rbx), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29e20
testb %al, %al
jne 0x2685b
addq $0x60, %rbx
decq %r12
addq $-0x60, %r14
cmpq $0x1, %r12
jg 0x26799
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r14
cmpq $0x1, %r14
je 0x26846
cmpq $0x2, %r14
je 0x26836
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x3, %r14
jne 0x2685b
movq %rbx, %rdi
callq 0x29e20
testb %al, %al
jne 0x26856
addq $0x18, %rbx
movq %rbx, %rdi
callq 0x29e20
testb %al, %al
jne 0x26856
addq $0x18, %rbx
movq %rbx, %rdi
callq 0x29e20
testb %al, %al
cmoveq 0x68(%rsp), %rbx
movq %rbx, 0x8(%rsp)
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r12
cmpq %r12, %r13
je 0x26b6e
movq %rbp, 0xc0(%rsp)
movq 0xc0(%rsp), %r15
leaq 0x8(%r13), %r14
cmpq %r12, %r14
je 0x268da
movq (%r14), %rsi
movq (%r13), %rbx
movl 0x30(%rsi), %eax
movl 0x30(%rbx), %ecx
movq 0x8(%rsp), %rdx
cmpq 0x68(%rsp), %rdx
je 0x268bd
cmpl %ecx, %eax
jne 0x268bd
movq %r15, %rdx
callq 0x27512
movl %eax, %ebp
movq %rbx, %rsi
movq %r15, %rdx
callq 0x27512
cmpl %eax, %ebp
jmp 0x268bf
cmpl %ecx, %eax
setl %al
movq %r14, %rbp
testb %al, %al
jne 0x268cc
movq %r13, %rbp
addq $0x8, %r14
movq %rbp, %r13
cmpq %r12, %r14
jne 0x26887
jmp 0x268dd
movq %r13, %rbp
movq (%rbp), %r13
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
movq %r13, %rdx
movq 0x78(%rsp), %rcx
callq 0x26c5e
movq 0x40(%rsp), %rax
movaps 0x80(%rsp), %xmm0
movq 0x90(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movaps 0x30(%rsp), %xmm1
movaps %xmm0, 0x30(%rsp)
movaps %xmm1, 0xa0(%rsp)
movq %rax, 0xb0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2aa2e
movq %rbx, %rdi
callq 0x2aa2e
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %rdx
cmpq %r12, %rbx
je 0x26afb
leaq 0x8(%rbp), %rsi
cmpq %rdx, %rsi
je 0x26999
subq %rsi, %rdx
movq %rbp, %rdi
callq 0x65b0
movq 0x18(%rsp), %rdx
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
addq $-0x8, %rdx
movq %rdx, 0x18(%rsp)
cmpq %r12, %rbx
je 0x26abc
leaq 0x18(%r13), %r14
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x2aa82
movl $0x68, %edi
callq 0x6370
movq %rax, %rbp
movq %rax, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2aa82
movq %rbp, %rdi
addq $0x18, %rdi
movq %r14, %rsi
callq 0x2ab02
movl $0x0, 0x30(%rbp)
movq %r13, 0x38(%rbp)
movb $0x1, 0x40(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbp)
movups %xmm0, 0x54(%rbp)
movq %rbp, 0x80(%rsp)
movq 0x70(%rsp), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
movq 0x78(%rsp), %rdx
callq *0x20(%rax)
movq 0x80(%rsp), %rax
cmpb $0x1, 0x40(%rax)
jne 0x26a88
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x26a45
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x26a57
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x2b89c
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x26a76
movq 0x80(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x58(%rsp)
jmp 0x26a88
leaq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x2b89c
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x26aa5
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x269af
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
cmpq %rbx, %r12
je 0x26ae6
movq %rbx, %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x26ad8
movq 0x10(%r14), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %r14
cmpq %r12, %r14
jne 0x26ac4
movq %rbx, 0x38(%rsp)
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r12
cmpq %r12, %r13
jne 0x2687e
jmp 0x26b6e
cmpq %rdx, 0x10(%rsp)
setne %bl
je 0x26b6e
movq 0xc0(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rax
cmpq %rdi, %rax
je 0x26bbc
xorl %r14d, %r14d
xorl %r15d, %r15d
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
movq 0x18(%r13), %rsi
movq (%rsi,%r14), %rcx
cmpq 0x8(%rsi,%r14), %rcx
je 0x26b52
addq %r14, %rsi
addq %r14, %rdi
callq 0x1b2e0
movq (%r12), %rdi
movq 0x8(%r12), %rax
incq %r15
movq %rax, %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
imulq %rbp, %rcx
addq $0x18, %r14
cmpq %r15, %rcx
ja 0x26b2f
jmp 0x26b70
xorl %ebx, %ebx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x26b87
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26b9e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
leaq 0x30(%rsp), %rdi
callq 0x2aa2e
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0x26b70
jmp 0x26bf8
jmp 0x26bf8
jmp 0x26bf8
jmp 0x26bf8
jmp 0x26bf8
movq %rax, %rbx
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x26be7
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x26be7
movq %rax, %rbx
movl $0x68, %esi
movq %rbp, %rdi
callq 0x6380
jmp 0x26c00
jmp 0x26bf8
movq %rax, %rbx
jmp 0x26c1d
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x26c1d
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x26c34
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26c4b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
leaq 0x30(%rsp), %rdi
callq 0x2aa2e
movq %rbx, %rdi
callq 0x6620
nop