// File: therealgymmy[P]HelicopterGame/src/control.cpp
// Function: detectCollision(BombList&, TowerList&, ExplosionList&, HealthBar&, Score&)
void detectCollision (BombList &bombs,
                      TowerList &towers,
                      ExplosionList &explosions,
                      HealthBar &hp,
                      Score &score) {
    TowerList::Towers         &towerlist = towers.towers();
    BombList::Bombs           &bomblist  = bombs.bombs();

    for (TowerList::Towers::iterator t_itr = towerlist.begin();
         t_itr != towerlist.end();
         ++t_itr) {
        int th = t_itr->numBlocks();
        int tx = t_itr->x();
        for (BombList::Bombs::iterator b_itr = bomblist.begin();
             b_itr != bomblist.end();
             ++b_itr) {
            int bx = b_itr->x();
            int by = b_itr->y();

            if (bx >= tx - Bomb::Size::w() &&
                bx <= tx + Tower::Size::w() &&
                by >= PLANE_H - th * Tower::Size::h() - Bomb::Size::h() &&
                by <= PLANE_H) {
                if (t_itr->hasLauncher()) {
                    hp.incHealth();
                    score.incScore(1000);
                }

                b_itr = bomblist.erase(b_itr);

                t_itr->removeLauncher();

                explosions.addExplosion(bx + Bomb::w(),
                                        by + Bomb::h());

            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9b40
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9b50
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x4ed0
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x4f70
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4f40
testb $0x1, %al
jne 0x9589
jmp 0x9796
leaq -0x40(%rbp), %rdi
callq 0x4f00
movq %rax, %rdi
callq 0x9b60
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4f00
movq %rax, %rdi
callq 0x4f20
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
callq 0x9b80
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x9be0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x9bb0
testb $0x1, %al
jne 0x95e1
jmp 0x9786
leaq -0x58(%rbp), %rdi
callq 0x9c10
movq %rax, %rdi
callq 0x9c40
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9c10
movq %rax, %rdi
callq 0x9c60
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x80(%rbp)
callq 0x9c80
movl -0x80(%rbp), %ecx
movl %eax, %edx
movl -0x7c(%rbp), %eax
subl %edx, %ecx
cmpl %ecx, %eax
jl 0x9776
movl -0x64(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x88(%rbp)
callq 0x4e80
movl -0x88(%rbp), %ecx
movl %eax, %edx
movl -0x84(%rbp), %eax
addl %edx, %ecx
cmpl %ecx, %eax
jg 0x9776
movl -0x68(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x94(%rbp)
callq 0x4db0
movl -0x94(%rbp), %ecx
imull %eax, %ecx
movl $0xbb8, %eax            # imm = 0xBB8
subl %ecx, %eax
movl %eax, -0x90(%rbp)
callq 0x9c90
movl -0x90(%rbp), %ecx
movl %eax, %edx
movl -0x8c(%rbp), %eax
subl %edx, %ecx
cmpl %ecx, %eax
jl 0x9776
cmpl $0xbb8, -0x68(%rbp)     # imm = 0xBB8
jg 0x9776
leaq -0x40(%rbp), %rdi
callq 0x4f00
movq %rax, %rdi
callq 0x50d0
testb $0x1, %al
jne 0x96c9
jmp 0x96e0
movq -0x20(%rbp), %rdi
callq 0x9ca0
movq -0x28(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x9b20
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x9d20
movq -0xb0(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x9cd0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4f00
movq %rax, %rdi
callq 0x9d40
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0xa8(%rbp)
callq 0x9c80
movl %eax, %ecx
movl -0xa8(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x98(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0xa4(%rbp)
callq 0x9c90
movl -0xa4(%rbp), %edx
movq -0xa0(%rbp), %rdi
movl -0x98(%rbp), %esi
addl %eax, %edx
callq 0xbab0
jmp 0x9778
leaq -0x58(%rbp), %rdi
callq 0x9d60
jmp 0x95be
jmp 0x9788
leaq -0x40(%rbp), %rdi
callq 0x4fa0
jmp 0x9566
addq $0xb0, %rsp
popq %rbp
retq
nop