// File: /workspace/github_cpp_makefile_star2_O1/MatthewZMD[P]TetrisDual/concreteboard.cc
// Function: ConcreteBoard::drop()
int ConcreteBoard::drop() {
	// down until impossible
	while (down(1));
    // Consider level4 case
	if (level->dropBrownBlock()) {
        ++countTurn;
        if (countTurn == 5) {
			for (int i = 17; i >= 0; --i) {
				if (allCells[i][5].type == CellType::E) {
                    allCells[i][5].type = CellType::Star;
                    break;
                }
            }
			countTurn = 0;
        }
    }
	bool lineFull = 1;
	int RemoveLine = 0;
	for (int i = 17; i >= 0; --i) {
		for (int j = 0; j < 11; ++j) {
			if (allCells[i][j].isEmpty()) {
				lineFull = 0;
				break;
			}
		}
		if (lineFull == 1) {
			for (int j = 0; j < 11; ++j) {
				allCells[i][j].cellState.cellStatus = CellStatus::Dead;
				if (allCells[i][j].squad.size() == 0 && allCells[i][j].type != CellType::Star) {
					score += (allCells[i][j].blockLevel + 1) * (allCells[i][j].blockLevel + 1);
				}
				allCells[i][j].type = CellType::E;
				for (auto &k : allCells[i][j].squad) {
					for (unsigned p = 0; p < k->squad.size(); ++p) {
						if (k->squad[p]->pos == allCells[i][j].pos) {
							k->squad.erase(k->squad.begin() + p);
							break;
						}
					}
				}
				allCells[i][j].notifyObservers();
			}
			++RemoveLine;
			++i;
		}
		lineFull = 1;
	}
	if (RemoveLine != 0) {
		score += (RemoveLine + level->getLevel()) * (RemoveLine + level->getLevel());
		countTurn = 0;

	}
	for (int j = 0; j < 11; ++j) {
		if (!allCells[2][j].isEmpty()) {
			throw "Game Over";
		}
	}
	turnGG = true;
	notifyObservers();
	return RemoveLine;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
callq *0x20(%rax)
testb %al, %al
jne 0x98b5
movq 0x60(%rbx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x9916
movl 0x70(%rbx), %eax
incl %eax
movl %eax, 0x70(%rbx)
cmpl $0x5, %eax
jne 0x9916
movq 0x78(%rbx), %rax
movl $0x11, %ecx
movl %ecx, %edx
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rdx
cmpl $0x7, 0x334(%rdx)
je 0x9905
addl $-0x1, %ecx
jb 0x98eb
jmp 0x990f
movl $0x8, 0x334(%rdx)
movl $0x0, 0x70(%rbx)
movl $0x11, %ebp
xorl %r13d, %r13d
movl %ebp, %r14d
leaq (%r14,%r14,2), %r15
xorl %r12d, %r12d
movq 0x78(%rbx), %rax
movq (%rax,%r15,8), %rdi
addq %r12, %rdi
callq 0x8784
testb %al, %al
jne 0x9a76
addq $0x90, %r12
cmpq $0x630, %r12            # imm = 0x630
jne 0x9928
movq %rbp, 0x10(%rsp)
movq %r13, 0x18(%rsp)
leaq (%r14,%r14,2), %r12
xorl %edx, %edx
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rcx
leaq (%rdx,%rdx,8), %rbp
shlq $0x4, %rbp
leaq (%rcx,%rbp), %rax
movl $0x0, 0x88(%rcx,%rbp)
movq 0x68(%rcx,%rbp), %r14
movq 0x70(%rcx,%rbp), %rcx
movq %rcx, 0x8(%rsp)
cmpq %r14, %rcx
jne 0x99a4
cmpl $0x8, 0x64(%rax)
je 0x99a4
movl 0x60(%rax), %ecx
incl %ecx
imull %ecx, %ecx
addl %ecx, 0x5c(%rbx)
movq %rdx, 0x20(%rsp)
movl $0x7, 0x64(%rax)
cmpq 0x8(%rsp), %r14
je 0x9a40
movq (%r14), %rcx
movq 0x68(%rcx), %rax
cmpq %rax, 0x70(%rcx)
je 0x9a37
movl $0x1, %r15d
xorl %r13d, %r13d
movq (%rax,%r13,8), %rdi
addq $0x58, %rdi
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x58(%rax,%rbp), %rsi
callq 0xc0dc
testb %al, %al
jne 0x9a0e
movl %r15d, %r13d
movq (%r14), %rcx
movq 0x68(%rcx), %rax
movq 0x70(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r15d
cmpq %r13, %rcx
ja 0x99d1
jmp 0x9a37
movq (%r14), %r15
movq 0x68(%r15), %rax
movq 0x70(%r15), %rdx
leaq (%rax,%r13,8), %rsi
addq $0x8, %rsi
cmpq %rdx, %rsi
je 0x9a32
leaq (%rax,%r13,8), %rdi
subq %rsi, %rdx
callq 0x5490
addq $-0x8, 0x70(%r15)
addq $0x8, %r14
jmp 0x99b0
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
callq 0xedfe
movq 0x20(%rsp), %rdx
incq %rdx
cmpq $0xb, %rdx
jne 0x9960
movq 0x18(%rsp), %r13
incl %r13d
movq 0x10(%rsp), %rbp
incl %ebp
leal -0x1(%rbp), %eax
testl %ebp, %ebp
movl %eax, %ebp
jg 0x991e
testl %r13d, %r13d
je 0x9aaf
movq 0x60(%rbx), %rdi
callq 0xec5c
movl %eax, %ebp
addl %r13d, %ebp
movq 0x60(%rbx), %rdi
callq 0xec5c
addl %r13d, %eax
imull %ebp, %eax
addl %eax, 0x5c(%rbx)
movl $0x0, 0x70(%rbx)
xorl %r14d, %r14d
movq 0x78(%rbx), %rax
movq 0x30(%rax), %rdi
addq %r14, %rdi
callq 0x8784
testb %al, %al
je 0x9af7
addq $0x90, %r14
cmpq $0x630, %r14            # imm = 0x630
jne 0x9ab2
movb $0x1, 0x90(%rbx)
movq %rbx, %rdi
callq 0xedfe
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x5180
leaq 0x9829(%rip), %rcx      # 0x13331
movq %rcx, (%rax)
movq 0x1247e(%rip), %rsi     # 0x1bf90
movq %rax, %rdi
xorl %edx, %edx
callq 0x54c0