// File: /workspace/github_cpp_makefile_star2_O1/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 0x6ec7
xorl %r15d, %r15d
leaq 0x70(%rsp), %r14
movq 0xb8(%rbx), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x8872
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x50(%rax)
movl %eax, %ebp
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x6ea5
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
testb %bpl, %bpl
je 0x6ec7
movq 0xb8(%rbx), %rdi
movl $0x1, %esi
callq 0x8790
incl %r15d
cmpl 0xc0(%rbx), %r15d
jl 0x6e69
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0x110ce
cmpb $0x0, 0xa8(%rbx)
jne 0x6ef0
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
callq 0x110ce
movq 0xb8(%rbx), %rdi
callq 0x897a
movl %eax, %ebp
movq 0x90(%rbx), %rdi
callq 0xf176
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x8a24
leaq 0x58(%rbx), %rdi
movq %rdi, 0x8(%rsp)
movq %r15, %rsi
callq 0x7a88
movq 0xb8(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x8636
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
movq %rbx, (%rsp)
je 0x6f9f
movslq (%r14), %r12
movl 0x4(%r14), %ebp
movq 0x70(%rbx), %r13
movq 0xb8(%rbx), %rdi
callq 0x8632
shlq $0x5, %r12
addq %r12, %r13
movsbl %al, %edx
movq %r13, %rdi
movl %ebp, %esi
callq 0xf92e
movq (%rsp), %rax
addq 0x70(%rax), %r12
movq %r12, %rdi
movl %ebp, %esi
leaq 0x60(%rsp), %rdx
callq 0xf976
addq $0x8, %r14
cmpq %r15, %r14
movq (%rsp), %rbx
jne 0x6f50
movl 0xc0(%rbx), %r13d
testl %r13d, %r13d
jle 0x7084
leaq 0x70(%rbx), %r15
leaq 0x8(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
leaq 0x88(%rsp), %r14
movq %r13, 0x18(%rsp)
decl %r13d
movq %r13, %r12
shlq $0x5, %r12
movq (%r15), %rdi
addq %r12, %rdi
callq 0xf84c
testb %al, %al
je 0x7075
movq (%r15), %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0x81c6
movq %r14, %rbx
movq %r14, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
callq 0xf78c
movq (%r15), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x7ac8
incl %ebp
movl %ebp, 0x14(%rsp)
movl %r13d, %ebp
shlq $0x5, %rbp
movq 0x18(%rsp), %rax
movl %eax, %r13d
movq (%r15), %rdi
addq %rbp, %rdi
decl %r13d
movl %r13d, %esi
callq 0xf8ca
addq $-0x20, %rbp
testl %r13d, %r13d
jg 0x7039
addq (%r15), %r12
movq %r12, %rdi
callq 0xfa42
movq %r14, %rdi
callq 0x7b7c
movl 0x14(%rsp), %ebp
movq (%rsp), %rbx
movq 0x18(%rsp), %r13
jmp 0x7079
movq (%rsp), %rbx
testl %r13d, %r13d
jg 0x6fcf
jmp 0x7086
xorl %ebp, %ebp
movl %ebp, %r12d
testl %ebp, %ebp
jle 0x70b6
movq 0x90(%rbx), %rdi
callq 0xf176
movl %eax, %ebp
movq 0x90(%rbx), %rdi
callq 0xf176
addl %r12d, %ebp
addl %r12d, %eax
imull %ebp, %eax
addl %eax, 0x88(%rbx)
movq 0x58(%rbx), %rdi
cmpq %rdi, 0x60(%rbx)
je 0x712d
xorl %r14d, %r14d
xorl %r15d, %r15d
addq %r14, %rdi
callq 0x8a42
testb %al, %al
je 0x7112
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r14, %rdi
callq 0x8a4a
movl %eax, %ebp
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r14, %rdi
callq 0x8a4a
incl %ebp
incl %eax
imull %ebp, %eax
addl %eax, 0x88(%rbx)
movq 0x58(%rbx), %rsi
addq %r14, %rsi
movq 0x8(%rsp), %rdi
callq 0x8456
incq %r15
movq 0x58(%rbx), %rdi
movq 0x60(%rbx), %rax
subq %rdi, %rax
sarq $0x4, %rax
addq $0x10, %r14
cmpq %r15, %rax
ja 0x70c6
cmpb $0x0, 0xa8(%rbx)
jne 0x7145
leaq 0x30(%rbx), %rdi
movl 0x88(%rbx), %esi
callq 0x12678
movq 0xb8(%rbx), %rdi
movq $0x0, 0xb8(%rbx)
testq %rdi, %rdi
je 0x7162
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x98(%rbx), %rsi
movq 0xb8(%rbx), %rax
movq %rsi, 0xb8(%rbx)
movq %rax, 0x98(%rbx)
leaq 0x48(%rsp), %rdi
callq 0x8636
movq (%rbx), %rax
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq *0x50(%rax)
movl %eax, %ebp
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x71af
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
movq 0xb8(%rbx), %rdi
testb %bpl, %bpl
je 0x7228
addq $0x8, %rdi
leaq 0x8(%rbx), %rsi
callq 0x110bc
cmpb $0x0, 0xa8(%rbx)
jne 0x71e5
movq 0xb8(%rbx), %rdi
addq $0x8, %rdi
leaq 0x30(%rbx), %rsi
callq 0x110bc
movq 0xb8(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x7209
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
leaq 0x60(%rsp), %rdi
callq 0x8a36
movl %r12d, %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 0x723e
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x8, %edi
callq 0x5140
leaq 0xbef1(%rip), %rcx      # 0x13140
movq %rcx, (%rax)
movq 0x13d4f(%rip), %rsi     # 0x1afa8
movq %rax, %rdi
xorl %edx, %edx
callq 0x5470
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x72ca
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
jmp 0x72ca
jmp 0x7281
movq %rax, %rbx
jmp 0x72e1
jmp 0x72b5
jmp 0x72ba
jmp 0x72b5
jmp 0x72b5
jmp 0x72ba
jmp 0x72b5
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x72eb
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
jmp 0x72eb
jmp 0x72b5
jmp 0x72b5
movq %rax, %rbx
jmp 0x72ca
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x7b7c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x72e1
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x52c0
leaq 0x60(%rsp), %rdi
callq 0x8a36
movq %rbx, %rdi
callq 0x5480
nop