// File: /workspace/github_c_makefile_star2_O0/upcrob[P]garry/moves.c
// Function: evaluateBoard(char*, int)
int evaluateBoard(char* board, int functionId)
{
	int count;
	char i, j;
	count = 0;

	int pawnValue, rookValue, knightValue, bishopValue, queenValue;
	int pawnAdvanceValue, safetyRatio;
	switch (functionId)
	{
		case ROB:			//Rob's values
			pawnValue = 100;
			rookValue = 500;
			knightValue = 300;
			bishopValue = 350;
			queenValue = 900;
			pawnAdvanceValue = 4;
			safetyRatio = 30;
			break;
		case TURING:		//Turing's values
			pawnValue = 100;
			rookValue = 500;
			knightValue = 300;
			bishopValue = 350;
			queenValue = 1000;
			pawnAdvanceValue = 0;
			safetyRatio = 0;
			break;
		case BERLINER:
			pawnValue = 100;
			rookValue = 510;
			knightValue = 320;
			bishopValue = 333;
			queenValue = 880;
			pawnAdvanceValue = 6;
			safetyRatio = 0;
			break;
	}

	for (i = 0; i < 8; i++)
	{
		for (j = 0; j < 8; j++)
		{
			char p = getPieceAt(board, i, j);
			if (p != EMPTY)
			{
				if (!isBlack(p))
				{
					//white piece
					switch(p)
					{
						case PAWN:
							count += pawnValue;
							count += pawnAdvanceValue * i;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count += pawnValue / safetyRatio;
							break;
						case ROOK:
							count += rookValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count += rookValue / safetyRatio;
							break;
						case KNIGHT:
							count += knightValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count += knightValue / safetyRatio;
							break;
						case BISHOP:
							count += bishopValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count += bishopValue / safetyRatio;
							break;
						case QUEEN:
							count += queenValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count += queenValue / safetyRatio;
							break;
					}
				} else {
					//black piece
					switch(p)
					{
						case BLACK + PAWN:
							count -= pawnAdvanceValue * (7 - i);
							count -= pawnValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count -= pawnValue / safetyRatio;
							break;
						case BLACK + ROOK:
							count -= rookValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count -= rookValue / safetyRatio;
							break;
						case BLACK + KNIGHT:
							count -= knightValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count -= knightValue / safetyRatio;
							break;
						case BLACK + BISHOP:
							count -= bishopValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count -= bishopValue / safetyRatio;
							break;
						case BLACK + QUEEN:
							count -= queenValue;
							if (safetyRatio > 0 && pieceSafe(board, i, j))
								count -= queenValue / safetyRatio;
							break;
					}
				}
			}
		}
	}

	return count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x38(%rbp)
subl $0x1, %eax
je 0x17cba
jmp 0x17ca3
movl -0x38(%rbp), %eax
subl $0x2, %eax
je 0x17ced
jmp 0x17cad
movl -0x38(%rbp), %eax
subl $0x3, %eax
je 0x17d20
jmp 0x17d51
movl $0x64, -0x18(%rbp)
movl $0x1f4, -0x1c(%rbp)     # imm = 0x1F4
movl $0x12c, -0x20(%rbp)     # imm = 0x12C
movl $0x15e, -0x24(%rbp)     # imm = 0x15E
movl $0x384, -0x28(%rbp)     # imm = 0x384
movl $0x4, -0x2c(%rbp)
movl $0x1e, -0x30(%rbp)
jmp 0x17d51
movl $0x64, -0x18(%rbp)
movl $0x1f4, -0x1c(%rbp)     # imm = 0x1F4
movl $0x12c, -0x20(%rbp)     # imm = 0x12C
movl $0x15e, -0x24(%rbp)     # imm = 0x15E
movl $0x3e8, -0x28(%rbp)     # imm = 0x3E8
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x17d51
movl $0x64, -0x18(%rbp)
movl $0x1fe, -0x1c(%rbp)     # imm = 0x1FE
movl $0x140, -0x20(%rbp)     # imm = 0x140
movl $0x14d, -0x24(%rbp)     # imm = 0x14D
movl $0x370, -0x28(%rbp)     # imm = 0x370
movl $0x6, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movb $0x0, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x8, %eax
jge 0x18070
movb $0x0, -0x12(%rbp)
movsbl -0x12(%rbp), %eax
cmpl $0x8, %eax
jge 0x18061
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xeab0
movb %al, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
cmpl $0x0, %eax
je 0x18052
movsbl -0x31(%rbp), %edi
callq 0xeb30
cmpb $0x0, %al
jne 0x17ee8
movsbl -0x31(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x4, %eax
ja 0x17ee3
movq -0x40(%rbp), %rax
leaq 0x3737(%rip), %rcx      # 0x1b4fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x18(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x2c(%rbp), %eax
movsbl -0x11(%rbp), %ecx
imull %ecx, %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17e0f
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17e0f
movl -0x18(%rbp), %eax
cltd
idivl -0x30(%rbp)
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x17ee3
movl -0x1c(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17e45
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17e45
movl -0x1c(%rbp), %eax
cltd
idivl -0x30(%rbp)
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x17ee3
movl -0x20(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17e7b
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17e7b
movl -0x20(%rbp), %eax
cltd
idivl -0x30(%rbp)
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x17ee3
movl -0x24(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17eae
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17eae
movl -0x24(%rbp), %eax
cltd
idivl -0x30(%rbp)
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x17ee3
movl -0x28(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17ee1
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17ee1
movl -0x28(%rbp), %eax
cltd
idivl -0x30(%rbp)
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x17ee3
jmp 0x18050
movsbl -0x31(%rbp), %eax
addl $-0x33, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x4, %eax
ja 0x1804e
movq -0x48(%rbp), %rax
leaq 0x3607(%rip), %rcx      # 0x1b510
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x2c(%rbp), %ecx
movsbl -0x11(%rbp), %edx
movl $0x7, %eax
subl %edx, %eax
imull %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17f62
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17f62
movl -0x18(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x1804e
movl -0x1c(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17f9e
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17f9e
movl -0x1c(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x1804e
movl -0x20(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x17fda
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x17fda
movl -0x20(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x1804e
movl -0x24(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x18013
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x18013
movl -0x24(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x1804e
movl -0x28(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x1804c
movq -0x8(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movsbl -0x12(%rbp), %edx
callq 0xef70
cmpb $0x0, %al
je 0x1804c
movl -0x28(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x1804e
jmp 0x18050
jmp 0x18052
jmp 0x18054
movb -0x12(%rbp), %al
addb $0x1, %al
movb %al, -0x12(%rbp)
jmp 0x17d66
jmp 0x18063
movb -0x11(%rbp), %al
addb $0x1, %al
movb %al, -0x11(%rbp)
jmp 0x17d55
movl -0x10(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)