// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %esi
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %edx
callq 0xeab0
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $-0x2, %eax
jne 0x181cb
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $-0x3, %eax
jne 0x181cb
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0xeb30
movsbl %al, %eax
cmpl $0x1, %eax
jne 0x1816d
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x6, %edx
movl $0x38, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x5, %edx
movl $0x34, %ecx
callq 0xeb00
movb $0x1, 0x94a7(%rip)      # 0x2160b
movb $0x1, 0x94a1(%rip)      # 0x2160c
jmp 0x181c6
movq -0x8(%rbp), %rdi
xorl %ecx, %ecx
movl $0x4, %edx
movl %ecx, %esi
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %ecx, %ecx
movl $0x7, %edx
movl %ecx, %esi
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x6, %ecx
movl %ecx, %edx
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
movl $0x2, %ecx
callq 0xeb00
movb $0x1, 0x944a(%rip)      # 0x21609
movb $0x1, 0x9444(%rip)      # 0x2160a
jmp 0x18559
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $-0x2, %eax
jne 0x182c6
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $-0x4, %eax
jne 0x182c6
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0xeb30
movsbl %al, %eax
cmpl $0x1, %eax
jne 0x18268
movq -0x8(%rbp), %rdi
movl $0x7, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x2, %edx
movl $0x38, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
movl $0x7, %esi
movl $0x3, %edx
movl $0x34, %ecx
callq 0xeb00
movb $0x1, 0x93ad(%rip)      # 0x2160c
movb $0x1, 0x93a5(%rip)      # 0x2160b
jmp 0x182c1
movq -0x8(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %ecx, %ecx
movl $0x4, %edx
movl %ecx, %esi
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x6, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
callq 0xeb00
movb $0x1, 0x9350(%rip)      # 0x2160a
movb $0x1, 0x9349(%rip)      # 0x2160a
jmp 0x18557
movsbl -0x19(%rbp), %eax
cmpl $0x6, %eax
jne 0x182e2
movb $0x1, 0x9333(%rip)      # 0x21609
movb $0x1, 0x932d(%rip)      # 0x2160a
jmp 0x1851f
movsbl -0x19(%rbp), %eax
cmpl $0x38, %eax
jne 0x182fe
movb $0x1, 0x9319(%rip)      # 0x2160b
movb $0x1, 0x9313(%rip)      # 0x2160c
jmp 0x1851d
movsbl -0x19(%rbp), %eax
cmpl $0x2, %eax
jne 0x183a0
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x1832e
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x1832e
movb $0x1, 0x92de(%rip)      # 0x2160a
jmp 0x1839b
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x18351
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x7, %eax
jne 0x18351
movb $0x1, 0x92ba(%rip)      # 0x21609
jmp 0x18399
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x7, %eax
jne 0x18374
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x18374
movb $0x1, 0x929a(%rip)      # 0x2160c
jmp 0x18397
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x7, %eax
jne 0x18395
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x7, %eax
jne 0x18395
movb $0x1, 0x9276(%rip)      # 0x2160b
jmp 0x18397
jmp 0x18399
jmp 0x1839b
jmp 0x1851b
movsbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0x1845d
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x4, %eax
jne 0x18458
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x5, %eax
jne 0x18458
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
je 0x18458
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x33, %eax
jne 0x18456
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
movq -0x18(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0x18456
movq -0x18(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x4, %eax
jne 0x18456
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x1843e
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x18456
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %edx
movl $0x4, %esi
xorl %ecx, %ecx
callq 0xeb00
jmp 0x18458
jmp 0x18519
movsbl -0x19(%rbp), %eax
cmpl $0x33, %eax
jne 0x18517
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3, %eax
jne 0x18515
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x2, %eax
jne 0x18515
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
je 0x18515
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x1, %eax
jne 0x18513
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
movq -0x18(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0x18513
movq -0x18(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x3, %eax
jne 0x18513
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x184fb
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x18513
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movsbl 0x4(%rax), %edx
movl $0x3, %esi
xorl %ecx, %ecx
callq 0xeb00
jmp 0x18515
jmp 0x18517
jmp 0x18519
jmp 0x1851b
jmp 0x1851d
jmp 0x1851f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %esi
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %edx
xorl %ecx, %ecx
callq 0xeb00
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %esi
movq -0x10(%rbp), %rax
movsbl 0x4(%rax), %edx
movsbl -0x19(%rbp), %ecx
callq 0xeb00
jmp 0x18559
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x7, %eax
jne 0x1858d
movsbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0x1858d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %esi
movq -0x10(%rbp), %rax
movsbl 0x4(%rax), %edx
movl $0x5, %ecx
callq 0xeb00
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x0, %eax
jne 0x185c1
movsbl -0x19(%rbp), %eax
cmpl $0x33, %eax
jne 0x185c1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %esi
movq -0x10(%rbp), %rax
movsbl 0x4(%rax), %edx
movl $0x37, %ecx
callq 0xeb00
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)