// File: /workspace/github_cpp_makefile_star2_O1/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 0x34e7
movq %rdi, %r12
leaq 0x8042(%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 0x3480
movl 0x4(%r12), %eax
xorl %edx, %edx
movq %r13, %rcx
movl 0x4(%rcx), %ebx
cmpl %edx, %ebx
cmovlel %edx, %ebx
cmpl %eax, (%rcx)
cmovnel %edx, %ebx
addq $0xc, %rcx
movl %ebx, %edx
cmpq %rbp, %rcx
jne 0x3032
jmp 0x3482
movq 0x20(%r15), %rbp
movq 0x28(%r15), %rcx
cmpq %rcx, %rbp
je 0x34e7
leaq 0x38(%r12), %r14
leaq 0x20(%rsp), %r13
movq %rcx, 0x28(%rsp)
movl (%rbp), %eax
cmpl 0x4(%r12), %eax
jne 0x30fd
movaps 0x7f9c(%rip), %xmm0     # 0xb020
movups %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 0x30ee
movq %r14, %rdi
movq %r13, %rsi
callq 0x4408
cmpl $0x0, (%rax)
jle 0x30ee
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 0x4dd6
addq $0x4, %rbx
cmpq $0x10, %rbx
jne 0x308b
movq 0x28(%rsp), %rcx
addq $0xc, %rbp
cmpq %rcx, %rbp
jne 0x306f
jmp 0x34e7
movq 0x20(%r12), %rbx
movq 0x28(%r12), %rax
movq %rax, 0x28(%rsp)
cmpq %rax, %rbx
je 0x34e7
movq %rsp, %rbp
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
sete %dl
je 0x317a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdi
leaq 0x8(%rsi), %r8
xorl %edx, %edx
cmpq %rdi, %rsi
je 0x316e
movl (%rax), %r9d
cmpl (%rsi), %r9d
je 0x317a
movq %r8, %r11
cmpq %rdi, %r11
je 0x316e
movq %r11, %r10
addq $0x8, %r11
cmpl (%r10), %r9d
jne 0x3158
cmpq %rdi, %r10
jne 0x317a
addq $0x8, %rax
cmpq %rcx, %rax
sete %dl
jne 0x3148
testb $0x1, %dl
je 0x31d3
movq 0x20(%r15), %r14
movq 0x28(%r15), %r13
cmpq %r13, %r14
je 0x31d3
movl 0x4(%r12), %eax
cmpl %eax, (%r14)
jne 0x31cd
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 0x4dd6
addq $0xc, %r14
jmp 0x3187
addq $0x38, %rbx
cmpq 0x28(%rsp), %rbx
jne 0x312a
jmp 0x34e7
movaps 0x7e32(%rip), %xmm0     # 0xb020
movups %xmm0, 0x30(%rsp)
leaq 0x38(%r12), %r13
xorl %ebx, %ebx
leaq 0x20(%rsp), %rbp
leaq 0x48(%rsp), %r14
movl 0x30(%rsp,%rbx), %esi
movq 0x20(%r15), %rdx
movq 0x28(%r15), %rax
cmpq %rax, %rdx
setne %cl
je 0x3244
movl 0x4(%r12), %edi
cmpl %edi, (%rdx)
jne 0x3226
cmpl %esi, 0x8(%rdx)
je 0x3244
addq $0xc, %rdx
cmpq %rax, %rdx
setne %cl
je 0x3244
movq %rdx, %r8
addq $0xc, %rdx
cmpl %edi, (%r8)
jne 0x322a
cmpl %esi, 0x8(%r8)
jne 0x322a
testb %cl, %cl
je 0x32a6
movq %r12, %rdi
callq 0x29a4
movq %rax, 0x20(%rsp)
testl %eax, %eax
je 0x32a6
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4408
cmpl $0x0, (%rax)
jle 0x32a6
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 0x4dd6
addq $0x4, %rbx
cmpq $0x10, %rbx
jne 0x3204
jmp 0x34e7
movq 0x50(%r12), %r13
leaq 0x40(%r12), %rax
movq %rax, 0x28(%rsp)
cmpq %rax, %r13
je 0x34e7
movq %rsp, %r14
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rax
cmpq %rax, %rcx
sete %dl
je 0x3307
movl 0x20(%r13), %esi
cmpl %esi, (%rcx)
jne 0x32f0
xorl %edx, %edx
jmp 0x3307
addq $0x8, %rcx
cmpq %rax, %rcx
sete %dl
je 0x3307
leaq 0x8(%rcx), %rdi
cmpl %esi, (%rcx)
movq %rdi, %rcx
jne 0x32f4
testb %dl, %dl
je 0x3367
cmpl $0x0, 0x28(%r13)
jle 0x3367
movq 0x20(%r15), %rbx
movq 0x28(%r15), %rbp
cmpq %rbp, %rbx
je 0x3367
movl 0x4(%r12), %eax
cmpl %eax, (%rbx)
jne 0x3361
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 0x4dd6
addq $0xc, %rbx
jmp 0x331a
movq %r13, %rdi
callq 0x2200
movq %rax, %r13
cmpq 0x28(%rsp), %rax
jne 0x32d4
jmp 0x34e7
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
cmpq %rbp, %r13
je 0x34e7
leaq 0x48(%rsp), %rbx
movq %rsp, %r14
movl 0x4(%r12), %eax
cmpl %eax, (%r13)
jne 0x33dd
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 0x4dd6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x339b
jmp 0x34e7
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x340d
movl 0x4(%rax), %edx
incl 0x30(%rsp,%rdx,4)
addq $0x8, %rax
jmp 0x33fb
movq 0x20(%r15), %r13
movq 0x28(%r15), %rbp
cmpq %rbp, %r13
je 0x34e7
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 0x3475
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 0x4dd6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x3426
jmp 0x34e7
xorl %ebx, %ebx
testl %ebx, %ebx
sete %al
cmpq %rbp, %r13
sete %cl
orb %al, %cl
jne 0x34e7
movq %rsp, %r14
movl 0x4(%r12), %eax
cmpl %eax, (%r13)
je 0x34de
cmpl %ebx, 0x4(%r13)
jg 0x34de
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 0x4dd6
addq $0xc, %r13
cmpq %rbp, %r13
jne 0x3494
movq 0x40(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x60(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x4f12
leaq 0x48(%rsp), %rdi
callq 0x466c
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
jmp 0x352a
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x466c
movq %rbx, %rdi
callq 0x22d0