// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
leaq 0x98(%rdi), %rax
movq %rax, -0x60(%rbp)
xorl %r12d, %r12d
movq %rdi, -0x38(%rbp)
movq 0xa8(%rdi), %r14
cmpq -0x60(%rbp), %r14
je 0x340e
movq %r12, %r13
shlq $0x4, %r13
leaq 0xdc(%r14), %r15
movl $0xa, %ebx
movq %r15, %rsi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rdi
addq %r13, %rdi
leaq 0x4(%r15), %rdx
addq $0x8, %r15
leaq 0xc(%rsi), %r8
movq %r15, %rcx
callq 0x20b0
movq -0x38(%rbp), %rcx
testl %eax, %eax
je 0x33f4
movb $0x0, 0x88(%rcx)
decq %rbx
jne 0x33c3
movq %r14, %rdi
callq 0x21c0
movq -0x38(%rbp), %rdi
movq %rax, %r14
cmpq -0x60(%rbp), %rax
jne 0x33b7
incq %r12
cmpq $0x3, %r12
jne 0x33a3
leaq 0x40(%rdi), %rax
movq %rax, -0x78(%rbp)
leaq 0x48(%rdi), %rax
movq %rax, -0x68(%rbp)
leaq 0x90(%rdi), %rax
movq %rax, -0x70(%rbp)
movq 0x58(%rdi), %rax
cmpq -0x68(%rbp), %rax
sete %cl
je 0x35d2
movb %cl, -0x29(%rbp)
movq %rax, -0x58(%rbp)
movq 0x50(%rax), %rax
movl %eax, -0x88(%rbp)
shrq $0x20, %rax
movl %eax, -0x84(%rbp)
movabsq $0xa0000000a, %rax      # imm = 0xA0000000A
movq %rax, -0x80(%rbp)
movq 0xa8(%rdi), %rax
movq %rax, -0x50(%rbp)
cmpq -0x60(%rbp), %rax
sete %al
je 0x35a4
movb %al, -0x2a(%rbp)
movq $-0x1, %r14
movl $0xdc, %r15d
movl $0xe0, %r12d
movl $0xe4, %ebx
movl $0xe8, %r13d
cmpq $0x9, %r14
je 0x353a
movq -0x50(%rbp), %rax
leaq (%rax,%r15), %rsi
leaq (%rax,%r12), %rdx
leaq (%rax,%rbx), %rcx
leaq (%rax,%r13), %r8
leaq -0x88(%rbp), %rdi
callq 0x20b0
incq %r14
addq $0x8, %r15
addq $0x8, %r12
addq $0x8, %rbx
addq $0x8, %r13
testl %eax, %eax
je 0x34a5
cmpq $0xa, %r14
setae %r14b
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rbx
movq %rbx, %rsi
callq 0x3a8c
movq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x21c0
movq %rax, %r12
movq -0x78(%rbp), %rdi
movq %r15, %rsi
callq 0x3ad0
movl 0x74(%rbx), %eax
cmpl $0x25a, %eax            # imm = 0x25A
je 0x353f
cmpl $0x259, %eax            # imm = 0x259
jne 0x358a
movl $0x25a, -0x48(%rbp)     # imm = 0x25A
movl $0x4, -0x44(%rbp)
jmp 0x354d
movb $0x1, %r14b
jmp 0x358e
movl $0x25b, -0x48(%rbp)     # imm = 0x25B
movl $0x2, -0x44(%rbp)
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x40(%rbp)
shrq $0x20, %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x44(%rbp), %rdx
leaq -0x40(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x2e7e
movq %r12, -0x58(%rbp)
testb %r14b, %r14b
je 0x35a1
movq -0x50(%rbp), %rdi
callq 0x21c0
jmp 0x3473
movb -0x2a(%rbp), %al
testb $0x1, %al
je 0x35c4
movq -0x58(%rbp), %rdi
callq 0x21c0
cmpq -0x68(%rbp), %rax
sete %cl
movq -0x38(%rbp), %rdi
jne 0x3443
jmp 0x35d2
testb $0x1, -0x29(%rbp)
movq -0x38(%rbp), %rdi
je 0x3432
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop