// File: tkaczenko[P]asteroids-clone/src/GameEngine.cpp
// Function: GameEngine::collisions()
void GameEngine::collisions()
{
    for (int i=0; i != 3; i++) {
        for (auto rock_it = rocks.begin(); rock_it != rocks.end(); rock_it++) {
            for(int j = 0; j < ROCK_PARTS; j++) {
                if ( SDL_IntersectRectAndLine(&player.getColPoints()[i],
                                                &rock_it->second.getLines()[j].x,
                                                &rock_it->second.getLines()[j].y,
                                                &rock_it->second.getLines()[j+1].x,
                                                &rock_it->second.getLines()[j+1].y)) {
                    player.setAlive(false);
                }
            }
        }
    }
    BEGIN_MISSILE_COLLISION:
    for (auto bul_it = player.getBullets()->begin(); bul_it != player.getBullets()->end(); bul_it++) {
        SDL_Rect bul = {bul_it->second.getPosition().x, bul_it->second.getPosition().y, 10, 10};
        for (auto rock_it = rocks.begin(); rock_it != rocks.end(); rock_it++) {
            for(int j = 0; j < ROCK_PARTS; j++) {
                if ( SDL_IntersectRectAndLine(&bul,
                                                &rock_it->second.getLines()[j].x,
                                                &rock_it->second.getLines()[j].y,
                                                &rock_it->second.getLines()[j+1].x,
                                                &rock_it->second.getLines()[j+1].y) ) {
                    rocks.erase(rock_it);
                    player.getBullets()->erase(bul_it++);

                    if (rock_it->second.getType() == BIG_ROCK) {
                        this->spawnRock(MED_ROCK, 4, rock_it->second.getPosition().x, rock_it->second.getPosition().y);
                    } else if (rock_it->second.getType() == MED_ROCK) {
                        this->spawnRock(SMALL_ROCK, 2, rock_it->second.getPosition().x, rock_it->second.getPosition().y);
                    } else if (rock_it->second.getType() == SMALL_ROCK) {

                    }
                    goto BEGIN_MISSILE_COLLISION;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
je 0x4b37
movq -0xf0(%rbp), %rdi
addq $0x90, %rdi
callq 0x5390
movq %rax, -0x18(%rbp)
movq -0xf0(%rbp), %rdi
addq $0x90, %rdi
callq 0x53f0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x53c0
testb $0x1, %al
jne 0x49ef
jmp 0x4b27
movl $0x0, -0x24(%rbp)
cmpl $0xa, -0x24(%rbp)
jge 0x4b11
movq -0xf0(%rbp), %rdi
callq 0x5420
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x110(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movslq -0x24(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movslq -0x24(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x4, %rax
movq %rax, -0x100(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
movq -0xf8(%rbp), %rcx
movq %rax, %r8
movl -0x24(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %r8
addq $0x4, %r8
callq 0x30a0
cmpl $0x0, %eax
je 0x4b01
movq -0xf0(%rbp), %rdi
movb $0x0, -0x25(%rbp)
leaq -0x25(%rbp), %rsi
callq 0x5360
jmp 0x4b03
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x49f6
jmp 0x4b13
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x5480
movq %rax, -0x30(%rbp)
jmp 0x49c2
jmp 0x4b29
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x49a1
jmp 0x4b39
movq -0xf0(%rbp), %rdi
callq 0x54c0
movq %rax, %rdi
callq 0x54e0
movq %rax, -0x38(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x54c0
movq %rax, %rdi
callq 0x5540
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5510
testb $0x1, %al
jne 0x4b7f
jmp 0x4f2d
leaq -0x38(%rbp), %rdi
callq 0x5570
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq %rax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5570
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq -0xf0(%rbp), %rdi
movq %rax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0xa, -0x48(%rbp)
movl $0xa, -0x44(%rbp)
addq $0x90, %rdi
callq 0x5390
movq %rax, -0x68(%rbp)
movq -0xf0(%rbp), %rdi
addq $0x90, %rdi
callq 0x53f0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x53c0
testb $0x1, %al
jne 0x4c0f
jmp 0x4f14
movl $0x0, -0x74(%rbp)
cmpl $0xa, -0x74(%rbp)
jge 0x4efb
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movslq -0x74(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movslq -0x74(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x4, %rax
movq %rax, -0x120(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movl -0x74(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x118(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5460
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
movq -0x118(%rbp), %rcx
movq %rax, %r8
movl -0x74(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %r8
addq $0x4, %r8
leaq -0x50(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
je 0x4eeb
movq -0xf0(%rbp), %rdi
addq $0x90, %rdi
movq -0x68(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0x55a0
movq -0xf0(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x54c0
movq %rax, -0x130(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x5620
movq -0x130(%rbp), %rdi
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rsi
callq 0x55e0
movq %rax, -0x98(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5660
cmpl $0x259, %eax            # imm = 0x259
jne 0x4e0e
movl $0x25a, -0x9c(%rbp)     # imm = 0x25A
movl $0x4, -0xa0(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq %rax, -0xac(%rbp)
cvtsi2ssl -0xac(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq -0xf0(%rbp), %rdi
movq %rax, -0xb8(%rbp)
cvtsi2ssl -0xb4(%rbp), %xmm0
movss %xmm0, -0xb0(%rbp)
leaq -0x9c(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
leaq -0xa4(%rbp), %rcx
leaq -0xb0(%rbp), %r8
callq 0x4390
jmp 0x4ee6
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5660
cmpl $0x25a, %eax            # imm = 0x25A
jne 0x4ec4
movl $0x25b, -0xbc(%rbp)     # imm = 0x25B
movl $0x2, -0xc0(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq %rax, -0xcc(%rbp)
cvtsi2ssl -0xcc(%rbp), %xmm0
movss %xmm0, -0xc4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5180
movq -0xf0(%rbp), %rdi
movq %rax, -0xd8(%rbp)
cvtsi2ssl -0xd4(%rbp), %xmm0
movss %xmm0, -0xd0(%rbp)
leaq -0xbc(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
leaq -0xc4(%rbp), %rcx
leaq -0xd0(%rbp), %r8
callq 0x4390
jmp 0x4ee4
leaq -0x68(%rbp), %rdi
callq 0x5440
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5660
cmpl $0x25b, %eax            # imm = 0x25B
jne 0x4ee2
jmp 0x4ee2
jmp 0x4ee4
jmp 0x4ee6
jmp 0x4b39
jmp 0x4eed
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x4c16
jmp 0x4efd
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x5480
movq %rax, -0xe0(%rbp)
jmp 0x4be2
jmp 0x4f16
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x5620
movq %rax, -0xe8(%rbp)
jmp 0x4b51
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)