// File: /workspace/github_c_makefile_star2_O0/upcrob[P]garry/chess.c
// Function: strToMove(char*)
Move* strToMove(char* str)
{
	if (toUpperCase(str[0]) == 'C' && toUpperCase(str[1]) == 'K') {
		//kingside castle
		Move* move = (Move*) malloc(sizeof(Move));
		move->startRow = CASTLE;
		move->startCol = CASTLE;
		move->endRow = KINGSIDE;
		move->endCol = KINGSIDE;
		
		move->pieceId = EMPTY;
		move->boardScore = 0;
		
		return move;
	} else if (toUpperCase(str[0]) == 'C' && toUpperCase(str[1]) == 'Q') {
		printf("CASTLE QUEEN\n");
		Move* move = (Move*) malloc(sizeof(Move));
		move->startRow = CASTLE;
		move->startCol = CASTLE;
		move->endRow = QUEENSIDE;
		move->endCol = QUEENSIDE;
		
		move->pieceId = EMPTY;
		move->boardScore = 0;
		
		return move;
	} else if (strlen(str) < 4) {
		return NULL;
	} else {
		int startRow, startCol, endRow, endCol;
		char startc, endc;
		startc = toUpperCase(str[0]);
		endc = toUpperCase(str[2]);
		switch (startc)
		{
			case 'A':
				startCol = 0;
				break;
			case 'B':
				startCol = 1;
				break;
			case 'C':
				startCol = 2;
				break;
			case 'D':
				startCol = 3;
				break;
			case 'E':
				startCol = 4;
				break;
			case 'F':
				startCol = 5;
				break;
			case 'G':
				startCol = 6;
				break;
			case 'H':
				startCol = 7;
				break;
			default:
				return NULL;
		}

		startRow = str[1] - 48 - 1;
		if (startRow > 7 || startRow < 0)
			return NULL;

		switch (endc)
		{
			case 'A':
				endCol = 0;
				break;
			case 'B':
				endCol = 1;
				break;
			case 'C':
				endCol = 2;
				break;
			case 'D':
				endCol = 3;
				break;
			case 'E':
				endCol = 4;
				break;
			case 'F':
				endCol = 5;
				break;
			case 'G':
				endCol = 6;
				break;
			case 'H':
				endCol = 7;
				break;
			default:
				return NULL;
		}

		endRow = str[3] - 48 - 1;
		if (endRow > 7 || endRow < 0)
			return NULL;

		Move* move = (Move*) malloc(sizeof(Move));
		move->startRow = (char) startRow;
		move->startCol = (char) startCol;
		move->endRow = (char) endRow;
		move->endCol = (char) endCol;

		move->pieceId = EMPTY;
		move->boardScore = 0;

		return move;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x9e00
movsbl %al, %eax
cmpl $0x43, %eax
jne 0x93a2
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x9e00
movsbl %al, %eax
cmpl $0x4b, %eax
jne 0x93a2
movl $0xc, %edi
callq 0x8780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $-0x2, 0x1(%rax)
movq -0x18(%rbp), %rax
movb $-0x2, 0x2(%rax)
movq -0x18(%rbp), %rax
movb $-0x3, 0x3(%rax)
movq -0x18(%rbp), %rax
movb $-0x3, 0x4(%rax)
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x95fd
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x9e00
movsbl %al, %eax
cmpl $0x43, %eax
jne 0x9426
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x9e00
movsbl %al, %eax
cmpl $0x51, %eax
jne 0x9426
leaq 0x11d90(%rip), %rdi     # 0x1b162
movb $0x0, %al
callq 0x8040
movl $0xc, %edi
callq 0x8780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movb $-0x2, 0x1(%rax)
movq -0x20(%rbp), %rax
movb $-0x2, 0x2(%rax)
movq -0x20(%rbp), %rax
movb $-0x4, 0x3(%rax)
movq -0x20(%rbp), %rax
movb $-0x4, 0x4(%rax)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x95fd
movq -0x10(%rbp), %rdi
callq 0x81e0
cmpq $0x4, %rax
jae 0x9442
movq $0x0, -0x8(%rbp)
jmp 0x95fd
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x9e00
movb %al, -0x31(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %edi
callq 0x9e00
movb %al, -0x32(%rbp)
movsbl -0x31(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x7, %eax
ja 0x94cf
movq -0x48(%rbp), %rax
leaq 0x11b86(%rip), %rcx     # 0x1b004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x28(%rbp)
jmp 0x94dc
movl $0x1, -0x28(%rbp)
jmp 0x94dc
movl $0x2, -0x28(%rbp)
jmp 0x94dc
movl $0x3, -0x28(%rbp)
jmp 0x94dc
movl $0x4, -0x28(%rbp)
jmp 0x94dc
movl $0x5, -0x28(%rbp)
jmp 0x94dc
movl $0x6, -0x28(%rbp)
jmp 0x94dc
movl $0x7, -0x28(%rbp)
jmp 0x94dc
movq $0x0, -0x8(%rbp)
jmp 0x95fd
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
subl $0x30, %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x7, -0x24(%rbp)
jg 0x94f9
cmpl $0x0, -0x24(%rbp)
jge 0x9506
movq $0x0, -0x8(%rbp)
jmp 0x95fd
movsbl -0x32(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x7, %eax
ja 0x9574
movq -0x50(%rbp), %rax
leaq 0x11b01(%rip), %rcx     # 0x1b024
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x30(%rbp)
jmp 0x957e
movl $0x1, -0x30(%rbp)
jmp 0x957e
movl $0x2, -0x30(%rbp)
jmp 0x957e
movl $0x3, -0x30(%rbp)
jmp 0x957e
movl $0x4, -0x30(%rbp)
jmp 0x957e
movl $0x5, -0x30(%rbp)
jmp 0x957e
movl $0x6, -0x30(%rbp)
jmp 0x957e
movl $0x7, -0x30(%rbp)
jmp 0x957e
movq $0x0, -0x8(%rbp)
jmp 0x95fd
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
subl $0x30, %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x7, -0x2c(%rbp)
jg 0x959b
cmpl $0x0, -0x2c(%rbp)
jge 0x95a5
movq $0x0, -0x8(%rbp)
jmp 0x95fd
movl $0xc, %edi
callq 0x8780
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x28(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x3(%rax)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)