// File: 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
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x120(%rbp)
movq -0x18(%rbp), %rsi
callq 0xadcd0
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0xadd65
movb $0x1, -0x1(%rbp)
jmp 0xae5a6
movq -0x18(%rbp), %rdi
callq 0x63b50
movq -0x120(%rbp), %rdi
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rsi
callq 0xadd10
movq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xae5c0
movq %rax, -0x40(%rbp)
testb $0x1, -0x1d(%rbp)
je 0xaddf7
movq -0x120(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0xae620
cmpq -0x40(%rbp), %rax
jne 0xaddf7
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x3f490
movq -0x120(%rbp), %rdi
addq $0x88, %rdi
movslq -0x34(%rbp), %rsi
callq 0x4ea00
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0xae5a6
movq -0x120(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xae670
movq -0x120(%rbp), %rsi
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl -0x24(%rbp), %r8d
movl -0x44(%rbp), %r9d
leaq -0x60(%rbp), %rdi
callq 0xae6f0
leaq -0x60(%rbp), %rdi
callq 0x3ec00
testb $0x1, %al
jne 0xade3b
jmp 0xadeeb
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x24(%rbp), %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0xadeb3
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x3f490
jmp 0xade95
jmp 0xade97
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xade6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xae59b
movq -0x120(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, -0x124(%rbp)
addq $0x88, %rdi
movslq -0x34(%rbp), %rsi
callq 0x4ea00
movl -0x124(%rbp), %ecx
movl %ecx, (%rax)
movb $0x0, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0xae590
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0xadf9a
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, -0x130(%rbp)
movl -0x84(%rbp), %eax
movl -0x24(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rsi
leaq -0x60(%rbp), %rdi
callq 0xda90
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x3f490
jmp 0xadf55
testb $0x1, -0x1d(%rbp)
je 0xadf84
movl -0x84(%rbp), %eax
subl -0x24(%rbp), %eax
movslq %eax, %rsi
leaq -0x60(%rbp), %rdi
callq 0xda90
movq (%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0xadf84
movl -0x84(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0xadf9a
jmp 0xadf86
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xadf03
jmp 0xadf9c
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jg 0xae585
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0xda90
movq -0x120(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x13c(%rbp)
addq $0x88, %rdi
movslq -0x34(%rbp), %rsi
callq 0x4ea00
movl -0x13c(%rbp), %ecx
movq -0x120(%rbp), %rdi
movl %ecx, (%rax)
movq -0x30(%rbp), %rsi
movl -0x7c(%rbp), %edx
decl %edx
callq 0xaf2a0
movq %rax, -0x138(%rbp)
jmp 0xae015
movq -0x138(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x120(%rbp), %rdi
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x51bd0
testb $0x1, %al
jne 0xae056
jmp 0xae0f8
leaq -0x90(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x51c10
movq -0x150(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x148(%rbp)
callq 0x51c10
movq -0x120(%rbp), %rdi
movq (%rax), %rsi
callq 0xadcd0
movl %eax, -0x140(%rbp)
jmp 0xae096
movq -0x148(%rbp), %rsi
movq -0x120(%rbp), %rdi
movl -0x140(%rbp), %edx
incl %edx
movq (%rdi), %rax
movq 0x20(%rax), %rax
xorl %ecx, %ecx
callq *%rax
jmp 0xae0b9
movq -0x120(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x7c(%rbp), %edx
decl %edx
callq 0xaf2a0
movq %rax, -0x158(%rbp)
jmp 0xae0d7
movq -0x158(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0xae023
movq -0x120(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x7c(%rbp), %edx
callq 0xaf2a0
movq %rax, -0x160(%rbp)
jmp 0xae114
movq -0x120(%rbp), %rdi
movq -0x160(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x20, %rdi
callq 0x399f0
movq %rax, -0xb0(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x51bd0
testb $0x1, %al
jne 0xae163
jmp 0xae469
leaq -0x90(%rbp), %rdi
callq 0x51c10
movq -0x120(%rbp), %rdi
movq (%rax), %rsi
movl -0x7c(%rbp), %edx
movq (%rdi), %rax
movq 0x20(%rax), %rax
xorl %ecx, %ecx
callq *%rax
movb %al, -0x161(%rbp)
jmp 0xae18f
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0xae467
jmp 0xae19f
movl -0x7c(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0x80(%rbp), %eax
jg 0xae261
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movq %rdi, -0x180(%rbp)
movslq -0x34(%rbp), %rsi
callq 0xda70
movq -0x180(%rbp), %rdi
movq %rax, -0x178(%rbp)
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
callq 0x3b760
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
movl $0x1, %esi
callq 0x4c520
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x3f680
movq -0x178(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x3f610
movq %rax, -0x170(%rbp)
jmp 0xae23f
movq -0x170(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xae1a8
movq -0x120(%rbp), %rdi
movl -0x7c(%rbp), %eax
decl %eax
movl %eax, -0x184(%rbp)
addq $0x88, %rdi
movslq -0x34(%rbp), %rsi
callq 0x4ea00
movl -0x184(%rbp), %ecx
movq -0x120(%rbp), %rsi
movl %ecx, (%rax)
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl -0x7c(%rbp), %r8d
decl %r8d
movl -0x44(%rbp), %r9d
leaq -0xf0(%rbp), %rdi
callq 0xae6f0
jmp 0xae2b3
leaq -0xf0(%rbp), %rdi
callq 0x3ec00
testb $0x1, %al
jne 0xae2c8
jmp 0xae392
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movl -0x7c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
cmpl -0x80(%rbp), %eax
jg 0xae35a
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x3f490
jmp 0xae32a
jmp 0xae32c
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0xae2fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xd7d0
jmp 0xae59b
movq -0x120(%rbp), %rdi
movl -0x80(%rbp), %eax
movl %eax, -0x188(%rbp)
addq $0x88, %rdi
movslq -0x34(%rbp), %rsi
callq 0x4ea00
movl -0x188(%rbp), %ecx
movl %ecx, (%rax)
movb $0x0, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0xae44a
movl -0x1c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0x80(%rbp), %eax
jg 0xae443
movq -0x120(%rbp), %rdi
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, -0x190(%rbp)
movl -0xf8(%rbp), %eax
movl -0x7c(%rbp), %ecx
subl %ecx, %eax
incl %eax
movslq %eax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0xda90
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x3f490
jmp 0xae3f8
testb $0x1, -0x1d(%rbp)
je 0xae42d
movl -0xf8(%rbp), %eax
subl -0x7c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0xda90
movq (%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0xae42d
movl -0xf8(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0xae443
jmp 0xae42f
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0xae3a1
movl $0x8, -0x78(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xd7d0
movl -0x78(%rbp), %eax
subl $0x8, %eax
je 0xadf9c
jmp 0xae590
jmp 0xae469
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0xae577
testb $0x1, -0x1d(%rbp)
je 0xae48d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0xae590
movq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xadd10
movq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xae5c0
movq %rax, -0x198(%rbp)
jmp 0xae4b6
movq -0x198(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0xae575
movq -0x120(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movl -0x44(%rbp), %r9d
leaq -0x110(%rbp), %rdi
callq 0xae6f0
jmp 0xae4f2
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x80(%rbp), %eax
jg 0xae569
movl -0x114(%rbp), %eax
subl -0x7c(%rbp), %eax
movslq %eax, %rsi
leaq -0x110(%rbp), %rdi
callq 0xda90
movq -0x120(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
addq $0x70, %rdi
movslq -0x34(%rbp), %rsi
callq 0xda70
movq %rax, %rdi
movslq -0x114(%rbp), %rsi
callq 0xda90
movq -0x1a0(%rbp), %rcx
movq %rcx, (%rax)
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0xae4fe
leaq -0x110(%rbp), %rdi
callq 0xd7d0
jmp 0xae577
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xadf9c
movb $0x1, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd7d0
jmp 0xae5a6
leaq -0x60(%rbp), %rdi
callq 0xd7d0
jmp 0xae5b4
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x8880
nopl (%rax)