// File: /workspace/github_cpp_makefile_star2_O3/czinn[P]homeworlds/game.cc
// Function: Game::legal_system_actions(std::vector<Action, std::allocator<Action>>&, System const&, ActionType) const
void Game::legal_system_actions(std::vector<Action>& result,
                                const System& system, ActionType type) const {
  std::set<Action> actions;

  switch(type) {
    case PASS:
      break;

    case ATTACK: {
        Size largest = ZERO;
        for (const Ship& ship : system.ships) {
          if (ship.player == cur_player_ && ship.pyramid.size > largest) {
            largest = ship.pyramid.size;
          }
        }
        if (largest == ZERO) {
          break;

        }
        for (const Ship& ship : system.ships) {
          if (ship.player != cur_player_ && ship.pyramid.size <= largest) {
            actions.insert(
                Action{cur_player_, ATTACK, system.id, ship.pyramid});
          }
        }
      }
      break;

    case DISCOVER:
      for (const auto& it : stash_) {
        if (connected(system, it.first) && it.second > 0) {
          for (const Ship& ship : system.ships) {
            if (ship.player == cur_player_) {
              actions.insert(Action{cur_player_, DISCOVER,
                  system.id, ship.pyramid, 0, it.first});
            }
          }
        }
      }
      break;

    case TRAVEL:
      for (const auto& to_system : systems_) {
        if (connected(system, to_system)) {
          for (const Ship& ship : system.ships) {
            if (ship.player == cur_player_) {
              actions.insert(Action{cur_player_, TRAVEL,
                  system.id, ship.pyramid, to_system.id});
            }
          }
        }
      }
      break;

    case BUILD:
      for (Colour colour : { RED, YELLOW, GREEN, BLUE }) {
        if (colour_available(system, cur_player_, colour, false)) {
          Pyramid p = smallest_of_colour(colour);
          if (p.size != ZERO && stash_.at(p) > 0) {
            actions.insert(Action{cur_player_, BUILD, system.id, p});
          }
        }
      }
      break;

    case TRADE:
      for (const Ship& ship : system.ships) {
        if (ship.player == cur_player_) {
          for (Colour colour : { RED, YELLOW, GREEN, BLUE }) {
            Pyramid trade_pyramid{ship.pyramid.size, colour};
            if (colour != ship.pyramid.colour && stash_.at(trade_pyramid) > 0) {
              actions.insert(Action{cur_player_, TRADE,
                  system.id, ship.pyramid, 0, trade_pyramid});
            }
          }
        }
      }
      break;

    case SACRIFICE:
      for (const Ship& ship : system.ships) {
        if (ship.player == cur_player_) {
          actions.insert(Action{cur_player_, SACRIFICE,
              system.id, ship.pyramid});
        }
      }
      break;

    case CATASTROPHE: {
        int colour_counts[4] = {0};
        for (const Pyramid& star : system.stars) {
          colour_counts[star.colour]++;
        }
        for (const Ship& ship : system.ships) {
          if (++colour_counts[ship.pyramid.colour] == 4) {
            actions.insert(Action{cur_player_, CATASTROPHE,
                system.id, ship.pyramid});
          }
        }
      }
      break;
  }

  result.insert(result.end(), actions.begin(), actions.end());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r15
movq %rsi, 0x40(%rsp)
leaq 0x50(%rsp), %rdx
movl $0x0, (%rdx)
xorl %eax, %eax
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
decl %ecx
cmpl $0x6, %ecx
ja 0x346f
movq %rdi, %r12
leaq 0x8064(%rip), %rax      # 0xb050
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
cmpq %rbp, %r13
je 0x346f
movl 0x4(%r12), %eax
xorl %ebx, %ebx
movq %r13, %rcx
movl %ebx, %edx
movl 0x4(%rcx), %ebx
cmpl %edx, %ebx
cmovlel %edx, %ebx
cmpl %eax, (%rcx)
cmovnel %edx, %ebx
addq $0xc, %rcx
cmpq %rbp, %rcx
jne 0x3010
cmpq %rbp, %r13
sete %al
testl %ebx, %ebx
sete %cl
orb %al, %cl
jne 0x346f
movq %rsp, %r14
movl 0x4(%r12), %eax
cmpl %eax, (%r13)
je 0x3088
cmpl %ebx, 0x4(%r13)
jg 0x3088
movl %eax, (%rsp)
movl $0x1, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r13), %rax
movq %rax, 0xc(%rsp)
movq $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x4ce6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x303e
jmp 0x346f
movq 0x20(%r15), %rbp
movq 0x28(%r15), %rcx
cmpq %rcx, %rbp
je 0x346f
leaq 0x38(%r12), %r14
leaq 0x20(%rsp), %r13
movq %rcx, 0x28(%rsp)
movl (%rbp), %eax
cmpl 0x4(%r12), %eax
jne 0x3144
movaps 0x7f55(%rip), %xmm0     # 0xb020
movaps %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
movl 0x30(%rsp,%rbx), %eax
movl 0x4(%rbp), %ecx
movl %ecx, 0x20(%rsp)
movl %eax, 0x24(%rsp)
cmpl 0x8(%rbp), %eax
je 0x3135
movq %r14, %rdi
movq %r13, %rsi
callq 0x4330
cmpl $0x0, (%rax)
jle 0x3135
movl 0x4(%r12), %eax
movl %eax, (%rsp)
movl $0x5, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%rbp), %rax
movq %rax, 0xc(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %rsp, %rsi
callq 0x4ce6
addq $0x4, %rbx
cmpq $0x10, %rbx
jne 0x30d2
movq 0x28(%rsp), %rcx
addq $0xc, %rbp
cmpq %rcx, %rbp
jne 0x30b6
jmp 0x346f
movq 0x20(%r12), %rbx
movq 0x28(%r12), %rax
movq %rax, 0x28(%rsp)
cmpq %rax, %rbx
je 0x346f
movq %rsp, %rbp
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x31a7
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rsi
cmpq %rsi, %rdx
je 0x319e
movl (%rax), %edi
movq %rdx, %r8
cmpl (%r8), %edi
je 0x31fb
addq $0x8, %r8
cmpq %rsi, %r8
jne 0x3190
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x3186
movq 0x20(%r15), %r14
movq 0x28(%r15), %r13
cmpq %r13, %r14
je 0x31fb
movl (%r14), %eax
cmpl 0x4(%r12), %eax
jne 0x31f5
movl %eax, (%rsp)
movl $0x3, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r14), %rax
movq %rax, 0xc(%rsp)
movl (%rbx), %eax
movl %eax, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x4ce6
addq $0xc, %r14
jmp 0x31af
addq $0x38, %rbx
cmpq 0x28(%rsp), %rbx
jne 0x3171
jmp 0x346f
movaps 0x7e0a(%rip), %xmm0     # 0xb020
movaps %xmm0, 0x30(%rsp)
leaq 0x38(%r12), %r13
xorl %ebx, %ebx
leaq 0x20(%rsp), %rbp
leaq 0x48(%rsp), %r14
movq 0x20(%r15), %rax
movq 0x28(%r15), %rcx
cmpq %rcx, %rax
je 0x32b4
movl 0x30(%rsp,%rbx), %esi
movl 0x4(%r12), %edx
cmpl %edx, (%rax)
jne 0x324b
cmpl %esi, 0x8(%rax)
je 0x3256
addq $0xc, %rax
cmpq %rcx, %rax
jne 0x3242
jmp 0x32b4
movq %r12, %rdi
callq 0x2996
movq %rax, 0x20(%rsp)
testl %eax, %eax
je 0x32b4
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4330
cmpl $0x0, (%rax)
jle 0x32b4
movl 0x4(%r12), %eax
movl %eax, (%rsp)
movl $0x4, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0xc(%rsp)
movq $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq %r14, %rdi
movq %rsp, %rsi
callq 0x4ce6
addq $0x4, %rbx
cmpq $0x10, %rbx
jne 0x322c
jmp 0x346f
movq 0x50(%r12), %r13
leaq 0x40(%r12), %rax
movq %rax, 0x28(%rsp)
cmpq %rax, %r13
je 0x346f
movq %rsp, %r14
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x3300
movl 0x20(%r13), %edx
cmpl %edx, (%rax)
je 0x335c
addq $0x8, %rax
cmpq %rcx, %rax
jne 0x32f3
cmpl $0x0, 0x28(%r13)
jle 0x335c
movq 0x20(%r15), %rbx
movq 0x28(%r15), %rbp
cmpq %rbp, %rbx
je 0x335c
movl (%rbx), %eax
cmpl 0x4(%r12), %eax
jne 0x3356
movl %eax, (%rsp)
movl $0x2, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%rbx), %rax
movq %rax, 0xc(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x20(%r13), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x4ce6
addq $0xc, %rbx
jmp 0x330f
movq %r13, %rdi
callq 0x2200
movq %rax, %r13
cmpq 0x28(%rsp), %rax
jne 0x32e2
jmp 0x346f
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
cmpq %rbp, %r13
je 0x346f
leaq 0x48(%rsp), %rbx
movq %rsp, %r14
movl (%r13), %eax
cmpl 0x4(%r12), %eax
jne 0x33d2
movl %eax, (%rsp)
movl $0x6, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r13), %rax
movq %rax, 0xc(%rsp)
movq $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ce6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x3390
jmp 0x346f
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x3402
movl 0x4(%rax), %edx
incl 0x30(%rsp,%rdx,4)
addq $0x8, %rax
jmp 0x33f0
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
cmpq %rbp, %r13
je 0x346f
leaq 0x48(%rsp), %rbx
movq %rsp, %r14
movl 0x8(%r13), %eax
movl 0x30(%rsp,%rax,4), %ecx
incl %ecx
movl %ecx, 0x30(%rsp,%rax,4)
cmpl $0x4, %ecx
jne 0x3466
movl 0x4(%r12), %eax
movl %eax, (%rsp)
movl $0x7, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r13), %rax
movq %rax, 0xc(%rsp)
movq $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ce6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x3417
movq 0x40(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x60(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x4e24
leaq 0x48(%rsp), %rdi
callq 0x458a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
jmp 0x34b2
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x458a
movq %rbx, %rdi
callq 0x22d0