// File: 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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x128(%rbp)
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1f430
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1f450
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1f480
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x1f4b0
testb $0x1, %al
jne 0x1ea9a
jmp 0x1eb00
leaq -0x60(%rbp), %rdi
callq 0x1f4e0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdx
movq %rdx, %rsi
addq $0x8, %rsi
leaq -0x50(%rbp), %rdi
callq 0x1f500
movb %dl, -0x131(%rbp)
movq %rax, -0x130(%rbp)
jmp 0x1eaca
movb -0x131(%rbp), %al
movq -0x130(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movb %al, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1f550
jmp 0x1ea87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1f225
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x3320
leaq -0xd0(%rbp), %rdi
callq 0x3320
leaq -0xf0(%rbp), %rdi
callq 0x3320
movq -0x140(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x32e0
jmp 0x1eb3d
leaq 0x5712(%rip), %rsi      # 0x24256
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x141(%rbp)
jmp 0x1eb58
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x1eb64
jmp 0x1eb85
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x1f163
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1f201
leaq 0x570d(%rip), %rsi      # 0x24299
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x142(%rbp)
jmp 0x1eba0
movb -0x142(%rbp), %al
testb $0x1, %al
jne 0x1ebac
jmp 0x1ec0a
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1ebca
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ebdc
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x150(%rbp)
jmp 0x1ebf5
movq -0x150(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x1f161
leaq 0x568f(%rip), %rsi      # 0x242a0
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x151(%rbp)
jmp 0x1ec25
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x1ec34
jmp 0x1ecd4
movq -0x18(%rbp), %rax
movl $0x2, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1ec52
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ec64
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x160(%rbp)
jmp 0x1ec7d
movq -0x160(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x1e540
jmp 0x1eca0
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ecb2
movq -0x128(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3130
movl $0x1, -0xf4(%rbp)
jmp 0x1f1c4
leaq 0x55ce(%rip), %rsi      # 0x242a9
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x161(%rbp)
jmp 0x1ecef
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x1ecfe
jmp 0x1ed97
movq -0x18(%rbp), %rax
movl $0x3, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1ed1c
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ed2e
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x170(%rbp)
jmp 0x1ed47
movq -0x170(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ed69
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x178(%rbp)
jmp 0x1ed82
movq -0x178(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x1f15d
leaq 0x5510(%rip), %rsi      # 0x242ae
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x179(%rbp)
jmp 0x1edb2
movb -0x179(%rbp), %al
testb $0x1, %al
jne 0x1edbe
jmp 0x1ee1c
movq -0x18(%rbp), %rax
movl $0x4, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1eddc
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1edee
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x188(%rbp)
jmp 0x1ee07
movq -0x188(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x1f15b
leaq 0x5491(%rip), %rsi      # 0x242b4
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x189(%rbp)
jmp 0x1ee37
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x1ee43
jmp 0x1eeb4
movq -0x18(%rbp), %rax
movl $0x5, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1ee61
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x1e540
jmp 0x1ee74
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ee86
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x198(%rbp)
jmp 0x1ee9f
movq -0x198(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x1f159
leaq 0x53ff(%rip), %rsi      # 0x242ba
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x199(%rbp)
jmp 0x1eecf
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x1eedb
jmp 0x1ef39
movq -0x18(%rbp), %rax
movl $0x6, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x1e540
jmp 0x1eef9
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ef0b
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x1a8(%rbp)
jmp 0x1ef24
movq -0x1a8(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x1f157
leaq 0x5384(%rip), %rsi      # 0x242c4
leaq -0xb0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1a9(%rbp)
jmp 0x1ef54
movb -0x1a9(%rbp), %al
testb $0x1, %al
jne 0x1ef63
jmp 0x1f155
movq -0x18(%rbp), %rax
movl $0x7, 0x4(%rax)
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32e0
jmp 0x1ef80
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f5b0
movq %rax, -0x1b8(%rbp)
jmp 0x1ef99
movq -0x1b8(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq 0x17014(%rip), %rsi     # 0x35fc8
callq 0x3090
jmp 0x1efbb
movq -0x10(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x32e0
jmp 0x1efcd
leaq 0x52fc(%rip), %rsi      # 0x242d0
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1b9(%rbp)
jmp 0x1efe8
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x1f01b
jmp 0x1eff4
leaq 0x52ac(%rip), %rsi      # 0x242a7
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1ba(%rbp)
jmp 0x1f00f
movb -0x1ba(%rbp), %al
testb $0x1, %al
jne 0x1f01b
jmp 0x1f043
movl $0x0, -0xfc(%rbp)
movl $0x0, -0xf8(%rbp)
movq -0x18(%rbp), %rax
movq -0xfc(%rbp), %rcx
movq %rcx, 0xc(%rax)
jmp 0x1f153
leaq 0x5288(%rip), %rsi      # 0x242d2
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1bb(%rbp)
jmp 0x1f05e
movb -0x1bb(%rbp), %al
testb $0x1, %al
jne 0x1f091
jmp 0x1f06a
leaq 0x5263(%rip), %rsi      # 0x242d4
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1bc(%rbp)
jmp 0x1f085
movb -0x1bc(%rbp), %al
testb $0x1, %al
jne 0x1f091
jmp 0x1f0b9
movl $0x0, -0x104(%rbp)
movl $0x1, -0x100(%rbp)
movq -0x18(%rbp), %rax
movq -0x104(%rbp), %rcx
movq %rcx, 0xc(%rax)
jmp 0x1f151
leaq 0x5216(%rip), %rsi      # 0x242d6
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1bd(%rbp)
jmp 0x1f0d4
movb -0x1bd(%rbp), %al
testb $0x1, %al
jne 0x1f107
jmp 0x1f0e0
leaq 0x51f1(%rip), %rsi      # 0x242d8
leaq -0xf0(%rbp), %rdi
callq 0x1f580
movb %al, -0x1be(%rbp)
jmp 0x1f0fb
movb -0x1be(%rbp), %al
testb $0x1, %al
jne 0x1f107
jmp 0x1f12c
movl $0x0, -0x10c(%rbp)
movl $0x2, -0x108(%rbp)
movq -0x18(%rbp), %rax
movq -0x10c(%rbp), %rcx
movq %rcx, 0xc(%rax)
jmp 0x1f14f
movl $0x0, -0x114(%rbp)
movl $0x3, -0x110(%rbp)
movq -0x18(%rbp), %rax
movq -0x114(%rbp), %rcx
movq %rcx, 0xc(%rax)
jmp 0x1f151
jmp 0x1f153
jmp 0x1f155
jmp 0x1f157
jmp 0x1f159
jmp 0x1f15b
jmp 0x1f15d
jmp 0x1f15f
jmp 0x1f161
jmp 0x1f163
leaq -0x115(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x33d0
movq -0x128(%rbp), %rdi
movq -0x1c8(%rbp), %rdx
leaq 0x50ca(%rip), %rsi      # 0x24255
callq 0x8d40
jmp 0x1f192
leaq -0x115(%rbp), %rdi
callq 0x3280
movl $0x1, -0xf4(%rbp)
jmp 0x1f1c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x115(%rbp), %rdi
callq 0x3280
jmp 0x1f201
leaq -0xf0(%rbp), %rdi
callq 0x3160
leaq -0xd0(%rbp), %rdi
callq 0x3160
leaq -0xb0(%rbp), %rdi
callq 0x3160
leaq -0x50(%rbp), %rdi
callq 0x1f690
movq -0x120(%rbp), %rax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0xf0(%rbp), %rdi
callq 0x3160
leaq -0xd0(%rbp), %rdi
callq 0x3160
leaq -0xb0(%rbp), %rdi
callq 0x3160
leaq -0x50(%rbp), %rdi
callq 0x1f690
movq -0x78(%rbp), %rdi
callq 0x33c0
nopw (%rax,%rax)