// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x98(%rdi), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq 0xa8(%rbx), %r14
cmpq -0x48(%rbp), %r14
je 0x33b4
movq -0x40(%rbp), %r12
shlq $0x4, %r12
leaq 0xdc(%r14), %r15
movl $0xa, %r13d
movq %r15, %rsi
movq 0x38(%rbx), %rdi
addq %r12, %rdi
leaq 0x4(%r15), %rdx
addq $0x8, %r15
leaq 0xc(%rsi), %r8
movq %r15, %rcx
callq 0x20b0
testl %eax, %eax
je 0x339e
movb $0x0, 0x88(%rbx)
decq %r13
jne 0x3375
movq %r14, %rdi
callq 0x21c0
movq %rax, %r14
cmpq -0x48(%rbp), %rax
jne 0x3368
movq -0x40(%rbp), %rcx
incq %rcx
movq %rcx, -0x40(%rbp)
cmpq $0x3, %rcx
jne 0x3353
leaq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
movq %rax, -0x50(%rbp)
cmpq %rax, %rcx
je 0x350c
leaq 0x40(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x90(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq -0x70(%rbp), %r12
movq %rcx, -0x40(%rbp)
movq 0x50(%rcx), %rax
movl %eax, -0x70(%rbp)
shrq $0x20, %rax
movl %eax, -0x6c(%rbp)
movabsq $0xa0000000a, %rax      # imm = 0xA0000000A
movq %rax, -0x68(%rbp)
movq 0xa8(%rbx), %r14
cmpq -0x48(%rbp), %r14
je 0x3462
leaq 0xdc(%r14), %rsi
movl $0xb, %r13d
decq %r13
je 0x3451
leaq 0x8(%rsi), %r15
leaq 0x4(%rsi), %rdx
leaq 0x8(%rsi), %rcx
leaq 0xc(%rsi), %r8
movq %r12, %rdi
callq 0x20b0
movq %r15, %rsi
testl %eax, %eax
je 0x342b
jmp 0x347d
movq %r14, %rdi
callq 0x21c0
movq %rax, %r14
cmpq -0x48(%rbp), %rax
jne 0x341e
movq -0x40(%rbp), %rdi
callq 0x21c0
movq %rax, %rcx
cmpq -0x50(%rbp), %rax
jne 0x33f1
jmp 0x350c
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x39b6
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x39fa
movl 0x74(%r14), %eax
cmpl $0x25a, %eax            # imm = 0x25A
je 0x34b8
cmpl $0x259, %eax            # imm = 0x259
jne 0x34fe
movl $0x25a, -0x38(%rbp)     # imm = 0x25A
movl $0x4, -0x34(%rbp)
jmp 0x34c6
movl $0x25b, -0x38(%rbp)     # imm = 0x25B
movl $0x2, -0x34(%rbp)
movq 0x50(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
shrq $0x20, %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x34(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x2c(%rbp), %r8
callq 0x2e8e
movq 0x58(%rbx), %rcx
cmpq -0x50(%rbp), %rcx
jne 0x33f1
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop