// File: /workspace/github_cpp_makefile_star2_O3/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 0x9817
movq 0x60(%rbx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x9878
movl 0x70(%rbx), %eax
incl %eax
movl %eax, 0x70(%rbx)
cmpl $0x5, %eax
jne 0x9878
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 0x9867
addl $-0x1, %ecx
jb 0x984d
jmp 0x9871
movl $0x8, 0x334(%rdx)
movl $0x0, 0x70(%rbx)
movl $0x11, %r13d
xorl %r15d, %r15d
movl %r13d, %eax
leaq (%rax,%rax,2), %r12
xorl %r14d, %r14d
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rdi
addq %r14, %rdi
callq 0x8760
testb %al, %al
jne 0x99e6
addq $0x90, %r14
cmpq $0x630, %r14            # imm = 0x630
jne 0x988b
movq %r13, 0x8(%rsp)
movq %r15, 0x10(%rsp)
xorl %r15d, %r15d
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rax
leaq (%r15,%r15,8), %rbp
shlq $0x4, %rbp
leaq (%rax,%rbp), %rcx
movl $0x0, 0x88(%rax,%rbp)
movq 0x68(%rax,%rbp), %r14
movq 0x70(%rax,%rbp), %rdx
movq %rdx, 0x20(%rsp)
cmpq %r14, %rdx
je 0x99a4
movq %r15, 0x18(%rsp)
movl $0x7, 0x64(%rcx)
movq (%r14), %rcx
movq 0x68(%rcx), %rax
cmpq %rax, 0x70(%rcx)
je 0x9986
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 0xbf58
testb %al, %al
jne 0x9956
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 0x9919
jmp 0x9986
movq (%r14), %r15
movq 0x68(%r15), %rax
movq 0x70(%r15), %rdx
leaq (%rax,%r13,8), %rsi
addq $0x8, %rsi
cmpq %rdx, %rsi
je 0x997e
leaq (%rax,%r13,8), %rdi
subq %rsi, %rdx
callq 0x5490
movq 0x70(%r15), %rdx
addq $-0x8, %rdx
movq %rdx, 0x70(%r15)
addq $0x8, %r14
cmpq 0x20(%rsp), %r14
jne 0x9903
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x18(%rsp), %r15
jmp 0x99bc
cmpl $0x8, 0x64(%rcx)
je 0x99b5
movl 0x60(%rcx), %edx
incl %edx
imull %edx, %edx
addl %edx, 0x5c(%rbx)
movl $0x7, 0x64(%rcx)
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
callq 0xeb4e
incq %r15
cmpq $0xb, %r15
jne 0x98c0
movq 0x10(%rsp), %r15
incl %r15d
movq 0x8(%rsp), %r13
incl %r13d
leal -0x1(%r13), %eax
testl %r13d, %r13d
movl %eax, %r13d
jg 0x9881
testl %r15d, %r15d
je 0x9a22
movq 0x60(%rbx), %rdi
callq 0xe9ac
movl %eax, %ebp
addl %r15d, %ebp
movq 0x60(%rbx), %rdi
callq 0xe9ac
addl %r15d, %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 0x8760
testb %al, %al
je 0x9a6a
addq $0x90, %r14
cmpq $0x630, %r14            # imm = 0x630
jne 0x9a25
movb $0x1, 0x90(%rbx)
movq %rbx, %rdi
callq 0xeb4e
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x5180
leaq 0x98b6(%rip), %rcx      # 0x13331
movq %rcx, (%rax)
movq 0x1250b(%rip), %rsi     # 0x1bf90
movq %rax, %rdi
xorl %edx, %edx
callq 0x54c0
nop