// File: /workspace/github_cpp_makefile_star2_O2/Kei18[P]pibt/./src/solver/whca.cpp
// Function: WHCA::solve()
bool WHCA::solve() {
  solveStart();

  Paths PATHS;  // paths for all agents
  int t = 0;
  int limit;
  bool failed = false;

  // initialize path
  for (auto a : A) PATHS.push_back({ a->getNode() });

  while (!P->isSolved()) {
    for (int i = 0; i < A.size(); ++i) {
      Nodes path = getPath(A[i], t, PATHS);

      // check whether success for computing path or not
      if (path.empty()) {
        failed = true;
        break;
      }

      // reach goal
      if (!hasWindow) {
        CG* cg = new CG { A[i], (int)path.size() - 1, A[i]->getGoal() };
        CGOAL.push_back(cg);
      }

      PATHS[i].insert(PATHS[i].end(), path.begin() + 1, path.end());
    }

    if (failed) break;

    formalizePath(PATHS);
    limit = std::min(window, (int)PATHS[0].size() - t);
    for (int _t = 0; _t < limit; ++_t) {
      ++t;
      for (int i = 0; i < A.size(); ++i) A[i]->setNode(PATHS[i][t]);
      P->update();
      if (P->isSolved()) break;
      if (P->getTimestep() >= P->getTimestepLimit()) break;
    }

    if (P->getTimestep() >= P->getTimestepLimit()) break;
  }

  solveEnd();
  return !failed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
callq *(%rax)
leaq 0x20(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %r12
leaq 0x40(%rsp), %r15
pushq $0x1
popq %r13
leaq 0xf(%rsp), %rbp
cmpq %r12, %r14
je 0x369e7
movq (%r14), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x927a
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x15146
movq %r15, %rdi
callq 0x990e
addq $0x8, %r14
jmp 0x369a8
leaq 0x70(%rbx), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%rbx), %rdi
movq $0x0, 0x10(%rsp)
leaq 0x40(%rsp), %rbp
movl $0x0, 0x8(%rsp)
movq (%rdi), %rax
callq *0x10(%rax)
testb %al, %al
jne 0x36bbb
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x36ae8
movq (%rax,%r14,8), %rdx
movq %rbp, %rdi
movq %rbx, %rsi
movl 0x8(%rsp), %ecx
leaq 0x20(%rsp), %r8
callq 0x36c1c
movq 0x40(%rsp), %r13
movq 0x48(%rsp), %r12
cmpq %r12, %r13
je 0x36ac9
cmpb $0x0, 0x68(%rbx)
movq %r12, %rcx
movq %r13, %rdx
jne 0x36ab1
pushq $0x18
popq %rdi
callq 0x63b0
movq 0x20(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movq %rcx, (%rax)
movq %r12, %rdx
subq %r13, %rdx
shrq $0x3, %rdx
decl %edx
movl %edx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3750e
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq 0x8(%rdi,%r15), %rsi
addq %r15, %rdi
addq $0x8, %rdx
callq 0x35502
jmp 0x36ad0
movb $0x1, %al
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
callq 0x990e
incq %r14
addq $0x18, %r15
cmpq %r12, %r13
jne 0x36a1e
testb $0x1, 0x10(%rsp)
jne 0x36bbb
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x32c58
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
subq (%rax), %rdx
shrq $0x3, %rdx
movl 0x8(%rsp), %ecx
subl %ecx, %edx
movl 0x6c(%rbx), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
movslq %ecx, %r15
xorl %r13d, %r13d
testl %edx, %edx
cmovlel %r13d, %edx
movq %rdx, 0x60(%rsp)
addl %edx, %ecx
movl %ecx, 0x8(%rsp)
cmpl 0x60(%rsp), %r13d
je 0x36bab
movq %rbp, %r14
incq %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbp, %rcx
jbe 0x36b7a
movq (%rax,%rbp,8), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r12), %rax
movq (%rax,%r15,8), %rsi
callq 0x158b4
incq %rbp
addq $0x18, %r12
jmp 0x36b47
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x10(%rbx), %rdi
testb %al, %al
movq %r14, %rbp
jne 0x36ba4
movl 0x8(%rdi), %eax
incl %r13d
cmpl 0xc(%rdi), %eax
jl 0x36b35
movl %r15d, 0x8(%rsp)
jmp 0x36baf
movq 0x10(%rbx), %rdi
movl 0x8(%rdi), %eax
cmpl 0xc(%rdi), %eax
jl 0x36a0a
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq 0x10(%rsp), %rbx
notb %bl
leaq 0x20(%rsp), %rdi
callq 0x92ec
andb $0x1, %bl
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x36c06
jmp 0x36c06
jmp 0x36c06
jmp 0x36bf3
jmp 0x36bf3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x990e
jmp 0x36c09
jmp 0x36c06
jmp 0x36c06
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x92ec
movq %rbx, %rdi
callq 0x6650
nop