// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movl %ecx, 0xc(%rsp)
movslq (%rsi), %rbp
movq 0x88(%rdi), %rax
movl (%rax,%rbp,4), %r12d
movb $0x1, %r15b
cmpl %edx, %r12d
jge 0x45b41
movl %edx, %r13d
movq %rdi, %rbx
movslq %r12d, %rdx
movq %rsi, 0x18(%rsp)
movq 0x10(%rsi), %r15
leaq (,%rbp,2), %r14
addq %rbp, %r14
testq %r15, %r15
jne 0x45678
movq 0x70(%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rdx,8), %r15
movq %r15, 0x38(%rsp)
cmpb $0x0, 0xc(%rsp)
je 0x45696
movq 0x70(%rbx), %rax
movq (%rax,%r14,8), %rcx
cmpq %r15, (%rcx,%rdx,8)
je 0x45b12
movq %rdx, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x45be8
movq %r15, %rcx
movl %r13d, %r15d
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %rcx, 0x20(%rsp)
movl %r12d, %r8d
movl %eax, 0x34(%rsp)
movl %eax, %r9d
callq 0x45cd8
movq (%r13), %rax
cmpq 0x8(%r13), %rax
je 0x45a9b
movq %rbp, 0x28(%rsp)
leal 0x1(%r12), %r13d
movl %r15d, 0x8(%rsp)
movl %r15d, %ebp
negl %ebp
movl $0x8, %r15d
movq %r13, (%rsp)
movq 0x70(%rbx), %rax
leaq (%rax,%r14,8), %rdi
movq 0x58(%rsp), %rdx
addq %r15, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45722
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45727
callq 0x1c5cc
cmpb $0x0, 0xc(%rsp)
je 0x4573e
movq 0x58(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq %rcx, (%rax,%r15)
je 0x4575b
addq $0x8, %r15
leal 0x1(%rbp,%r13), %eax
movl %r13d, %ecx
incl %ecx
movl %ecx, %r13d
cmpl $0x1, %eax
jne 0x456fb
movl 0x8(%rsp), %eax
movl %eax, %r13d
movb $0x1, %r15b
cmpl %r13d, %r12d
movq 0x28(%rsp), %r12
jge 0x45af9
movl 0x8(%rsp), %eax
notl %eax
movq %rax, 0x70(%rsp)
movq (%rsp), %r15
movq 0x70(%rbx), %rax
movq %r15, (%rsp)
movslq %r15d, %rcx
movq (%rax,%r14,8), %rax
movq (%rax,%rcx,8), %r15
movq %r15, 0x10(%rsp)
movq 0x88(%rbx), %rax
movl %ecx, (%rax,%r12,4)
movq %rcx, 0x20(%rsp)
leal -0x1(%rcx), %r12d
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x46554
movq %rax, %rbp
cmpq 0x28(%rbx), %rax
je 0x457e4
movq (%rbp), %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 0x10(%rsp), %r15
jmp 0x457a7
movq %rbx, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
callq 0x46554
cmpq %rbp, %rax
je 0x4581a
movq (%rax), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
movq (%rsp), %r15
movl %r15d, %edx
xorl %ecx, %ecx
callq *0x20(%rax)
testb %al, %al
je 0x458e3
movq 0x10(%rsp), %r15
cmpq 0x38(%rsp), %r15
movq 0x28(%rsp), %r12
movq (%rsp), %r15
jne 0x458db
cmpb $0x0, 0xc(%rsp)
jne 0x45af6
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jne 0x4586a
movq 0x18(%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, 0x38(%rsp)
cmpl %r13d, %r15d
jge 0x458db
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movl %r15d, %r8d
movl 0x34(%rsp), %r9d
callq 0x45cd8
movslq %r13d, %rax
movq 0x20(%rsp), %rcx
subq %rcx, %rax
leaq 0x8(,%rcx,8), %rcx
xorl %edx, %edx
movq 0x40(%rsp), %rsi
movq 0x8(%rsi,%rdx,8), %rsi
movq 0x70(%rbx), %rdi
movq (%rdi,%r14,8), %rdi
addq %rcx, %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x458a3
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x458db
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
incl %r15d
jmp 0x45a82
cmpl %r13d, %r15d
jg 0x45921
movl %r13d, %ebp
subl (%rsp), %ebp
incl %ebp
movq 0x70(%rbx), %rax
leaq (%rax,%r14,8), %r15
movq 0x8(%r15), %rsi
movb $0x1, %al
testb %al, %al
jne 0x45915
leaq -0x8(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0x65b0
movq 0x8(%r15), %rsi
addq $-0x8, %rsi
movq %rsi, 0x8(%r15)
decl %ebp
jne 0x458f0
movq 0x88(%rbx), %rax
movq 0x28(%rsp), %rcx
movl %r12d, (%rax,%rcx,4)
movq 0x38(%rsp), %rcx
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %rcx, 0x20(%rsp)
movl %r12d, %r8d
movl 0x34(%rsp), %r9d
callq 0x45cd8
movq 0x40(%rsp), %rdi
cmpq 0x48(%rsp), %rdi
movq (%rsp), %r15
je 0x459f9
movl $0x8, %ebp
movl 0x8(%rsp), %eax
movl %eax, %r13d
cmpl %eax, %r15d
jg 0x45a66
movq 0x70(%rsp), %rax
leal (%rax,%r15), %ebp
xorl %r13d, %r13d
movq 0x70(%rbx), %rax
leal 0x1(%r13), %r12d
movslq %r12d, %r15
leaq (,%r15,8), %rdx
addq 0x40(%rsp), %rdx
leaq (%rax,%r14,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x459bd
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x459c2
callq 0x1c5cc
cmpb $0x0, 0xc(%rsp)
je 0x459dd
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rax
cmpq %rax, (%rdi,%r15,8)
je 0x45a8d
movl %ebp, %eax
movl %r12d, %r13d
addl %r12d, %eax
jne 0x4598a
movl $0x8, %ebp
movl 0x8(%rsp), %eax
movl %eax, %r13d
movq (%rsp), %r15
jmp 0x45a61
movq 0x70(%rbx), %rax
movslq %r12d, %rcx
movq (%rax,%r14,8), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpl %r13d, %r15d
leaq 0x10(%rsp), %r12
jg 0x45a4c
movl %r13d, %ebp
subl %r15d, %ebp
incl %ebp
movq 0x70(%rbx), %rax
leaq (%rax,%r14,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45a40
movq 0x10(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45a48
movq %r12, %rdx
callq 0x1c5cc
decl %ebp
jne 0x45a1f
movq 0x88(%rbx), %rax
movq 0x28(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
movl $0x1, %ebp
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x45a78
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
cmpl $0x8, %ebp
movq 0x28(%rsp), %r12
jne 0x45af1
cmpl %r13d, %r15d
jle 0x4577b
jmp 0x45af6
movq (%rsp), %r15
addl %r15d, %r13d
movl $0x8, %ebp
jmp 0x45a6b
movq 0x70(%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x70(%rbx), %rax
leaq (%rax,%r14,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45ad4
movq 0x10(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45ade
leaq 0x10(%rsp), %rdx
callq 0x1c5cc
incl %r12d
cmpl %r12d, %r15d
jne 0x45ab3
movq 0x88(%rbx), %rax
movl %r15d, (%rax,%rbp,4)
xorl %r15d, %r15d
jmp 0x45af9
movb $0x1, %r15b
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x45b41
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x45b41
leaq (%rax,%r14,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x45b2a
movq %r15, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x45b34
leaq 0x38(%rsp), %rdx
callq 0x1c5cc
movq 0x88(%rbx), %rax
incl (%rax,%rbp,4)
movb $0x1, %r15b
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x45b7b
jmp 0x45b7b
jmp 0x45b7b
jmp 0x45b7b
jmp 0x45b5f
jmp 0x45b7b
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x45b7e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x45b7e
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x45b95
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %rbx, %rdi
callq 0x6620
nop