// File: /workspace/github_cpp_makefile_star2_O3/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, %rdi
subq %r13, %rdi
movq %rdi, %r8
sarq $0x3, %r8
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rdx, %r8
sarq $0x2, %r8
testq %r8, %r8
jle 0x3f52
imulq $0xe0, %r8, %rcx
addq %r13, %rcx
incq %r8
addq $0x70, %r13
cmpl %esi, -0x70(%r13)
je 0x3f80
cmpl %esi, -0x38(%r13)
je 0x3f86
cmpl %esi, (%r13)
je 0x3f9f
cmpl %esi, 0x38(%r13)
je 0x3f8c
decq %r8
addq $0xe0, %r13
cmpq $0x1, %r8
jg 0x3f22
movq %rax, %rdi
subq %rcx, %rdi
jmp 0x3f55
movq %r13, %rcx
sarq $0x3, %rdi
imulq %rdx, %rdi
cmpq $0x1, %rdi
je 0x3f96
cmpq $0x2, %rdi
je 0x3f77
cmpq $0x3, %rdi
jne 0x3f9c
cmpl %esi, (%rcx)
je 0x3f7b
addq $0x38, %rcx
cmpl %esi, (%rcx)
jne 0x3f92
movq %rcx, %r13
jmp 0x3f9f
addq $-0x70, %r13
jmp 0x3f9f
addq $-0x38, %r13
jmp 0x3f9f
addq $0x38, %r13
jmp 0x3f9f
addq $0x38, %rcx
cmpl %esi, (%rcx)
cmoveq %rcx, %rax
movq %rax, %r13
movq 0x8(%r13), %rbx
movq 0x10(%r13), %r14
movq %r14, %rdx
subq %rbx, %rdx
movq %rdx, %rcx
sarq $0x5, %rcx
testq %rcx, %rcx
jle 0x3ff3
andq $-0x20, %rdx
movq %rdx, %rax
addq %rbx, %rax
incq %rcx
addq $0x10, %rbx
cmpl %ebp, -0xc(%rbx)
je 0x402e
cmpl %ebp, -0x4(%rbx)
je 0x4034
cmpl %ebp, 0x4(%rbx)
je 0x403e
cmpl %ebp, 0xc(%rbx)
je 0x403a
decq %rcx
addq $0x20, %rbx
cmpq $0x1, %rcx
jg 0x3fca
movq %r14, %rdx
subq %rax, %rdx
jmp 0x3ff6
movq %rbx, %rax
sarq $0x3, %rdx
cmpq $0x1, %rdx
je 0x4022
cmpq $0x2, %rdx
je 0x4019
cmpq $0x3, %rdx
jne 0x40a4
cmpl %ebp, 0x4(%rax)
je 0x4029
addq $0x8, %rax
cmpl %ebp, 0x4(%rax)
je 0x4029
addq $0x8, %rax
cmpl %ebp, 0x4(%rax)
cmovneq %r14, %rax
movq %rax, %rbx
jmp 0x403e
addq $-0x10, %rbx
jmp 0x403e
addq $-0x8, %rbx
jmp 0x403e
addq $0x8, %rbx
cmpq %r14, %rbx
je 0x4068
leaq 0x8(%rbx), %rax
cmpq %r14, %rax
je 0x4068
cmpl %ebp, 0x4(%rax)
je 0x405b
movq (%rax), %rcx
movq %rcx, (%rbx)
addq $0x8, %rbx
addq $0x8, %rax
cmpq %r14, %rax
jne 0x404c
movq 0x10(%r13), %r14
cmpq %r14, %rbx
je 0x409b
movl %esi, 0x14(%rsp)
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %r15
movq %rbx, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x427c
incl (%rax)
addq $0x8, %r12
cmpq %r14, %r12
jne 0x407d
movq 0x10(%r13), %r14
movl 0x14(%rsp), %esi
cmpq %r14, %rbx
je 0x40a4
movq %rbx, 0x10(%r13)
movq 0x20(%r13), %r14
movq 0x28(%r13), %r12
movq %r12, %rdi
subq %r14, %rdi
movq %rdi, %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
sarq $0x2, %rdx
testq %rdx, %rdx
jle 0x410f
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
addq %r14, %rax
incq %rdx
addq $0x18, %r14
cmpl %ebp, -0x10(%r14)
je 0x414e
cmpl %ebp, -0x4(%r14)
je 0x4154
cmpl %ebp, 0x8(%r14)
je 0x415e
cmpl %ebp, 0x14(%r14)
je 0x415a
decq %rdx
addq $0x30, %r14
cmpq $0x1, %rdx
jg 0x40e2
movq %r12, %rdi
subq %rax, %rdi
jmp 0x4112
movq %r14, %rax
sarq $0x2, %rdi
imulq %rcx, %rdi
cmpq $0x1, %rdi
je 0x4142
cmpq $0x2, %rdi
je 0x4139
cmpq $0x3, %rdi
jne 0x41cb
cmpl %ebp, 0x8(%rax)
je 0x4149
addq $0xc, %rax
cmpl %ebp, 0x8(%rax)
je 0x4149
addq $0xc, %rax
cmpl %ebp, 0x8(%rax)
cmovneq %r12, %rax
movq %rax, %r14
jmp 0x415e
addq $-0x18, %r14
jmp 0x415e
addq $-0xc, %r14
jmp 0x415e
addq $0xc, %r14
cmpq %r12, %r14
je 0x418f
leaq 0xc(%r14), %rax
cmpq %r12, %rax
je 0x418f
cmpl %ebp, 0x8(%rax)
je 0x4182
movl 0x8(%rax), %ecx
movl %ecx, 0x8(%r14)
movq (%rax), %rcx
movq %rcx, (%r14)
addq $0xc, %r14
addq $0xc, %rax
cmpq %r12, %rax
jne 0x416c
movq 0x28(%r13), %r12
cmpq %r12, %r14
je 0x41bf
movl %esi, %ebp
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %r15
movq %r14, %rbx
leaq 0x4(%rbx), %rsi
movq %r15, %rdi
callq 0x427c
incl (%rax)
addq $0xc, %rbx
cmpq %r12, %rbx
jne 0x41a2
movq 0x28(%r13), %r12
movl %ebp, %esi
cmpq %r12, %r14
je 0x41c8
movq %r14, 0x28(%r13)
movq %r14, %r12
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rax
je 0x41ea
cmpq 0x20(%r13), %r12
je 0x41ea
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3da2