// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movl %esi, %ebx
movq 0x20(%rdi), %rsi
movq 0x28(%rdi), %r9
movq %r9, %rcx
subq %rsi, %rcx
pushq $0x38
popq %r8
movq %rcx, %rax
cqto
idivq %r8
sarq $0x2, %rax
testq %rax, %rax
jle 0x3b16
cmpl %ebx, (%rsi)
je 0x3b5b
cmpl %ebx, 0x38(%rsi)
je 0x3b48
cmpl %ebx, 0x70(%rsi)
je 0x3b4e
cmpl %ebx, 0xa8(%rsi)
je 0x3b54
addq $0xe0, %rsi
decq %rax
addq $-0xe0, %rcx
jmp 0x3ae8
movq %rcx, %rax
cqto
idivq %r8
cmpq $0x1, %rax
je 0x3b40
cmpq $0x2, %rax
je 0x3b38
cmpq $0x3, %rax
jne 0x3b5e
cmpl %ebx, (%rsi)
je 0x3b5b
addq $0x38, %rsi
cmpl %ebx, (%rsi)
je 0x3b5b
addq $0x38, %rsi
cmpl %ebx, (%rsi)
cmoveq %rsi, %r9
jmp 0x3b5e
addq $0x38, %rsi
jmp 0x3b5b
addq $0x70, %rsi
jmp 0x3b5b
addq $0xa8, %rsi
movq %rsi, %r9
leaq 0x8(%r9), %rsi
movq 0x8(%r9), %rcx
movq 0x10(%r9), %r14
movq %r14, %rdx
subq %rcx, %rdx
movq %rdx, %rax
sarq $0x5, %rax
addq $0x10, %rcx
movq %r9, (%rsp)
movq %rsi, 0x10(%rsp)
testq %rax, %rax
jle 0x3baa
cmpl %ebp, -0xc(%rcx)
je 0x3bd5
cmpl %ebp, -0x4(%rcx)
je 0x3bdb
cmpl %ebp, 0x4(%rcx)
je 0x3be5
cmpl %ebp, 0xc(%rcx)
je 0x3be1
decq %rax
addq $0x20, %rcx
addq $-0x20, %rdx
jmp 0x3b84
sarq $0x3, %rdx
leaq -0x10(%rcx), %rax
cmpq $0x1, %rdx
je 0x3daf
cmpq $0x3, %rdx
je 0x3d92
cmpq $0x2, %rdx
je 0x3da2
movq %r14, %r12
jmp 0x3c1a
addq $-0x10, %rcx
jmp 0x3be5
addq $-0x8, %rcx
jmp 0x3be5
addq $0x8, %rcx
movq %rcx, %rax
cmpq %r14, %rax
je 0x3c17
movq %rax, %r12
movq %rax, %rcx
leaq 0x8(%rcx), %rax
cmpq %r14, %rax
je 0x3c11
cmpl %ebp, 0xc(%rcx)
movq %rax, %rcx
je 0x3bf3
movq (%rax), %rcx
movq %rcx, (%r12)
addq $0x8, %r12
jmp 0x3bf0
movq 0x10(%r9), %r14
jmp 0x3c1a
movq %rax, %r12
movq %rdi, 0x8(%rsp)
leaq 0x38(%rdi), %r15
movq %r12, %r13
cmpq %r14, %r13
je 0x3c3e
movq %r15, %rdi
movq %r13, %rsi
callq 0x3e88
incl (%rax)
addq $0x8, %r13
jmp 0x3c26
movq (%rsp), %r14
movq 0x10(%r14), %rdx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x40e0
leaq 0x20(%r14), %r8
movq 0x20(%r14), %rsi
movq 0x28(%r14), %r13
movq %r13, %rcx
subq %rsi, %rcx
pushq $0xc
popq %rdi
movq %rcx, %rax
cqto
idivq %rdi
sarq $0x2, %rax
addq $0x18, %rsi
testq %rax, %rax
jle 0x3c9e
cmpl %ebp, -0x10(%rsi)
je 0x3cd0
cmpl %ebp, -0x4(%rsi)
je 0x3cd6
cmpl %ebp, 0x8(%rsi)
je 0x3ce0
cmpl %ebp, 0x14(%rsi)
je 0x3cdc
decq %rax
addq $0x30, %rsi
addq $-0x30, %rcx
jmp 0x3c78
movq %rcx, %rax
cqto
idivq %rdi
leaq -0x18(%rsi), %rcx
cmpq $0x1, %rax
je 0x3dd8
cmpq $0x3, %rax
je 0x3dbb
cmpq $0x2, %rax
je 0x3dcb
movq %r8, %rbp
movq %r13, %r14
jmp 0x3d25
addq $-0x18, %rsi
jmp 0x3ce0
addq $-0xc, %rsi
jmp 0x3ce0
addq $0xc, %rsi
movq %rsi, %rcx
cmpq %r13, %rcx
je 0x3d1f
movq %rcx, %r14
movq %rcx, %rax
leaq 0xc(%rax), %rcx
cmpq %r13, %rcx
je 0x3d12
cmpl %ebp, 0x14(%rax)
movq %rcx, %rax
je 0x3cee
movl 0x8(%rcx), %eax
movl %eax, 0x8(%r14)
movq (%rcx), %rax
movq %rax, (%r14)
addq $0xc, %r14
jmp 0x3ceb
movq %r8, %rbp
movq (%rsp), %rax
movq 0x28(%rax), %r13
jmp 0x3d25
movq %r8, %rbp
movq %rcx, %r14
movq %r14, %r12
cmpq %r13, %r12
je 0x3d42
leaq 0x4(%r12), %rsi
movq %r15, %rdi
callq 0x3e88
incl (%rax)
addq $0xc, %r12
jmp 0x3d28
movq (%rsp), %r15
movq 0x28(%r15), %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x40e6
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rax
je 0x3d78
movq 0x28(%r15), %rax
cmpq 0x20(%r15), %rax
je 0x3d78
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movl %ebx, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39ba
cmpl %ebp, -0xc(%rcx)
je 0x3be8
addq $-0x8, %rcx
movq %rcx, %rax
cmpl %ebp, 0x4(%rax)
je 0x3be8
addq $0x8, %rax
cmpl %ebp, 0x4(%rax)
cmovneq %r14, %rax
jmp 0x3be8
cmpl %ebp, -0x10(%rsi)
je 0x3ce3
addq $-0xc, %rsi
movq %rsi, %rcx
cmpl %ebp, 0x8(%rcx)
je 0x3ce3
addq $0xc, %rcx
cmpl %ebp, 0x8(%rcx)
cmovneq %r13, %rcx
jmp 0x3ce3