// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movslq (%rsi), %rcx
movq 0x88(%rdi), %rax
movq %rcx, 0x10(%rsp)
movslq (%rax,%rcx,4), %r15
movb $0x1, %r12b
cmpl %edx, %r15d
jge 0x38220
movl %edx, %r13d
movq %rsi, %r14
movq %rdi, %rbx
callq 0x38288
movq %rax, %r12
movq %rax, 0x68(%rsp)
movl %ebp, 0x1c(%rsp)
testb %bpl, %bpl
je 0x37ea7
movq 0x70(%rbx), %rdi
imulq $0x18, 0x10(%rsp), %rax
movq (%rdi,%rax), %rcx
cmpq %r12, (%rcx,%r15,8)
je 0x38235
movq %rbx, %rdi
movl %r13d, %esi
callq 0x382d2
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, 0x20(%rsp)
movq %r12, %rcx
movl %r15d, %r8d
movl %eax, 0x2c(%rsp)
movl %eax, %r9d
callq 0x3838c
movq (%rbp), %rax
cmpq 0x8(%rbp), %rax
je 0x3817e
movq %r14, 0x58(%rsp)
leal 0x1(%r15), %ecx
movl %r13d, %eax
movl %ecx, 0xc(%rsp)
movslq %ecx, %r13
movl %eax, 0x28(%rsp)
cltq
movq %rax, 0x60(%rsp)
leaq (,%r13,8), %r12
shlq $0x3, %r15
subq %r15, %r12
imulq $0x18, 0x10(%rsp), %r14
movl 0x1c(%rsp), %ebp
movq 0x20(%rsp), %r15
cmpq 0x60(%rsp), %r13
jg 0x37f55
movq 0x70(%rbx), %rdi
addq %r14, %rdi
movq 0x70(%rsp), %rsi
addq %r12, %rsi
callq 0x171da
testb %bpl, %bpl
je 0x37f4c
movq 0x70(%rsp), %rax
cmpq %r15, (%rax,%r12)
je 0x37f5c
incq %r13
addq $0x8, %r12
jmp 0x37f21
movl 0x28(%rsp), %eax
movl %eax, %r13d
movl 0xc(%rsp), %ebp
movslq %ebp, %rax
leal -0x1(%rax), %r15d
movl %ebp, 0xc(%rsp)
movq %rax, 0x38(%rsp)
movb $0x1, %r12b
cmpl %r13d, %ebp
jg 0x38216
movq %rax, %rcx
movq 0x70(%rbx), %rax
movq (%rax,%r14), %rax
movq (%rax,%rcx,8), %r12
movq %r12, 0x30(%rsp)
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %ebp, (%rax,%rcx,4)
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x389f6
movq %rax, %rbp
cmpq 0x28(%rbx), %rax
je 0x37fdc
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 0x30(%rsp), %r12
jmp 0x37f9f
movq %rbx, %rdi
movq %r12, %rsi
movl 0xc(%rsp), %edx
callq 0x389f6
cmpq %rbp, %rax
movl 0xc(%rsp), %ebp
je 0x380de
movq (%rax), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq *0x20(%rax)
testb %al, %al
jne 0x380d5
cmpl %r13d, %ebp
jg 0x3802e
movq 0x70(%rbx), %rdi
movq 0x8(%rdi,%r14), %rsi
addq %r14, %rdi
addq $-0x8, %rsi
callq 0x2d9b6
incl %ebp
jmp 0x38010
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r15d, (%rax,%rcx,4)
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl %r15d, %r8d
movl 0x2c(%rsp), %r9d
callq 0x3838c
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x381c6
pushq $0x1
popq %rbp
movq 0x38(%rsp), %r13
cmpq 0x60(%rsp), %r13
jg 0x380b6
movq 0x70(%rbx), %rdi
addq %r14, %rdi
movslq %ebp, %r12
leaq (,%r12,8), %rsi
addq 0x40(%rsp), %rsi
callq 0x171da
cmpb $0x0, 0x1c(%rsp)
je 0x380af
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq %rcx, (%rax,%r12,8)
je 0x380bd
incq %r13
incl %ebp
jmp 0x38075
movl 0x28(%rsp), %eax
movl %eax, %r13d
leaq 0x40(%rsp), %rdi
callq 0x990e
movl 0xc(%rsp), %ebp
movq 0x38(%rsp), %rax
jmp 0x37f70
movq 0x30(%rsp), %r12
movl 0xc(%rsp), %ebp
movq 0x20(%rsp), %r15
cmpq %r15, %r12
jne 0x38172
cmpb $0x0, 0x1c(%rsp)
movb $0x1, %r12b
jne 0x38216
movq %rbx, %rdi
movq 0x58(%rsp), %r15
movq %r15, %rsi
callq 0x38288
movq %rax, %r12
movq %rax, 0x68(%rsp)
cmpl %r13d, %ebp
jge 0x38163
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl %ebp, %r8d
movl 0x2c(%rsp), %r9d
callq 0x3838c
movq %r12, %r15
movslq %r13d, %rax
pushq $0x1
popq %rcx
movq 0x38(%rsp), %rdi
cmpq %rax, %rdi
jge 0x38168
movq 0x40(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x70(%rbx), %rsi
movq (%rsi,%r14), %rsi
movq %rdx, 0x8(%rsi,%rdi,8)
incq %rdi
incq %rcx
jmp 0x38140
movq %r12, %r15
jmp 0x38172
leaq 0x40(%rsp), %rdi
callq 0x990e
movq %r15, 0x20(%rsp)
incl %ebp
jmp 0x37f60
movq 0x70(%rbx), %rax
imulq $0x18, 0x10(%rsp), %r12
movq (%rax,%r12), %rax
movq (%rax,%r15,8), %rax
leaq 0x30(%rsp), %r14
movq %rax, (%r14)
leal -0x1(%r15), %ebp
incl %ebp
cmpl %r13d, %ebp
jge 0x381b4
movq 0x70(%rbx), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x171da
jmp 0x3819c
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
jmp 0x38213
movq 0x70(%rbx), %rax
movslq %r15d, %rcx
movq (%rax,%r14), %rax
movq (%rax,%rcx,8), %rax
leaq 0x30(%rsp), %r15
movq %rax, (%r15)
movl 0xc(%rsp), %ebp
cmpl %r13d, %ebp
jg 0x381f9
movq 0x70(%rbx), %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0x171da
incl %ebp
jmp 0x381e1
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
leaq 0x40(%rsp), %rdi
callq 0x990e
xorl %r12d, %r12d
leaq 0x70(%rsp), %rdi
callq 0x990e
movl %r12d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rax, %rdi
leaq 0x68(%rsp), %rsi
callq 0x171da
movq 0x88(%rbx), %rax
movq 0x10(%rsp), %rcx
incl (%rax,%rcx,4)
movb $0x1, %r12b
jmp 0x38220
jmp 0x38273
jmp 0x38262
jmp 0x38273
jmp 0x38273
jmp 0x38273
jmp 0x38273
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x990e
jmp 0x38276
jmp 0x38273
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x990e
movq %rbx, %rdi
callq 0x6650