// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0x50(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rsi, 0x40(%rsp)
decl %ecx
cmpl $0x6, %ecx
ja 0x31eb
movq %rdx, %r15
movq %rdi, %r12
leaq 0x724f(%rip), %rax      # 0xa050
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
movl 0x4(%r12), %eax
xorl %ebx, %ebx
movq %r13, %rcx
cmpq %rbp, %rcx
je 0x30ac
movl 0x4(%rcx), %edx
cmpl %ebx, %edx
cmovlel %ebx, %edx
cmpl %eax, (%rcx)
cmovel %edx, %ebx
addq $0xc, %rcx
jmp 0x2e1c
movq 0x20(%r15), %r14
movq 0x28(%r15), %rcx
leaq 0x38(%r12), %r13
leaq 0x20(%rsp), %rbp
movq %rcx, 0x28(%rsp)
cmpq %rcx, %r14
je 0x31eb
movl (%r14), %eax
cmpl 0x4(%r12), %eax
jne 0x2ee7
movaps 0x71b3(%rip), %xmm0     # 0xa020
movaps %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
cmpq $0x10, %rbx
je 0x2ee2
movl 0x30(%rsp,%rbx), %eax
movl 0x4(%r14), %ecx
movl %ecx, 0x20(%rsp)
movl %eax, 0x24(%rsp)
cmpl 0x8(%r14), %eax
je 0x2edc
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3f4c
cmpl $0x0, (%rax)
jle 0x2edc
movl 0x4(%r12), %eax
movl %eax, (%rsp)
movl $0x5, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r14), %rax
movq %rax, 0xc(%rsp)
andl $0x0, 0x14(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %rsp, %rsi
callq 0x49f4
addq $0x4, %rbx
jmp 0x2e74
movq 0x28(%rsp), %rcx
addq $0xc, %r14
jmp 0x2e4f
movq 0x20(%r12), %rbx
movq 0x28(%r12), %rax
movq %rax, 0x28(%rsp)
movq %rsp, %r13
cmpq 0x28(%rsp), %rbx
je 0x31eb
movq %r15, %rdi
movq %rbx, %rsi
callq 0x32a5
testb %al, %al
je 0x2f6d
movq 0x20(%r15), %rbp
movq 0x28(%r15), %r14
cmpq %r14, %rbp
je 0x2f6d
movl (%rbp), %eax
cmpl 0x4(%r12), %eax
jne 0x2f67
movl %eax, (%rsp)
movl $0x3, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%rbp), %rax
movq %rax, 0xc(%rsp)
movl (%rbx), %eax
movl %eax, 0x14(%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x49f4
addq $0xc, %rbp
jmp 0x2f24
addq $0x38, %rbx
jmp 0x2f02
movaps 0x70a6(%rip), %xmm0     # 0xa020
movaps %xmm0, 0x30(%rsp)
leaq 0x38(%r12), %r13
xorl %ebp, %ebp
leaq 0x20(%rsp), %rbx
cmpq $0x10, %rbp
je 0x31eb
movl 0x30(%rsp,%rbp), %r14d
movl 0x4(%r12), %esi
movq %r15, %rdi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x3243
testb %al, %al
je 0x300d
movq %r12, %rdi
movl %r14d, %esi
callq 0x2888
movq %rax, 0x20(%rsp)
testl %eax, %eax
je 0x300d
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3f4c
cmpl $0x0, (%rax)
jle 0x300d
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)
andq $0x0, 0x14(%rsp)
andl $0x0, 0x1c(%rsp)
leaq 0x48(%rsp), %rdi
movq %rsp, %rsi
callq 0x49f4
addq $0x4, %rbp
jmp 0x2f8b
movq 0x50(%r12), %r13
leaq 0x40(%r12), %rax
movq %rax, 0x28(%rsp)
cmpq 0x28(%rsp), %r13
je 0x31eb
leaq 0x20(%r13), %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3284
testb %al, %al
je 0x309c
cmpl $0x0, 0x28(%r13)
jle 0x309c
movq 0x20(%r15), %rbx
movq 0x28(%r15), %r14
cmpq %r14, %rbx
je 0x309c
movl (%rbx), %eax
cmpl 0x4(%r12), %eax
jne 0x3096
movl %eax, (%rsp)
movl $0x2, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%rbx), %rax
movq %rax, 0xc(%rsp)
andl $0x0, 0x14(%rsp)
movq (%rbp), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %rsp, %rsi
callq 0x49f4
addq $0xc, %rbx
jmp 0x3052
movq %r13, %rdi
callq 0x2210
movq %rax, %r13
jmp 0x3025
testl %ebx, %ebx
je 0x31eb
movq %rsp, %r14
cmpq %rbp, %r13
je 0x31eb
movl 0x4(%r12), %eax
cmpl %eax, (%r13)
je 0x3104
cmpl %ebx, 0x4(%r13)
jg 0x3104
movl %eax, (%rsp)
movl $0x1, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r13), %rax
movq %rax, 0xc(%rsp)
andq $0x0, 0x14(%rsp)
andl $0x0, 0x1c(%rsp)
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x49f4
addq $0xc, %r13
jmp 0x30b7
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
leaq 0x48(%rsp), %rbx
movq %rsp, %r14
cmpq %rbp, %r13
je 0x31eb
movl (%r13), %eax
cmpl 0x4(%r12), %eax
jne 0x315f
movl %eax, (%rsp)
movl $0x6, 0x4(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq 0x4(%r13), %rax
movq %rax, 0xc(%rsp)
andq $0x0, 0x14(%rsp)
andl $0x0, 0x1c(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49f4
addq $0xc, %r13
jmp 0x311a
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x3187
movl 0x4(%rax), %edx
incl 0x30(%rsp,%rdx,4)
addq $0x8, %rax
jmp 0x3175
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
leaq 0x48(%rsp), %rbx
movq %rsp, %r14
cmpq %rbp, %r13
je 0x31eb
movl 0x8(%r13), %eax
movl 0x30(%rsp,%rax,4), %ecx
incl %ecx
movl %ecx, 0x30(%rsp,%rax,4)
cmpl $0x4, %ecx
jne 0x31e5
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)
andq $0x0, 0x14(%rsp)
andl $0x0, 0x1c(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49f4
addq $0xc, %r13
jmp 0x3197
movq 0x40(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x60(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x3f92
leaq 0x48(%rsp), %rdi
callq 0x41b2
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
jmp 0x322e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x41b2
movq %rbx, %rdi
callq 0x2300