// File: /workspace/github_cpp_makefile_star2_O3/EstherJin[P]TetrisRemake/basicboard.cc
// Function: BasicBoard::dropBlock()
int BasicBoard::dropBlock() {
	// keep dropping
	for (int i = 0; i < gridRows; ++i) {
		bool valid = validMove(currentBlock->downPos(1));
		if (valid) {
			currentBlock->down(1);
		}
		else break;
	}

	// change to block 2
	currentBlock->detach();
	if (!textOnly) currentBlock->detach();
	Block2 b2(currentBlock->getNum(),lvl->getLevel());
	activeBlocks.emplace_back(b2);
	vector<Coordinates> blockCoords = currentBlock->getPos();
  	for (auto coord:blockCoords) {
		grid[coord.row].changeCell(coord.col, currentBlock->getType());
		grid[coord.row].attachObserver(coord.col, &b2);
	}

	// check lines cleared
	int linesCleared = 0;
	for (int i = gridRows - 1; i >= 0; --i) {
		if (grid[i].checkFull()) {
			++linesCleared;
			grid.erase(grid.begin() + i);
			Row newRow {0, &sg, &gd};
			grid.insert(grid.begin(), newRow);
			for (int j = i; j >= 0; --j) {
				grid[j].changeRowNum(j);
			}
			grid[i].notifAbout();
			++i;
		}
	}

	// calculate score
	if (linesCleared > 0)  score += (lvl->getLevel() + linesCleared) * (lvl->getLevel() + linesCleared);
	for (int i = 0; i < activeBlocks.size(); ++i) {
		if (activeBlocks[i].checkDeleted()) {
			score += (activeBlocks[i].getLevelDropped() + 1) * (activeBlocks[i].getLevelDropped() + 1);
			activeBlocks.erase(activeBlocks.begin() + i);
		}
	}
	if (!textOnly) gd.printScore(score);

	// switch blocks
	currentBlock = nullptr;
	std::swap(currentBlock, nextBlock);

	// check game over
	if (!validMove(currentBlock->getPos())) {
		currentBlock = nullptr;
		throw "game over";
	}

	currentBlock->attach(&sg);
	if (!textOnly) currentBlock->attach(&gd);
	currentBlock->notifCurrPos();

	return linesCleared;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
cmpl $0x0, 0xc0(%rdi)
jle 0x6ecf
xorl %r15d, %r15d
leaq 0x70(%rsp), %r14
movq 0xb8(%rbx), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x8918
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x50(%rax)
movl %eax, %ebp
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x6ead
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
testb %bpl, %bpl
je 0x6ecf
movq 0xb8(%rbx), %rdi
movl $0x1, %esi
callq 0x8828
incl %r15d
cmpl 0xc0(%rbx), %r15d
jl 0x6e71
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0x10e26
cmpb $0x0, 0xa8(%rbx)
jne 0x6ef8
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0x10e26
movq 0xb8(%rbx), %rdi
callq 0x8a22
movl %eax, %ebp
movq 0x90(%rbx), %rdi
callq 0xeeee
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x8acc
leaq 0x58(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x7a96
movq %r14, 0x18(%rsp)
movq 0xb8(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x86ca
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
je 0x6f9b
movslq (%r14), %r12
movl 0x4(%r14), %ebp
movq 0x70(%rbx), %r13
movq 0xb8(%rbx), %rdi
callq 0x86c6
shlq $0x5, %r12
addq %r12, %r13
movsbl %al, %edx
movq %r13, %rdi
movl %ebp, %esi
callq 0xf6a6
addq 0x70(%rbx), %r12
movq %r12, %rdi
movl %ebp, %esi
leaq 0x60(%rsp), %rdx
callq 0xf6ee
addq $0x8, %r14
jmp 0x6f52
movl 0xc0(%rbx), %ebp
testl %ebp, %ebp
jle 0x70a4
leaq 0x70(%rbx), %r15
leaq 0x8(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x88(%rsp), %rbx
leal -0x1(%rbp), %r14d
movq %r14, %r12
shlq $0x5, %r12
movq (%r15), %rdi
addq %r12, %rdi
callq 0xf5c4
testb %al, %al
je 0x705b
movq (%r15), %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0x81e0
movq %rbx, %r13
movq %rbx, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
callq 0xf504
movq (%r15), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x7ade
incl 0xc(%rsp)
movl %ebp, %r13d
movq (%r15), %rdi
addq %r12, %rdi
decl %r13d
movl %r13d, %esi
callq 0xf642
addq $-0x20, %r12
testl %r13d, %r13d
jg 0x7028
shlq $0x5, %r14
addq (%r15), %r14
movq %r14, %rdi
callq 0xf7ba
movq %rbx, %rdi
callq 0x7b92
jmp 0x705e
movl %r14d, %ebp
testl %ebp, %ebp
jg 0x6fd4
cmpl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %r12
jle 0x70b3
movq 0x10(%rsp), %rbx
movq 0x90(%rbx), %rdi
callq 0xeeee
movl %eax, %ebp
movq 0x90(%rbx), %rdi
callq 0xeeee
movl 0xc(%rsp), %ecx
addl %ecx, %ebp
addl %ecx, %eax
imull %ebp, %eax
addl %eax, 0x88(%rbx)
jmp 0x70b8
movl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %r12
jmp 0x70b8
movq 0x10(%rsp), %rbx
movq 0x58(%rbx), %rdi
cmpq %rdi, 0x60(%rbx)
je 0x7125
xorl %r14d, %r14d
xorl %r15d, %r15d
addq %r14, %rdi
callq 0x8aea
testb %al, %al
je 0x710a
movq (%r12), %rdi
addq %r14, %rdi
callq 0x8af2
movl %eax, %ebp
movq (%r12), %rdi
addq %r14, %rdi
callq 0x8af2
incl %ebp
incl %eax
imull %ebp, %eax
addl %eax, 0x88(%rbx)
movq 0x58(%rbx), %rsi
addq %r14, %rsi
movq %r12, %rdi
callq 0x84e8
incq %r15
movq 0x58(%rbx), %rdi
movq 0x60(%rbx), %rax
subq %rdi, %rax
sarq $0x4, %rax
addq $0x10, %r14
cmpq %r15, %rax
ja 0x70c8
cmpb $0x0, 0xa8(%rbx)
jne 0x713d
leaq 0x30(%rbx), %rdi
movl 0x88(%rbx), %esi
callq 0x122f0
movq 0xb8(%rbx), %rdi
movq $0x0, 0xb8(%rbx)
testq %rdi, %rdi
je 0x7163
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xb8(%rbx), %rax
jmp 0x7165
xorl %eax, %eax
movq 0x98(%rbx), %rsi
movq %rsi, 0xb8(%rbx)
movq %rax, 0x98(%rbx)
leaq 0x48(%rsp), %rdi
callq 0x86ca
movq (%rbx), %rax
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq *0x50(%rax)
movl %eax, %ebp
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x71ab
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
movq 0xb8(%rbx), %rdi
testb %bpl, %bpl
je 0x7225
addq $0x8, %rdi
leaq 0x8(%rbx), %rsi
callq 0x10e14
cmpb $0x0, 0xa8(%rbx)
jne 0x71e1
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
leaq 0x30(%rbx), %rsi
callq 0x10e14
movq 0xb8(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x7205
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
leaq 0x60(%rsp), %rdi
callq 0x8ade
movl 0xc(%rsp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0xb8(%rbx)
testq %rdi, %rdi
je 0x723b
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x8, %edi
callq 0x5140
leaq 0xbef4(%rip), %rcx      # 0x13140
movq %rcx, (%rax)
movq 0x13d52(%rip), %rsi     # 0x1afa8
movq %rax, %rdi
xorl %edx, %edx
callq 0x5470
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x72c7
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
jmp 0x72c7
jmp 0x727e
movq %rax, %rbx
jmp 0x72de
jmp 0x72b2
jmp 0x72b7
jmp 0x72b2
jmp 0x72b2
jmp 0x72b7
jmp 0x72b2
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x72e8
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
jmp 0x72e8
jmp 0x72b2
jmp 0x72b2
movq %rax, %rbx
jmp 0x72c7
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x7b92
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x72de
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
leaq 0x60(%rsp), %rdi
callq 0x8ade
movq %rbx, %rdi
callq 0x5480