// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %rdi, %rbx
xorl %r12d, %r12d
leaq 0x80(%rsp), %r14
pushq $0x1
popq %rbp
cmpl 0xc0(%rbx), %r12d
jge 0x6715
movq 0xb8(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x8492
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x50(%rax)
movl %eax, %r15d
movq %r14, %rdi
callq 0x7c3a
testb %r15b, %r15b
je 0x6715
movq 0xb8(%rbx), %rdi
movl %ebp, %esi
callq 0x83ac
incl %r12d
jmp 0x66cc
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0xf296
cmpb $0x0, 0xa8(%rbx)
jne 0x673e
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0xf296
movq 0xb8(%rbx), %rdi
callq 0x857a
movl %eax, %ebp
movq 0x90(%rbx), %rdi
callq 0xd9ce
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x8638
leaq 0x58(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7242
movq %r15, 0x18(%rsp)
movq 0xb8(%rbx), %rsi
leaq 0x30(%rsp), %rdi
callq 0x8266
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rbx), %r13
cmpq 0x8(%rsp), %r14
je 0x67ec
movslq (%r14), %r12
movl 0x4(%r14), %ebp
movq 0x70(%rbx), %r15
movq 0xb8(%rbx), %rdi
callq 0x8262
shlq $0x5, %r12
addq %r12, %r15
movsbl %al, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0xdf84
addq (%r13), %r12
movq %r12, %rdi
movl %ebp, %esi
leaq 0x20(%rsp), %rdx
callq 0xdf9a
addq $0x8, %r14
jmp 0x67a1
movl 0xc0(%rbx), %r12d
leaq 0x8(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x60(%rsp), %r15
testl %r12d, %r12d
jle 0x68a9
decl %r12d
movl %r12d, %r14d
shlq $0x5, %r14
movq (%r13), %rdi
addq %r14, %rdi
callq 0xdf14
testb %al, %al
je 0x680c
movq (%r13), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0x728a
movq %r15, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0xde74
movq (%r13), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x7290
incl %ebp
leal 0x1(%r12), %r15d
testl %r12d, %r12d
js 0x6885
movl %r12d, %edi
shlq $0x5, %rdi
addq (%r13), %rdi
movl %r12d, %esi
callq 0xdf50
decl %r12d
jmp 0x6868
addq (%r13), %r14
movq %r14, %rdi
callq 0xdfd6
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x755c
movl %r15d, %r12d
movq %r14, %r15
jmp 0x680c
testl %ebp, %ebp
movq 0x18(%rsp), %r13
je 0x68dc
movq 0x90(%rbx), %rdi
callq 0xd9ce
movl %eax, %r14d
movq 0x90(%rbx), %rdi
callq 0xd9ce
addl %ebp, %r14d
addl %ebp, %eax
imull %r14d, %eax
addl %eax, 0x88(%rbx)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x58(%rbx), %rdi
movq 0x60(%rbx), %rax
subq %rdi, %rax
sarq $0x4, %rax
cmpq %r12, %rax
jbe 0x6944
addq %r15, %rdi
callq 0x8654
testb %al, %al
je 0x693b
movq (%r13), %rdi
addq %r15, %rdi
callq 0x865c
movl %eax, %r14d
movq (%r13), %rdi
addq %r15, %rdi
callq 0x865c
incl %r14d
incl %eax
imull %r14d, %eax
addl %eax, 0x88(%rbx)
movq 0x58(%rbx), %rsi
addq %r15, %rsi
movq %r13, %rdi
callq 0x7328
incq %r12
addq $0x10, %r15
jmp 0x68e2
cmpb $0x0, 0xa8(%rbx)
jne 0x695d
movl 0x88(%rbx), %esi
movq 0x8(%rsp), %rdi
callq 0x10302
movq 0xb8(%rbx), %rdi
andq $0x0, 0xb8(%rbx)
testq %rdi, %rdi
je 0x6980
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xb8(%rbx), %rax
jmp 0x6982
xorl %eax, %eax
movq 0x98(%rbx), %rsi
movq %rsi, 0xb8(%rbx)
movq %rax, 0x98(%rbx)
leaq 0x48(%rsp), %rdi
callq 0x8266
movq (%rbx), %rax
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq *0x50(%rax)
movl %eax, %r14d
leaq 0x48(%rsp), %rdi
callq 0x7c3a
movq 0xb8(%rbx), %rdi
testb %r14b, %r14b
je 0x6a29
addq $0x8, %rdi
movq 0x10(%rsp), %rsi
callq 0xf284
cmpb $0x0, 0xa8(%rbx)
jne 0x69f4
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
movq 0x8(%rsp), %rsi
callq 0xf284
movq 0xb8(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
leaq 0x30(%rsp), %rdi
callq 0x7c3a
leaq 0x20(%rsp), %rdi
callq 0x864a
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, 0xb8(%rbx)
testq %rdi, %rdi
je 0x6a3c
movq (%rdi), %rax
callq *0x8(%rax)
pushq $0x8
popq %rdi
callq 0x5170
leaq 0xa6e2(%rip), %rcx      # 0x1112d
movq %rcx, (%rax)
movq 0x13553(%rip), %rsi     # 0x19fa8
movq %rax, %rdi
xorl %edx, %edx
callq 0x5440
jmp 0x6aa6
jmp 0x6a93
jmp 0x6a93
jmp 0x6aa6
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x7c3a
jmp 0x6aa9
jmp 0x6a78
movq %rax, %rbx
jmp 0x6ab3
jmp 0x6aa6
jmp 0x6aa6
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x7c3a
jmp 0x6abd
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x755c
jmp 0x6aa9
jmp 0x6aa6
jmp 0x6aa6
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x7c3a
leaq 0x20(%rsp), %rdi
callq 0x864a
movq %rbx, %rdi
callq 0x5450
nop