// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %rbx
leaq 0x70(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq 0x18(%r12), %r13
addq $0x8, %r12
cmpq %r12, %r13
je 0x8ec5
leaq 0x68(%rsp), %rbp
leaq 0x20(%r13), %rdx
leaq 0x28(%r13), %rsi
movq %rbp, %rdi
callq 0x97f2
movq %r13, %rdi
callq 0x2140
movq %rax, %r13
cmpq %r12, %rax
jne 0x8ea5
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %r12d, %r12d
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq %r12, -0x8(%r13)
movb %r12b, (%r13)
leaq 0x58(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %r12, -0x8(%rbp)
movb %r12b, (%rbp)
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x22bc(%rip), %rsi      # 0xb1ca
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x90b7
leaq 0x22e6(%rip), %rsi      # 0xb20d
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x90c1
leaq 0x22d4(%rip), %rsi      # 0xb214
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x90fe
leaq 0x22c4(%rip), %rsi      # 0xb21d
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9176
leaq 0x22b0(%rip), %rsi      # 0xb222
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9256
leaq 0x229d(%rip), %rsi      # 0xb228
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x92b4
leaq 0x228a(%rip), %rsi      # 0xb22e
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x92f5
leaq 0x227b(%rip), %rsi      # 0xb238
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
jne 0x91d4
movl $0x7, 0x4(%r14)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
movl (%rax), %eax
movl %eax, 0x8(%r14)
movq %r15, %rdi
callq 0x2180
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x222f(%rip), %rsi      # 0xb244
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x932a
leaq 0x21ed(%rip), %rsi      # 0xb21b
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x932a
leaq 0x21ff(%rip), %rsi      # 0xb246
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9334
leaq 0x21e8(%rip), %rsi      # 0xb248
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9334
leaq 0x21d1(%rip), %rsi      # 0xb24a
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9344
leaq 0x21ba(%rip), %rsi      # 0xb24c
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9344
movl $0x0, 0xc(%r14)
movl $0x3, %r12d
jmp 0x9352
movl $0x4, %eax
jmp 0x91d0
movl $0x1, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
movl (%rax), %r12d
movl $0x8, %eax
jmp 0x91d0
movl $0x2, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
movl (%rax), %eax
movl %eax, 0x8(%r14)
addq $0x18, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
cmpq %r13, %rcx
je 0x928b
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x9293
movl $0x3, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
movl (%rax), %eax
movl %eax, 0x8(%r14)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
movl (%rax), %r12d
movl $0x14, %eax
movl %r12d, (%r14,%rax)
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1fe7(%rip), %rdx      # 0xb1c9
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4974
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9204
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x921b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x9237
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x68(%rsp), %rdi
callq 0x9484
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
jmp 0x90f1
movups (%r13), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %r13, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
jmp 0x91ed
movl $0x5, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x18(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
jmp 0x90f1
movl $0x6, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x893f
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9408
jmp 0x90f1
movl $0x0, 0xc(%r14)
jmp 0x9352
movl $0x0, 0xc(%r14)
movl $0x1, %r12d
jmp 0x9352
movl $0x0, 0xc(%r14)
movl $0x2, %r12d
movl $0x10, %eax
jmp 0x91d0
jmp 0x935e
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9378
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x938f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x93b0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x93b0
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x9484
movq %rbx, %rdi
callq 0x22d0