// File: /workspace/github_cpp_makefile_star2_O3/Kei18[P]pibt/./src/solver/pps.cpp
// Function: PPS::SWAP(S*)
RES PPS::SWAP(S* s) {
  // swapping phase
  if (s->phase == SWAPPHASE::EVAC_H ||
      s->phase == SWAPPHASE::EVAC_L ||
      s->phase == SWAPPHASE::SWAP_DONE) {
    SWAP_PRIMITIVES(s);
    return RES::SUCCESS;
  }

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

  if (s->agents.size() == 2) {  // l.1
    if (aH->getNode() != target) {  // l.2
      PUSH(s);  // l.3
    } else {  // swap starts
      if (CLEAR(s)) {  // l.7
        if (s->phase != SWAPPHASE::CLEARING) {
          SWAP_PRIMITIVES(s);  // l.6
        }
      } else {
        if (FIND_NEW_VERTEX(s) == RES::SUCCESS) {
          SWAP(s);
        } else {
          // for avoid collision
          M.push_back(aH);
          M.push_back(aL);
        }
      }
    }
  } else if (s->agents.size() == 3) {
    if (s->phase != SWAPPHASE::CLEARING) {
      std::cout << "error@PPS::SWAP, there are three agents" << "\n";
      std::exit(1);
    }
    Agent* a = s->agents[2];  // l.10
    RES attempt = PUSH(a, s->area, true);  // l.11
    if (attempt == RES::FAIL) {  // l.12

      s->agents.erase(s->agents.end() - 1);  // l.13, pop
      isTmpGoals[a->getId()] = false;
      P->assign(a->getTask());
      a->releaseTask();
      a->setGoal(goals[a->getId()]);
      pushers.push_back(a);

      s->phase = SWAPPHASE::GO_TARGET;

      // avoid collision
      // M.push_back(s->agents[0]);
      // M.push_back(s->agents[1]);

      return FIND_NEW_VERTEX(s);  // l.14

    } else if (attempt == RES::SUCCESS) {

      if (a->getNode() == a->getGoal()) {

        s->agents.erase(s->agents.end() - 1);  // l.17
        P->assign(a->getTask());
        a->releaseTask();
        a->setGoal(goals[a->getId()]);  // l.17
        isTmpGoals[a->getId()] = false;

        swaperToPusher.push_back(a);

        if (s->agents.size() == 2) {
          s->phase = SWAPPHASE::GO_TARGET;
          SWAP(s);
        } else {
          std::cout << "error@PPS::SWAP, "
                    << "the number of agents should be two" << "\n";
          std::exit(1);
        }
      } else {

        PUSH(s);  // l.18

      }
    }
  } else {
    std::cout << "error@PPS::SWAP, "
              << "the number of agents should be"
              << " less than four" << "\n";
    std::exit(1);
  }

  return RES::SUCCESS;  // l.19
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x78(%rsi), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
ja 0x397bb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ba20
jmp 0x39925
movq 0x8(%r14), %rcx
movq (%rcx), %r12
movq %r12, 0x18(%rsp)
movq 0x8(%rcx), %r15
movq %r15, 0x10(%rsp)
movq 0x10(%r14), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq $0x3, %rdx
je 0x3982d
cmpq $0x2, %rdx
jne 0x39aab
movq 0x28(%r14), %rax
movq 0x8(%r12), %rcx
cmpq (%rax), %rcx
jne 0x3991a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3bc22
testb %al, %al
je 0x39936
xorl %ebp, %ebp
cmpl $0x1, 0x78(%r14)
je 0x39927
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ba20
jmp 0x39927
cmpl $0x1, %eax
jne 0x39ad9
movq 0x10(%rcx), %r15
movq %r15, 0x8(%rsp)
leaq 0x60(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq 0x39c78
testl %eax, %eax
je 0x3990c
cmpl $0x1, %eax
jne 0x39925
movq 0x10(%r14), %rsi
movb $0x1, %al
testb %al, %al
jne 0x39881
leaq -0x8(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0x65b0
movq 0x10(%r14), %rsi
addq $-0x8, %rsi
movq %rsi, 0x10(%r14)
movslq (%r15), %rcx
leal 0x3f(%rcx), %eax
testq %rcx, %rcx
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x160(%rbx), %rax
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x3f(%rdx), %rsi
andq %rcx, %rsi
xorl %edi, %edi
cmpq %rdx, %rsi
setbe %dil
movq $-0x2, %rdx
rolq %cl, %rdx
andq %rdx, -0x8(%rax,%rdi,8)
movq 0x10(%rbx), %rdi
movq 0x18(%r15), %rsi
callq 0x25936
movq %r15, %rdi
callq 0x19392
movslq (%r15), %rax
movq 0x148(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, 0x10(%r15)
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x3997e
movq %r15, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x3998c
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
je 0x399a3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3aea8
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c93e
testl %eax, %eax
je 0x39a5c
leaq 0xe0(%rbx), %r14
movq 0xe8(%rbx), %rsi
cmpq 0xf0(%rbx), %rsi
je 0x39a6c
movq %r12, (%rsi)
movq 0xe8(%rbx), %rsi
addq $0x8, %rsi
movq %rsi, 0xe8(%rbx)
jmp 0x39a80
leaq 0x68(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0x18f28
movl $0x0, 0x78(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c93e
movl %eax, %ebp
jmp 0x39927
movq 0x10(%r14), %rsi
movb $0x1, %al
testb %al, %al
jne 0x399c0
leaq -0x8(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0x65b0
movq 0x10(%r14), %rsi
addq $-0x8, %rsi
movq %rsi, 0x10(%r14)
movq 0x10(%rbx), %rdi
movq 0x18(%r15), %rsi
callq 0x25936
movq %r15, %rdi
callq 0x19392
movslq (%r15), %rcx
leal 0x3f(%rcx), %eax
testq %rcx, %rcx
movq 0x148(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, 0x10(%r15)
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x160(%rbx), %rax
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x3f(%rdx), %rsi
andq %rcx, %rsi
xorl %edi, %edi
cmpq %rdx, %rsi
setbe %dil
movq $-0x2, %rdx
rolq %cl, %rdx
andq %rdx, -0x8(%rax,%rdi,8)
leaq 0xb0(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3d62a
movq 0x10(%r14), %rax
subq 0x8(%r14), %rax
cmpq $0x10, %rax
jne 0x39b05
movl $0x0, 0x78(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3978e
jmp 0x39925
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x18f28
movq 0xe8(%rbx), %rsi
cmpq 0xf0(%rbx), %rsi
je 0x39a99
movq %r15, (%rsi)
addq $0x8, 0xe8(%rbx)
jmp 0x39925
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x18f28
jmp 0x39925
movq 0x284f6(%rip), %rdi     # 0x61fa8
leaq 0x11a6e(%rip), %rsi     # 0x4b527
callq 0x6360
leaq 0x11a97(%rip), %rsi     # 0x4b55c
movq %rax, %rdi
callq 0x6360
leaq 0x11aa7(%rip), %rsi     # 0x4b57b
movq %rax, %rdi
jmp 0x39ae7
movq 0x284c8(%rip), %rdi     # 0x61fa8
leaq 0x11a18(%rip), %rsi     # 0x4b4ff
callq 0x6360
leaq 0xea70(%rip), %rsi      # 0x48563
movq %rax, %rdi
callq 0x6360
movl $0x1, %edi
callq 0x6440
movq 0x2849c(%rip), %rdi     # 0x61fa8
leaq 0x11a14(%rip), %rsi     # 0x4b527
callq 0x6360
leaq 0x11a1a(%rip), %rsi     # 0x4b539
jmp 0x39ad4
nop