// File: /workspace/github_c_makefile_star2_O0/ArchLuke[P]YouSuck/Bishop.c
// Function: EvalBlackBishop
int EvalBlackBishop(const S_BOARD *pos)
{
	int pceNum;
	int sq;
	int index;
	int score=0;

//loop through all the black bishops
	for(pceNum = 0; pceNum < pos->pceNum[bB]; ++pceNum) {
		int mobility=7;
		sq = pos->pList[bB][pceNum];
		int sq64=SQ64(sq);
//the bishop should be on diagonals that control the center
		score += BishopTable[sq64];
		
		//check the diagonal influences
		U64 mask=BlackBishopForwardMask[sq64][0] & pos->pawns[BOTH];
		if(mask)
		{
		//	int square=FindBit(mask2);
			int square=(63-__builtin_clzll(mask));

			mobility -= (BlackMaxDiagonalDistance[sq64][0]-DiagonalDistance[square][sq64]);
				
		}

		U64 mask2=BlackBishopForwardMask[sq64][1] & pos->pawns[BOTH];		

		if(mask2)
		{
		//	int square=FindBit(mask2);
			int square=(63-__builtin_clzll(mask2));
			mobility -= (BlackMaxDiagonalDistance[sq64][1]-DiagonalDistance[square][sq64]);
				
		}

		score += mobility * bishopMobility;				
	}
	//bishop pair
	if(pos->pceNum[bB]>1)
		score += BishopPair;
	
	return -score;	

}

// Assembly:
movq %rdi, -0x8(%rsp)
movl $0x0, -0x18(%rsp)
movl $0x0, -0xc(%rsp)
movl -0xc(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x24c(%rcx), %eax
jge 0x997a
movl $0x7, -0x1c(%rsp)
movq -0x8(%rsp), %rax
movslq -0xc(%rsp), %rcx
movl 0xc3d8(%rax,%rcx,4), %eax
movl %eax, -0x10(%rsp)
movslq -0x10(%rsp), %rcx
leaq 0x607d(%rip), %rax      # 0xf8c0
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
movslq -0x20(%rsp), %rcx
leaq 0x293a(%rip), %rax      # 0xc190
movl (%rax,%rcx,4), %eax
addl -0x18(%rsp), %eax
movl %eax, -0x18(%rsp)
movslq -0x20(%rsp), %rcx
leaq 0x5843(%rip), %rax      # 0xf0b0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rsp), %rcx
andq 0x1f0(%rcx), %rax
movq %rax, -0x28(%rsp)
cmpq $0x0, -0x28(%rsp)
je 0x98de
movq -0x28(%rsp), %rax
bsrq %rax, %rax
xorq $0x3f, %rax
movl %eax, %ecx
movl $0x3f, %eax
subl %ecx, %eax
movl %eax, -0x2c(%rsp)
movslq -0x20(%rsp), %rcx
leaq 0x143fa(%rip), %rax     # 0x1dcb0
movl (%rax,%rcx,8), %ecx
movslq -0x2c(%rsp), %rdx
leaq 0x146eb(%rip), %rax     # 0x1dfb0
shlq $0x8, %rdx
addq %rdx, %rax
movslq -0x20(%rsp), %rdx
subl (%rax,%rdx,4), %ecx
movl -0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rsp)
movslq -0x20(%rsp), %rcx
leaq 0x57c6(%rip), %rax      # 0xf0b0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rsp), %rcx
andq 0x1f0(%rcx), %rax
movq %rax, -0x38(%rsp)
cmpq $0x0, -0x38(%rsp)
je 0x995d
movq -0x38(%rsp), %rax
bsrq %rax, %rax
xorq $0x3f, %rax
movl %eax, %ecx
movl $0x3f, %eax
subl %ecx, %eax
movl %eax, -0x3c(%rsp)
movslq -0x20(%rsp), %rcx
leaq 0x1437c(%rip), %rax     # 0x1dcb0
movl 0x4(%rax,%rcx,8), %ecx
movslq -0x3c(%rsp), %rdx
leaq 0x1466c(%rip), %rax     # 0x1dfb0
shlq $0x8, %rdx
addq %rdx, %rax
movslq -0x20(%rsp), %rdx
subl (%rax,%rdx,4), %ecx
movl -0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rsp)
imull $0x3, -0x1c(%rsp), %eax
addl -0x18(%rsp), %eax
movl %eax, -0x18(%rsp)
movl -0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rsp)
jmp 0x9805
movq -0x8(%rsp), %rax
cmpl $0x1, 0x24c(%rax)
jle 0x9993
movl -0x18(%rsp), %eax
addl $0xa, %eax
movl %eax, -0x18(%rsp)
xorl %eax, %eax
subl -0x18(%rsp), %eax
retq
nopw (%rax,%rax)