// File: Kei18[P]pibt/./src/solver/pps.cpp
// Function: PPS::FIND_NEW_VERTEX(S*)
RES PPS::FIND_NEW_VERTEX(S* s) {
  // error check
  if (s->agents.size() != 2) {
    std::cout << "error@PPS::FIND_NEW_VERTEX, "
              << "the number of agents should be two" << "\n";
    std::exit(1);
  }

  if (s->esv.empty()) {
    return RES::FAIL;
  }

  // not highest swaper
  for (auto t : swapers) {
    if (s->id == t->id) continue;
    if (CHECK_PRIORITY(s, t) == CHECK::INVALID) {
      return RES::PAUSE;
    }
  }

  // highest swaper
  s->esv.erase(s->esv.begin());  // pop
  Agents agents;
  Agent* a0 = s->agents[0];
  Agent* a1 = s->agents[1];
  Node* v = s->esv[0];
  if (pathDist(a0->getNode(), v) <= pathDist(a1->getNode(), v)) {
    agents = { a0, a1 };
  } else {
    agents = { a1, a0 };
  }
  s->agents = agents;

  return RES::SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x383b0
cmpq $0x2, %rax
je 0x9345c
movq 0x6db70(%rip), %rdi     # 0x100f98
leaq 0x2381f(%rip), %rsi     # 0xb6c4e
callq 0x84d0
movq %rax, %rdi
leaq 0x237be(%rip), %rsi     # 0xb6bfc
callq 0x84d0
movq %rax, %rdi
leaq 0x2016a(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
callq 0x3ec00
testb $0x1, %al
jne 0x9346f
jmp 0x9347b
movl $0x1, -0x4(%rbp)
jmp 0x936e6
movq -0xd8(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x96ce0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x96d10
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x96d40
testb $0x1, %al
jne 0x934b9
jmp 0x9350b
leaq -0x28(%rbp), %rdi
callq 0x96d80
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x934d9
jmp 0x93500
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x93700
cmpl $0x1, %eax
jne 0x934fe
movl $0x2, -0x4(%rbp)
jmp 0x936e6
jmp 0x93500
leaq -0x28(%rbp), %rdi
callq 0x96da0
jmp 0x934a6
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0xf0(%rbp)
callq 0x3b730
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3f680
movq -0xf0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3f610
movq %rax, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xd9a0
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0xe8(%rbp)
callq 0x53720
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movl $0x1, %esi
callq 0x53720
movq -0xe8(%rbp), %rsi
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
callq 0xda90
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
callq 0x51cb0
movq %rax, -0xe0(%rbp)
jmp 0x935b2
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movq -0x80(%rbp), %rdx
callq 0x9d410
movl %eax, -0xf4(%rbp)
jmp 0x935d1
movq -0x78(%rbp), %rdi
callq 0x51cb0
movq %rax, -0x100(%rbp)
jmp 0x935e3
movq -0x100(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movq -0x80(%rbp), %rdx
callq 0x9d410
movl %eax, -0x104(%rbp)
jmp 0x93602
movl -0xf4(%rbp), %eax
movl -0x104(%rbp), %ecx
cmpl %ecx, %eax
jg 0x93679
movq -0x70(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x2, -0x98(%rbp)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x96fb0
jmp 0x9365a
jmp 0x936c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xddf0
jmp 0x936f2
movq -0x78(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq $0x2, -0xb8(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x96fb0
jmp 0x936c1
jmp 0x936c3
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
leaq -0x68(%rbp), %rsi
callq 0x62500
jmp 0x936d6
movl $0x0, -0x4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xddf0
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x8880
nop