// File: czinn[P]homeworlds/game.cc
// Function: Game::apply_catastrophe(int, Colour)
void Game::apply_catastrophe(int system_id, Colour colour) {
  auto it = find_if(systems_.begin(), systems_.end(),
      [system_id](const System& system) {
        return system.id == system_id;
      });
  const auto& stars_end = std::remove_if(it->stars.begin(), it->stars.end(),
        [colour](const Pyramid& pyramid) {
          return pyramid.colour == colour;
        });
  std::for_each(stars_end, it->stars.end(), [this](const Pyramid& pyramid) {
        this->stash_[pyramid]++;
      });
  it->stars.erase(stars_end, it->stars.end());
  const auto& ships_end = std::remove_if(it->ships.begin(), it->ships.end(),
        [colour](const Ship& ship) {
          return ship.pyramid.colour == colour;
        });
  std::for_each(ships_end, it->ships.end(), [this](const Ship& ship) {
        this->stash_[ship.pyramid]++;
      });
  it->ships.erase(ships_end, it->ships.end());

  if (it->stars.size() == 0 || it->ships.size() == 0) {
    destroy_system(system_id);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
addq $0x20, %rdi
callq 0x96c0
movq -0x110(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x20, %rdi
callq 0x96f0
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x6910
movq %rax, -0x18(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x9740
movq %rax, -0x48(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x9770
movq %rax, -0x50(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x54(%rbp), %edx
callq 0x6970
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x9770
movq %rax, %rcx
movq -0x110(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x69d0
movq %rax, -0x78(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
addq $0x8, %rax
movq %rax, -0x118(%rbp)
movq -0x38(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x9b60
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x9770
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x9b60
movq -0x118(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x9ad0
movq %rax, -0x98(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x20, %rdi
callq 0x9820
movq %rax, -0xb0(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x20, %rdi
callq 0x9850
movq %rax, -0xb8(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl -0xbc(%rbp), %edx
callq 0x6a30
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x20, %rdi
callq 0x9850
movq %rax, %rcx
movq -0x110(%rbp), %rax
movq %rcx, -0xd0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0x6a90
movq %rax, -0xe0(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
addq $0x20, %rax
movq %rax, -0x108(%rbp)
movq -0xa0(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x9a90
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x20, %rdi
callq 0x9850
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x9a90
movq -0x108(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
callq 0x9ba0
movq %rax, -0x100(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x9c30
cmpq $0x0, %rax
je 0x672f
leaq -0x18(%rbp), %rdi
callq 0x9720
movq %rax, %rdi
addq $0x20, %rdi
callq 0x94e0
cmpq $0x0, %rax
jne 0x673e
movq -0x110(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x62c0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)