// File: /workspace/github_cpp_makefile_star2_O2/czinn[P]homeworlds/game_io.cc
// Function: read_action(std::istream&, Action&, std::map<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<int>, std::allocator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&)
std::string read_action(std::istream& is, Action& action,
                        std::map<int, std::string>& system_names) {
  std::map<std::string, int> name_lookup;
  for (const auto& it : system_names) {
    name_lookup.emplace(it.second, it.first);
  }

  std::string type, system_name, colour;
  is >> type;

  if (type == "PASS") {
    action.type = PASS;
  } else if (type == "ATTACK") {
    action.type = ATTACK;
    is >> action.ship;
    is >> system_name;
    action.system = name_lookup[system_name];
  } else if (type == "DISCOVER") {
    action.type = DISCOVER;
    is >> action.ship;
    is >> system_name;
    action.system = name_lookup[system_name];
    is >> action.target;
    is >> system_name;
    return system_name;
  } else if (type == "MOVE") {
    action.type = TRAVEL;
    is >> action.ship;
    is >> system_name;
    action.system = name_lookup[system_name];
    is >> system_name;
    action.system_target = name_lookup[system_name];
  } else if (type == "BUILD") {
    action.type = BUILD;
    is >> action.ship;
    is >> system_name;
    action.system = name_lookup[system_name];
  } else if (type == "TRADE") {
    action.type = TRADE;
    is >> action.ship;
    is >> action.target;
    is >> system_name;
    action.system = name_lookup[system_name];
  } else if (type == "SACRIFICE") {
    action.type = SACRIFICE;
    is >> action.ship;
    is >> system_name;
    action.system = name_lookup[system_name];
  } else if (type == "CATASTROPHE") {
    action.type = CATASTROPHE;
    is >> system_name;
    action.system = name_lookup[system_name];
    is >> std::ws;
    is >> colour;
    if (colour == "r" || colour == "R") {
      action.ship = Pyramid{ZERO, RED};
    } else if (colour == "y" || colour == "Y") {
      action.ship = Pyramid{ZERO, YELLOW};
    } else if (colour == "g" || colour == "G") {
      action.ship = Pyramid{ZERO, GREEN};
    } else {
      action.ship = Pyramid{ZERO, BLUE};
    }
  }

  return "";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r15
leaq 0x70(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rdi, %rbx
movq 0x18(%rcx), %rbp
addq $0x8, %r12
leaq 0x68(%rsp), %r13
cmpq %r12, %rbp
je 0x89ae
leaq 0x20(%rbp), %rdx
leaq 0x28(%rbp), %rsi
movq %r13, %rdi
callq 0x926c
movq %rbp, %rdi
callq 0x2150
movq %rax, %rbp
jmp 0x898c
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
andq $0x0, -0x8(%r12)
movb %bpl, (%rax)
movb %bpl, (%r12)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %bpl, (%rax)
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x17c0(%rip), %rsi      # 0xa1ba
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8a0c
pushq $0x4
jmp 0x8a59
leaq 0x17ea(%rip), %rsi      # 0xa1fd
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8aaf
movl $0x1, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
movl (%rax), %ebp
pushq $0x8
popq %rax
movl %ebp, (%r14,%rax)
leaq 0x1754(%rip), %rsi      # 0xa1b9
leaq 0x7(%rsp), %rdx
movq %rbx, %rdi
callq 0x3f10
leaq 0x48(%rsp), %rdi
callq 0x20c0
leaq 0x8(%rsp), %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x68(%rsp), %rdi
callq 0x8ebc
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x174e(%rip), %rsi      # 0xa204
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8b3c
movl $0x2, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
movl (%rax), %eax
movl %eax, 0x8(%r14)
addq $0x18, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
cmpq %r12, %rcx
je 0x8bf6
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x8bfe
leaq 0x16ca(%rip), %rsi      # 0xa20d
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8bac
movl $0x3, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
movl (%rax), %eax
movl %eax, 0x8(%r14)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
movl (%rax), %ebp
pushq $0x14
jmp 0x8a59
leaq 0x165f(%rip), %rsi      # 0xa212
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8c1c
movl $0x4, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
jmp 0x8a55
movups (%r12), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %r12, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
jmp 0x8a72
leaq 0x15f5(%rip), %rsi      # 0xa218
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8c72
movl $0x5, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x18(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
jmp 0x8a55
leaq 0x15a5(%rip), %rsi      # 0xa21e
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8cbc
movl $0x6, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x85dd
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
jmp 0x8a55
leaq 0x1565(%rip), %rsi      # 0xa228
leaq 0x28(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8a5e
movl $0x7, 0x4(%r14)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8e56
movl (%rax), %eax
movl %eax, 0x8(%r14)
movq %r15, %rdi
callq 0x2190
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2230
leaq 0x1519(%rip), %rsi      # 0xa234
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
jne 0x8d3e
leaq 0x14db(%rip), %rsi      # 0xa20b
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8d45
andl $0x0, 0xc(%r14)
jmp 0x8d77
leaq 0x14ea(%rip), %rsi      # 0xa236
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
jne 0x8d6f
leaq 0x14d7(%rip), %rsi      # 0xa238
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8d7e
andl $0x0, 0xc(%r14)
pushq $0x1
popq %rbp
pushq $0x10
jmp 0x8a59
leaq 0x14b5(%rip), %rsi      # 0xa23a
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
jne 0x8da8
leaq 0x14a2(%rip), %rsi      # 0xa23c
leaq 0x48(%rsp), %rdi
callq 0x8e49
testb %al, %al
je 0x8db1
andl $0x0, 0xc(%r14)
pushq $0x2
jmp 0x8d76
andl $0x0, 0xc(%r14)
pushq $0x3
jmp 0x8d76
jmp 0x8dbc
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20c0
leaq 0x8(%rsp), %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20c0
jmp 0x8de2
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x8ebc
movq %rbx, %rdi
callq 0x2300