// File: /workspace/github_cpp_makefile_star2_O1/Kei18[P]pibt/./src/solver/winpibt.cpp
// Function: winPIBT::winpibt(Agent*, int, bool)
bool winPIBT::winpibt(Agent* a, int t_tmp, bool varphi)
{
  int l = ell(a);
  if (l >= t_tmp) return true;

  Node* v;
  int i = a->getId();

  updateGoal(a);
  Node* g = getGoal(a);

  if (varphi && lastNode(i) == g) {
    PATHS[i].push_back(g);
    L[i] += 1;
    return true;
  }

  int t_max = getTmax(t_tmp);

  Nodes path = getPath(a, g, l, t_max);

  if (path.empty()) {
    v = PATHS[i][l];
    for (int _t = l + 1; _t <= t_tmp; ++_t) {
      PATHS[i].push_back(v);
    }
    L[i] = t_tmp;
    return false;
  }

  int _t = l + 1;

  // future information
  int t_dtmp = t_tmp;
  for (int j = _t; j <= t_tmp; ++j) {
    PATHS[i].push_back(path[j - l]);
    if (varphi && path[j - l] == g) {
      t_dtmp = j;
      break;
    }
  }

  while (_t <= t_dtmp) {
    v = PATHS[i][_t];
    L[i] = _t;

    auto itrA = findPITargetAgent(v, _t - 1);
    while (itrA != A.end()) {
      winpibt(*itrA, ell(*itrA) + 1, false);
      itrA = findPITargetAgent(v, _t - 1);
    }
    itrA = findPITargetAgent(v, _t);

    if (itrA != A.end()) {
      if (!winpibt(*itrA, _t, false)) {
        for (int j = _t; j <= t_dtmp; ++j) {
          PATHS[i].erase(PATHS[i].end() - 1);
        }
        L[i] = _t - 1;
        Nodes newPath = getPath(a, g, _t - 1, t_max);

        if (newPath.empty()) {

          v = PATHS[i][_t - 1];
          for (int __t = _t; __t <= t_dtmp; ++__t) {
            PATHS[i].push_back(v);
          }
          L[i] = t_dtmp;

          return false;

        } else {

          t_dtmp = t_tmp;
          for (int j = _t; j <= t_dtmp; ++j) {
            PATHS[i].push_back(newPath[j - _t + 1]);
            if (varphi && newPath[j - _t + 1] == g) {
              t_dtmp = j;
              break;
            }
          }

          continue;
        }
      }
    }

    if (v == g) {
      if (varphi) return true;

      updateGoal(a);
      g = getGoal(a);
      if (_t < t_dtmp) {
        Nodes newPath = getPath(a, g, _t, t_max);
        for (int j = _t + 1; j <= t_dtmp; ++j) {
          PATHS[i][j] = newPath[j - _t];
        }
      }
    }

    ++_t;
  }

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, 0x24(%rsp)
movslq (%rsi), %rcx
movq 0x88(%rdi), %rax
movq %rcx, 0x10(%rsp)
movslq (%rax,%rcx,4), %r15
movb $0x1, %bpl
cmpl %r15d, %edx
jle 0x45e33
movl %edx, %r13d
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
jne 0x45911
movq 0x70(%rbx), %rcx
movq 0x10(%rsp), %rsi
leaq (%rsi,%rsi,2), %rdx
movslq (%rax,%rsi,4), %rsi
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rsi,8), %rcx
movq %rcx, 0x30(%rsp)
cmpb $0x0, 0x24(%rsp)
je 0x4593c
movq 0x70(%rbx), %rdx
movq 0x10(%rsp), %rdi
leaq (%rdi,%rdi,2), %rsi
movslq (%rax,%rdi,4), %rax
movq (%rdx,%rsi,8), %rdi
cmpq %rcx, (%rdi,%rax,8)
je 0x45de2
movq %rbx, %rdi
movl %r13d, %esi
callq 0x45ee0
movq 0x30(%rsp), %rcx
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, 0x40(%rsp)
movq %r14, %rdx
movl %r15d, %r8d
movl %eax, 0x3c(%rsp)
movl %eax, %r9d
callq 0x45fc4
movq (%r12), %rax
cmpq 0x8(%r12), %rax
je 0x45d75
movq %r15, %rcx
incl %r15d
movl %r13d, 0xc(%rsp)
movq %rcx, 0x28(%rsp)
cmpl %r13d, %ecx
jge 0x45a0f
movl 0xc(%rsp), %eax
movl %eax, %r14d
negl %r14d
movl $0x8, %r12d
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rbp
movl %r15d, %r13d
movq 0x70(%rbx), %rax
leaq (%rax,%rbp,8), %rdi
movq 0x60(%rsp), %rdx
addq %r12, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x459d5
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x459da
callq 0x1c69a
cmpb $0x0, 0x24(%rsp)
je 0x459f1
movq 0x60(%rsp), %rax
movq (%rax,%r12), %rax
cmpq 0x30(%rsp), %rax
je 0x45a0f
addq $0x8, %r12
leal (%r14,%r13), %eax
incl %eax
movl %r13d, %ecx
incl %ecx
movl %ecx, %r13d
cmpl $0x1, %eax
jne 0x459ae
movl 0xc(%rsp), %eax
movl %eax, %r13d
movb $0x1, %bpl
cmpl %r13d, 0x28(%rsp)
jge 0x45dfe
movl 0xc(%rsp), %eax
notl %eax
movq %rax, 0x78(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %r12
movl %eax, 0x38(%rsp)
movq 0x70(%rbx), %rax
movq %r15, 0x28(%rsp)
movslq %r15d, %r14
movq (%rax,%r12,8), %rax
movq (%rax,%r14,8), %rsi
movq %rsi, 0x18(%rsp)
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r14d, (%rax,%rcx,4)
leal -0x1(%r14), %ebp
movq %rbx, %rdi
movl %ebp, %edx
callq 0x46818
movq 0x28(%rbx), %r15
cmpq %r15, %rax
je 0x45a9a
movq (%rax), %rsi
movslq (%rsi), %rax
movq (%rbx), %r8
movq 0x88(%rbx), %rcx
movl (%rcx,%rax,4), %edx
incl %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq *0x20(%r8)
movq 0x18(%rsp), %rsi
jmp 0x45a62
movq %r14, 0x80(%rsp)
movq 0x18(%rsp), %rsi
movq %rbx, %rdi
movq 0x28(%rsp), %r14
movl %r14d, %edx
callq 0x46818
cmpq %r15, %rax
movq %r14, %r15
je 0x45ad4
movq (%rax), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %edx
xorl %ecx, %ecx
callq *0x20(%rax)
testb %al, %al
je 0x45aee
movq 0x18(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x45b87
incl %r15d
xorl %ebp, %ebp
jmp 0x45d5a
cmpl %r13d, %r15d
jg 0x45b2a
movl %r13d, %r14d
subl 0x28(%rsp), %r14d
incl %r14d
movq 0x70(%rbx), %r15
movb $0x1, %al
testb %al, %al
jne 0x45b1c
movq 0x8(%r15,%r12,8), %rsi
leaq -0x8(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0x65b0
leaq (%r15,%r12,8), %rax
addq $-0x8, 0x8(%rax)
decl %r14d
jne 0x45afe
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %ebp, (%rax,%rcx,4)
movq 0x30(%rsp), %rcx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq 0x40(%rsp), %rdx
movl %ebp, %r8d
movl 0x3c(%rsp), %r9d
callq 0x45fc4
movq 0x48(%rsp), %rax
cmpq 0x50(%rsp), %rax
movq 0x28(%rsp), %r15
je 0x45c50
movl $0x8, %ebp
movl 0xc(%rsp), %eax
cmpl %eax, %r15d
jle 0x45cc2
movl %eax, %r13d
jmp 0x45d43
cmpb $0x0, 0x24(%rsp)
je 0x45b9e
movb $0x1, %al
movl %eax, 0x38(%rsp)
movl $0x1, %ebp
jmp 0x45d5a
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jne 0x45bcf
movq 0x40(%rsp), %rax
movslq (%rax), %rax
leaq (%rax,%rax,2), %rcx
movq 0x70(%rbx), %rdx
movq 0x88(%rbx), %rsi
movslq (%rsi,%rax,4), %rax
movq (%rdx,%rcx,8), %rcx
movq (%rcx,%rax,8), %rcx
movq %rcx, 0x30(%rsp)
cmpl %r13d, %r15d
jge 0x45ae4
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq 0x40(%rsp), %rdx
movl %r15d, %r8d
movl 0x3c(%rsp), %r9d
callq 0x45fc4
movslq %r13d, %rax
movq 0x80(%rsp), %rcx
subq %rcx, %rax
leaq 0x8(,%rcx,8), %rcx
xorl %edx, %edx
movq 0x48(%rsp), %rsi
movq 0x8(%rsi,%rdx,8), %rsi
movq 0x70(%rbx), %rdi
movq (%rdi,%r12,8), %rdi
addq %rcx, %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x45c0f
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x45ae4
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x45ae4
movq 0x70(%rbx), %rax
movslq %ebp, %rcx
movq (%rax,%r12,8), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
cmpl %r13d, %r15d
jg 0x45ca0
movl %r13d, %ebp
subl %r15d, %ebp
incl %ebp
movq 0x70(%rbx), %rax
leaq (%rax,%r12,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45c92
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45c9c
leaq 0x18(%rsp), %rdx
callq 0x1c69a
decl %ebp
jne 0x45c71
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
movl $0x1, %ebp
movl $0x0, 0x38(%rsp)
jmp 0x45d43
movq 0x78(%rsp), %rax
leal (%rax,%r15), %r14d
xorl %r13d, %r13d
movq 0x70(%rbx), %rax
leal 0x1(%r13), %r15d
movslq %r15d, %rbp
leaq (,%rbp,8), %rdx
addq 0x48(%rsp), %rdx
leaq (%rax,%r12,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45d01
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45d06
callq 0x1c69a
cmpb $0x0, 0x24(%rsp)
je 0x45d1d
movq 0x48(%rsp), %rax
movq (%rax,%rbp,8), %rax
cmpq 0x30(%rsp), %rax
je 0x45d36
movl %r14d, %eax
movl %r15d, %r13d
addl %r15d, %eax
jne 0x45cce
movl 0xc(%rsp), %eax
movl %eax, %r13d
movq 0x28(%rsp), %r15
jmp 0x45d3e
movq 0x28(%rsp), %r15
addl %r15d, %r13d
movl $0x8, %ebp
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x45d5a
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
testb $0x7, %bpl
jne 0x45dfa
cmpl %r13d, %r15d
jle 0x45a35
movb $0x1, %bpl
jmp 0x45dfe
movq 0x70(%rbx), %rax
movq 0x10(%rsp), %rcx
movq %r15, %rdx
leaq (%rcx,%rcx,2), %r15
movq (%rax,%r15,8), %rax
movq (%rax,%rdx,8), %rax
movq %rax, 0x18(%rsp)
cmpl %r13d, %edx
jge 0x45dce
movl %r13d, %ebp
subl %edx, %ebp
leaq 0x18(%rsp), %r14
movq 0x70(%rbx), %rax
leaq (%rax,%r15,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45dc2
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45dca
movq %r14, %rdx
callq 0x1c69a
decl %ebp
jne 0x45da1
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
xorl %ebp, %ebp
jmp 0x45dfe
leaq (%rdx,%rsi,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45e17
movq %rcx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45e21
movl 0x38(%rsp), %ebp
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x45e33
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x45e33
leaq 0x30(%rsp), %rdx
callq 0x1c69a
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
incl (%rax,%rcx,4)
movb $0x1, %bpl
andb $0x1, %bpl
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x45e73
jmp 0x45e73
jmp 0x45e73
jmp 0x45e73
jmp 0x45e73
jmp 0x45e57
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x45e76
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x45e76
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x45e8d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %rbx, %rdi
callq 0x6620
nop