// File: miklhh[P]tetris/src/game.cpp
// Function: test_rotation(block_t*, bool)
collision_t test_rotation(block_t* block, rotation_t counter_clockwise)
{
	/* Make a copy of the block and rotate the copy. */
	block_t block_copy = *block;
	block_rotate(&block_copy, counter_clockwise);

	/* Test if any part of the copied block interfears with the taken boxes on the field. 
	 * Also test if the copied block interfears with the wall. Return accordingly. */
	collision_t collision = NO_COLLISION;
	
	/* Test for collision with other boxes. */
	for (int y = 0; y < MAX_BLOCK_HEIGHT; y++)
	{
		for (int x = 0; x < MAX_BLOCK_WIDTH; x++)
		{
			if (block_copy.structure.tile[y][x] == FILLED   &&
				field[y + block_copy.position.y][x + block_copy.position.x].tile == TAKEN)
			{
				collision = COLLISION_BLOCK;
			}
		}
	}

	/* Test for collision with left side wall. */
	for (int y = 0; y < MAX_BLOCK_HEIGHT; y++)
	{
		for (int x = 0; x < MAX_BLOCK_WIDTH; x++)
		{
			if (block_copy.structure.tile[y][x] == FILLED   &&
				x + block_copy.position.x < 0)
			{
				collision = COLLISION_WALL_R;
			}
		}
	}

	/* Test for collision with the right side wall. */
	for (int y = 0; y < MAX_BLOCK_HEIGHT; y++)
	{
		for (int x = 0; x < MAX_BLOCK_WIDTH; x++)
		{
			if (block_copy.structure.tile[y][x] == FILLED   &&
				x + block_copy.position.x > GRID_WIDTH - 1)
			{
				collision = COLLISION_WALL_R;
			}
		}
	}
	return collision;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x5c(%rbp), %rdi
movl $0x50, %edx
callq 0x2130
movb -0x9(%rbp), %al
leaq -0x5c(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x2c20
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
cmpl $0x4, -0x64(%rbp)
jge 0x2f36
movl $0x0, -0x68(%rbp)
cmpl $0x4, -0x68(%rbp)
jge 0x2f29
leaq -0x5c(%rbp), %rax
addq $0x10, %rax
movslq -0x64(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x68(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x2f1c
movl -0x64(%rbp), %eax
addl -0x50(%rbp), %eax
movslq %eax, %rcx
leaq 0x5278(%rip), %rax      # 0x8170
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl -0x68(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
jne 0x2f1c
movl $0x5, -0x60(%rbp)
jmp 0x2f1e
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x2ec5
jmp 0x2f2b
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2eb8
movl $0x0, -0x6c(%rbp)
cmpl $0x4, -0x6c(%rbp)
jge 0x2f99
movl $0x0, -0x70(%rbp)
cmpl $0x4, -0x70(%rbp)
jge 0x2f8c
leaq -0x5c(%rbp), %rax
addq $0x10, %rax
movslq -0x6c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x70(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x2f7f
movl -0x70(%rbp), %eax
addl -0x54(%rbp), %eax
cmpl $0x0, %eax
jge 0x2f7f
movl $0x2, -0x60(%rbp)
jmp 0x2f81
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x2f4a
jmp 0x2f8e
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x2f3d
movl $0x0, -0x74(%rbp)
cmpl $0x4, -0x74(%rbp)
jge 0x2ffc
movl $0x0, -0x78(%rbp)
cmpl $0x4, -0x78(%rbp)
jge 0x2fef
leaq -0x5c(%rbp), %rax
addq $0x10, %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x2fe2
movl -0x78(%rbp), %eax
addl -0x54(%rbp), %eax
cmpl $0x9, %eax
jle 0x2fe2
movl $0x2, -0x60(%rbp)
jmp 0x2fe4
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x2fad
jmp 0x2ff1
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x2fa0
movl -0x60(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)