// File: Kei18[P]pibt/./src/solver/pps.cpp
// Function: PPS::SWAP_PRIMITIVES(S*)
void PPS::SWAP_PRIMITIVES(S* s) {
  // error check
  if (s->phase != SWAPPHASE::EVAC_H &&
      s->phase != SWAPPHASE::EVAC_L &&
      s->phase != SWAPPHASE::SWAP_DONE) {
    std::cout << "error@PPS::SWAP_PRIMITIVES, "
              << "invalid phase was called" << "\n";
    std::exit(1);
  }
  if (s->agents.size() != 2) {
    std::cout << "error@PPS::SWAP_PRIMITIVES, "
              << "the size of agents must be 2, not "
              <<  s->agents.size() << "\n";
    std::exit(1);
  }

  Agent* aH = s->agents[0];
  Agent* aL = s->agents[1];

  if (inArray(aH, M) || inArray(aL, M)) {
    M.push_back(aH);
    M.push_back(aL);
    return;
  }

  switch (s->phase) {
  case SWAPPHASE::EVAC_H:
    aH->setNode(s->evacH);
    aL->setNode(s->target);
    s->phase = SWAPPHASE::EVAC_L;
    break;
  case SWAPPHASE::EVAC_L:
    aH->setNode(s->target);
    aL->setNode(s->evacL);
    s->phase = SWAPPHASE::SWAP_DONE;
    break;
  case SWAPPHASE::SWAP_DONE:
    aH->setNode(s->origin);
    aL->setNode(s->target);
    FINISH_SWAP(s);
    break;
  default:
    break;
  }
  M.push_back(aH);
  M.push_back(aL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x78(%rax)
je 0x91ec1
movq -0x10(%rbp), %rax
cmpl $0x3, 0x78(%rax)
je 0x91ec1
movq -0x10(%rbp), %rax
cmpl $0x4, 0x78(%rax)
je 0x91ec1
movq 0x6f10b(%rip), %rdi     # 0x100f98
leaq 0x24e23(%rip), %rsi     # 0xb6cb7
callq 0x84d0
movq %rax, %rdi
leaq 0x24e31(%rip), %rsi     # 0xb6cd4
callq 0x84d0
movq %rax, %rdi
leaq 0x21705(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x383b0
cmpq $0x2, %rax
je 0x91f2c
movq 0x6f0bd(%rip), %rdi     # 0x100f98
leaq 0x24dd5(%rip), %rsi     # 0xb6cb7
callq 0x84d0
movq %rax, %rdi
leaq 0x24dfc(%rip), %rsi     # 0xb6ced
callq 0x84d0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x383b0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x8150
movq %rax, %rdi
leaq 0x2169a(%rip), %rsi     # 0xb35b7
callq 0x84d0
movl $0x1, %edi
callq 0x85d0
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x53720
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl $0x1, %esi
callq 0x53720
movq -0x28(%rbp), %rsi
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0xe0, %rsi
callq 0x8f430
testb $0x1, %al
jne 0x91f8f
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdi
addq $0xe0, %rsi
callq 0x8f430
testb $0x1, %al
jne 0x91f8f
jmp 0x91fbc
movq -0x28(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x18(%rbp), %rsi
callq 0xdab0
movq -0x28(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x20(%rbp), %rsi
callq 0xdab0
jmp 0x9209d
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x34(%rbp)
subl $0x2, %eax
je 0x91fe4
jmp 0x91fcd
movl -0x34(%rbp), %eax
subl $0x3, %eax
je 0x92013
jmp 0x91fd7
movl -0x34(%rbp), %eax
subl $0x4, %eax
je 0x92042
jmp 0x92073
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x3a480
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x3a480
movq -0x10(%rbp), %rax
movl $0x3, 0x78(%rax)
jmp 0x92075
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x3a480
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x3a480
movq -0x10(%rbp), %rax
movl $0x4, 0x78(%rax)
jmp 0x92075
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0x3a480
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x3a480
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x93750
jmp 0x92075
jmp 0x92075
movq -0x28(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x18(%rbp), %rsi
callq 0xdab0
movq -0x28(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x20(%rbp), %rsi
callq 0xdab0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)