// File: /workspace/github_cpp_makefile_star2_O1/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 0x90ee
leaq 0x68(%rsp), %rbp
leaq 0x20(%r13), %rdx
leaq 0x28(%r13), %rsi
movq %rbp, %rdi
callq 0x9a24
movq %r13, %rdi
callq 0x2140
movq %rax, %r13
cmpq %r12, %rax
jne 0x90ce
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 0x2093(%rip), %rsi      # 0xb1ca
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x92e0
leaq 0x20bd(%rip), %rsi      # 0xb20d
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x92ea
leaq 0x20ab(%rip), %rsi      # 0xb214
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9327
leaq 0x209b(%rip), %rsi      # 0xb21d
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x939f
leaq 0x2087(%rip), %rsi      # 0xb222
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x947f
leaq 0x2074(%rip), %rsi      # 0xb228
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x94dd
leaq 0x2061(%rip), %rsi      # 0xb22e
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x951e
leaq 0x2052(%rip), %rsi      # 0xb238
leaq 0x28(%rsp), %rdi
callq 0x2070
testl %eax, %eax
jne 0x93fd
movl $0x7, 0x4(%r14)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
movl (%rax), %eax
movl %eax, 0x8(%r14)
movq %r15, %rdi
callq 0x2180
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x2006(%rip), %rsi      # 0xb244
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9553
leaq 0x1fc4(%rip), %rsi      # 0xb21b
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x9553
leaq 0x1fd6(%rip), %rsi      # 0xb246
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x955d
leaq 0x1fbf(%rip), %rsi      # 0xb248
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x955d
leaq 0x1fa8(%rip), %rsi      # 0xb24a
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x956d
leaq 0x1f91(%rip), %rsi      # 0xb24c
leaq 0x48(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x956d
movl $0x0, 0xc(%r14)
movl $0x3, %r12d
jmp 0x957b
movl $0x4, %eax
jmp 0x93f9
movl $0x1, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
movl (%rax), %r12d
movl $0x8, %eax
jmp 0x93f9
movl $0x2, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
movl (%rax), %eax
movl %eax, 0x8(%r14)
addq $0x18, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
cmpq %r13, %rcx
je 0x94b4
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x94bc
movl $0x3, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
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 0x9638
movl (%rax), %r12d
movl $0x14, %eax
movl %r12d, (%r14,%rax)
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1dbe(%rip), %rdx      # 0xb1c9
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4a6a
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x942d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x9444
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x9460
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x68(%rsp), %rdi
callq 0x96b4
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 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
jmp 0x931a
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 0x9416
movl $0x5, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x18(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
jmp 0x931a
movl $0x6, 0x4(%r14)
leaq 0xc(%r14), %rsi
movq %r15, %rdi
callq 0x8b53
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2210
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9638
jmp 0x931a
movl $0x0, 0xc(%r14)
jmp 0x957b
movl $0x0, 0xc(%r14)
movl $0x1, %r12d
jmp 0x957b
movl $0x0, 0xc(%r14)
movl $0x2, %r12d
movl $0x10, %eax
jmp 0x93f9
jmp 0x9587
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x95a1
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x95b8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x95d9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x95d9
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x96b4
movq %rbx, %rdi
callq 0x22d0
nop