// File: /workspace/github_cpp_makefile_star2_O1/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
movq 0x20(%rdi), %r13
movq %rdi, 0x8(%rsp)
movq 0x28(%rdi), %rax
movq %rax, %rdx
subq %r13, %rdx
sarq $0x3, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
sarq $0x2, %rdx
testq %rdx, %rdx
jle 0x3fe8
imulq $0xe0, %rdx, %rdi
addq %r13, %rdi
incq %rdx
addq $0x70, %r13
cmpl %esi, -0x70(%r13)
je 0x4026
cmpl %esi, -0x38(%r13)
je 0x402c
cmpl %esi, (%r13)
je 0x403b
cmpl %esi, 0x38(%r13)
je 0x4037
decq %rdx
addq $0xe0, %r13
cmpq $0x1, %rdx
jg 0x3fbd
movq %rdi, %r13
movq %rax, %rdx
subq %r13, %rdx
sarq $0x3, %rdx
imulq %rcx, %rdx
cmpq $0x1, %rdx
je 0x401c
cmpq $0x2, %rdx
je 0x4012
cmpq $0x3, %rdx
jne 0x4032
cmpl %esi, (%r13)
je 0x403b
addq $0x38, %r13
cmpl %esi, (%r13)
je 0x403b
addq $0x38, %r13
cmpl %esi, (%r13)
cmovneq %rax, %r13
jmp 0x403b
addq $-0x70, %r13
jmp 0x403b
addq $-0x38, %r13
jmp 0x403b
movq %rax, %r13
jmp 0x403b
addq $0x38, %r13
movq 0x8(%r13), %rcx
movq 0x10(%r13), %rax
movq %rax, %rdx
subq %rcx, %rdx
movq %rdx, %rdi
sarq $0x5, %rdi
testq %rdi, %rdi
jle 0x408e
andq $-0x20, %rdx
addq %rcx, %rdx
incq %rdi
addq $0x10, %rcx
movq %rcx, %r14
cmpl %ebp, -0xc(%r14)
je 0x40cb
cmpl %ebp, -0x4(%r14)
je 0x40d1
cmpl %ebp, 0x4(%r14)
je 0x40db
cmpl %ebp, 0xc(%r14)
je 0x40d7
decq %rdi
addq $0x20, %r14
cmpq $0x1, %rdi
jg 0x4066
movq %rdx, %rcx
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq $0x1, %rdx
je 0x40bf
cmpq $0x2, %rdx
je 0x40b6
movq %rax, %r14
cmpq $0x3, %rdx
jne 0x40db
cmpl %ebp, 0x4(%rcx)
je 0x40c6
addq $0x8, %rcx
cmpl %ebp, 0x4(%rcx)
je 0x40c6
addq $0x8, %rcx
cmpl %ebp, 0x4(%rcx)
cmovneq %rax, %rcx
movq %rcx, %r14
jmp 0x40db
addq $-0x10, %r14
jmp 0x40db
addq $-0x8, %r14
jmp 0x40db
addq $0x8, %r14
cmpq %rax, %r14
sete %dl
leaq 0x8(%r14), %rcx
cmpq %rax, %rcx
sete %dil
orb %dl, %dil
jne 0x4109
cmpl %ebp, 0x4(%rcx)
je 0x4100
movq (%rcx), %rdx
movq %rdx, (%r14)
addq $0x8, %r14
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x40f1
movl %esi, 0x14(%rsp)
movq 0x10(%r13), %rbx
cmpq %rbx, %r14
je 0x4138
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %r15
movq %r14, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x434e
incl (%rax)
addq $0x8, %r12
cmpq %rbx, %r12
jne 0x4122
movq 0x10(%r13), %rax
cmpq %rax, %r14
je 0x4157
movq 0x10(%r13), %rcx
movq %rcx, %rdx
subq %rax, %rdx
addq %rdx, %r14
cmpq %r14, %rcx
je 0x4157
movq %r14, 0x10(%r13)
movq 0x20(%r13), %rcx
movq 0x28(%r13), %rax
movq %rax, %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
sarq $0x2, %rsi
testq %rsi, %rsi
jle 0x41c1
leaq (%rsi,%rsi,2), %rdi
shlq $0x4, %rdi
addq %rcx, %rdi
incq %rsi
addq $0x18, %rcx
movq %rcx, %r12
cmpl %ebp, -0x10(%r12)
je 0x4202
cmpl %ebp, -0x4(%r12)
je 0x4208
cmpl %ebp, 0x8(%r12)
je 0x4212
cmpl %ebp, 0x14(%r12)
je 0x420e
decq %rsi
addq $0x30, %r12
cmpq $0x1, %rsi
jg 0x4195
movq %rdi, %rcx
movq %rax, %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
imulq %rdx, %rsi
cmpq $0x1, %rsi
je 0x41f6
cmpq $0x2, %rsi
je 0x41ed
movq %rax, %r12
cmpq $0x3, %rsi
jne 0x4212
cmpl %ebp, 0x8(%rcx)
je 0x41fd
addq $0xc, %rcx
cmpl %ebp, 0x8(%rcx)
je 0x41fd
addq $0xc, %rcx
cmpl %ebp, 0x8(%rcx)
cmovneq %rax, %rcx
movq %rcx, %r12
jmp 0x4212
addq $-0x18, %r12
jmp 0x4212
addq $-0xc, %r12
jmp 0x4212
addq $0xc, %r12
cmpq %rax, %r12
sete %dl
leaq 0xc(%r12), %rcx
cmpq %rax, %rcx
sete %sil
orb %dl, %sil
jne 0x424a
cmpl %ebp, 0x8(%rcx)
je 0x4241
movl 0x8(%rcx), %edx
movl %edx, 0x8(%r12)
movq (%rcx), %rdx
movq %rdx, (%r12)
addq $0xc, %r12
addq $0xc, %rcx
cmpq %rax, %rcx
jne 0x4229
movq 0x28(%r13), %r14
cmpq %r14, %r12
je 0x4276
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %r15
movq %r12, %rbx
leaq 0x4(%rbx), %rsi
movq %r15, %rdi
callq 0x434e
incl (%rax)
addq $0xc, %rbx
cmpq %r14, %rbx
jne 0x425f
movq 0x28(%r13), %rax
cmpq %rax, %r12
je 0x4295
movq 0x28(%r13), %rcx
movq %rcx, %rdx
subq %rax, %rdx
addq %rdx, %r12
cmpq %r12, %rcx
je 0x4295
movq %r12, 0x28(%r13)
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rax
je 0x42b8
movq 0x28(%r13), %rax
cmpq 0x20(%r13), %rax
je 0x42b8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3e46