// File: /workspace/github_c_makefile_star2_O2/upcrob[P]garry/moves.c
// Function: executeMove(char*, Move*, Move*)
void executeMove(char* board, Move* move, Move* prevMove)
{
	char pieceId = getPieceAt(board, move->startRow, move->startCol);
	if (move->startRow == CASTLE && move->endRow == KINGSIDE)
	{
		//castle kingside
		if (isBlack(move->pieceId) == TRUE)
		{
			//black
			setPieceAt(board, 7, 4, EMPTY);
			setPieceAt(board, 7, 7, EMPTY);
			setPieceAt(board, 7, 6, BLACK + KING);
			setPieceAt(board, 7, 5, BLACK + ROOK);
			blackKCastleInvalid = TRUE;
			blackQCastleInvalid = TRUE;
		} else {
			//white
			setPieceAt(board, 0, 4, EMPTY);
			setPieceAt(board, 0, 7, EMPTY);
			setPieceAt(board, 0, 6, KING);
			setPieceAt(board, 0, 5, ROOK);
			whiteKCastleInvalid = TRUE;
			whiteQCastleInvalid = TRUE;
		}
	} else if (move->startRow == CASTLE && move->endRow == QUEENSIDE) {
		//castle queenside
		if (isBlack(move->pieceId) == TRUE)
		{
			//black
			setPieceAt(board, 7, 0, EMPTY);
			setPieceAt(board, 7, 4, EMPTY);
			setPieceAt(board, 7, 2, BLACK + KING);
			setPieceAt(board, 7, 3, BLACK + ROOK);
			blackQCastleInvalid = TRUE;
			blackKCastleInvalid = TRUE;
		} else {
			//white
			setPieceAt(board, 0, 0, EMPTY);
			setPieceAt(board, 0, 4, EMPTY);
			setPieceAt(board, 0, 2, KING);
			setPieceAt(board, 0, 3, ROOK);
			whiteQCastleInvalid = TRUE;
			whiteQCastleInvalid = TRUE;
		}
	} else {
		if (pieceId == KING)
		{
			whiteKCastleInvalid = TRUE;
			whiteQCastleInvalid = TRUE;
		} else if (pieceId == BLACK + KING) {
			blackKCastleInvalid = TRUE;
			blackQCastleInvalid = TRUE;
		} else if (pieceId == ROOK) {
			if (move->startRow == 0 && move->startCol == 0)
			{
				whiteQCastleInvalid = TRUE;
			} else if (move->startRow == 0 && move->startCol == 7) {
				whiteKCastleInvalid = TRUE;
			} else if (move->startRow == 7 && move->startCol == 0) {
				blackQCastleInvalid = TRUE;
			} else if (move->startRow == 7 && move->startCol == 7) {
				blackKCastleInvalid = TRUE;
			}
		} else if (pieceId == PAWN) {
			//check for white en passant case
			if (move->startRow == 4 && move->endRow == 5 && move->startCol != move->endCol)
			{
				if (prevMove->pieceId == PAWN + BLACK && prevMove->startCol == prevMove->endCol &&
					prevMove->endRow == 4 && (prevMove->endCol == move->startCol + 1 ||
											  prevMove->endCol == move->startCol - 1))
				{
					//capture pawn
					setPieceAt(board, 4, prevMove->endCol, EMPTY);
				}
			}
		} else if (pieceId == PAWN + BLACK) {
			//check for black en passant case
			if (move->startRow == 3 && move->endRow == 2 && move->startCol != move->endCol)
			{
				if (prevMove->pieceId == PAWN && prevMove->startCol == prevMove->endCol &&
					prevMove->endRow == 3 && (prevMove->endCol == move->startCol + 1 ||
											  prevMove->endCol == move->startCol - 1))
				{
					//capture pawn
					setPieceAt(board, 3, prevMove->endCol, EMPTY);
				}
			}
		}
		
		setPieceAt(board, move->startRow, move->startCol, EMPTY);
		setPieceAt(board, move->endRow, move->endCol, pieceId);
	}

	//convert pawn to queen if necessary
	if (move->endRow == 7 && pieceId == PAWN)
		setPieceAt(board, move->endRow, move->endCol, QUEEN);

	if (move->endRow == 0 && pieceId == BLACK + PAWN)
		setPieceAt(board, move->endRow, move->endCol, BLACK + QUEEN);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movsbl 0x1(%rsi), %esi
movsbl 0x2(%r14), %edx
callq 0x3534
movl %eax, %r15d
movzbl 0x1(%r14), %eax
cmpl $0xfe, %eax
jne 0x8997
movzbl 0x3(%r14), %ecx
cmpl $0xfc, %ecx
je 0x89dc
cmpl $0xfd, %ecx
jne 0x8997
movsbl (%r14), %edi
callq 0x3565
cmpb $0x1, %al
jne 0x8b69
pushq $0x7
popq %r12
pushq $0x4
popq %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x3557
movq %rbx, %rdi
movl %r12d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x3557
pushq $0x6
popq %rdx
pushq $0x38
popq %rcx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3557
pushq $0x5
popq %rdx
pushq $0x34
popq %rcx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3557
movb $0x1, %al
movb %al, 0x4887(%rip)       # 0xd213
movb %al, 0x4882(%rip)       # 0xd214
jmp 0x8c54
cmpb $0x1, %r15b
je 0x8af3
movzbl %r15b, %ecx
cmpl $0x2, %ecx
je 0x8a45
cmpl $0x38, %ecx
je 0x8ae0
cmpl $0x33, %ecx
je 0x8a78
cmpl $0x6, %ecx
jne 0x8c2a
movb $0x1, %al
movb %al, 0x4840(%rip)       # 0xd211
movb %al, 0x483b(%rip)       # 0xd212
jmp 0x8c2a
movsbl (%r14), %edi
callq 0x3565
cmpb $0x1, %al
jne 0x8bb9
pushq $0x7
popq %r12
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3557
pushq $0x4
popq %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x3557
pushq $0x2
popq %rdx
pushq $0x38
popq %rcx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3557
pushq $0x3
popq %rdx
pushq $0x34
popq %rcx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3557
movb $0x1, %al
movb %al, 0x47da(%rip)       # 0xd214
movb %al, 0x47d3(%rip)       # 0xd213
jmp 0x8c54
cmpl $0x7, %eax
je 0x8c03
testl %eax, %eax
jne 0x8c2a
movzbl 0x2(%r14), %eax
cmpl $0x7, %eax
je 0x8c1a
testl %eax, %eax
jne 0x8c2a
movb $0x1, 0x479f(%rip)      # 0xd212
jmp 0x8c2a
cmpl $0x3, %eax
jne 0x8c2a
cmpb $0x2, 0x3(%r14)
jne 0x8c2a
movsbl 0x2(%r14), %eax
cmpb 0x4(%r14), %al
je 0x8c2a
cmpb $0x1, (%r12)
jne 0x8c2a
movsbl 0x4(%r12), %edx
cmpb %dl, 0x2(%r12)
jne 0x8c2a
cmpb $0x3, 0x3(%r12)
jne 0x8c2a
leal 0x1(%rax), %ecx
cmpl %edx, %ecx
sete %cl
decl %eax
cmpl %edx, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x8c2a
pushq $0x3
jmp 0x8b59
movb $0x1, %al
movb %al, 0x472b(%rip)       # 0xd213
movb %al, 0x4726(%rip)       # 0xd214
jmp 0x8c2a
cmpl $0x4, %eax
jne 0x8c2a
cmpb $0x5, 0x3(%r14)
jne 0x8c2a
movsbl 0x2(%r14), %eax
cmpb 0x4(%r14), %al
je 0x8c2a
cmpb $0x33, (%r12)
jne 0x8c2a
movsbl 0x4(%r12), %edx
cmpb %dl, 0x2(%r12)
jne 0x8c2a
cmpb $0x4, 0x3(%r12)
jne 0x8c2a
leal 0x1(%rax), %ecx
cmpl %edx, %ecx
sete %cl
decl %eax
cmpl %edx, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x8c2a
pushq $0x4
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3557
jmp 0x8c2a
pushq $0x4
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3557
pushq $0x7
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3557
pushq $0x6
popq %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %ecx, %edx
callq 0x3557
pushq $0x5
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3557
movb $0x1, %al
movb %al, 0x4663(%rip)       # 0xd211
movb %al, 0x465e(%rip)       # 0xd212
jmp 0x8c54
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3557
pushq $0x4
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3557
pushq $0x2
popq %r12
pushq $0x6
popq %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x3557
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
movl %r12d, %ecx
callq 0x3557
movb $0x1, 0x4611(%rip)      # 0xd212
jmp 0x8c54
movzbl 0x2(%r14), %eax
cmpl $0x7, %eax
je 0x8c23
testl %eax, %eax
jne 0x8c2a
movb $0x1, 0x45fc(%rip)      # 0xd214
jmp 0x8c2a
movb $0x1, 0x45f0(%rip)      # 0xd211
jmp 0x8c2a
movb $0x1, 0x45e9(%rip)      # 0xd213
movsbl 0x1(%r14), %esi
movsbl 0x2(%r14), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3557
movsbl 0x3(%r14), %esi
movsbl 0x4(%r14), %edx
movsbl %r15b, %ecx
movq %rbx, %rdi
callq 0x3557
movb 0x3(%r14), %al
movl %eax, %ecx
xorb $0x7, %cl
movl %r15d, %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x8c77
movsbl 0x4(%r14), %edx
pushq $0x7
popq %rsi
pushq $0x5
popq %rcx
movq %rbx, %rdi
jmp 0x8c8d
xorb $0x33, %r15b
orb %al, %r15b
jne 0x8c9a
movsbl 0x4(%r14), %edx
pushq $0x37
popq %rcx
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3557
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq