// File: /workspace/github_c_makefile_star2_O3/ArchLuke[P]YouSuck/Engine.c
// Function: CheckCaptures
static int CheckCaptures(S_BOARD *pos, int pvMove,S_MOVELIST *list, int bestScore)
{
    int counter;
    int score=-INFINITE;
    int index=0;

    int refutationMove=NOMOVE;
    int trapScore=-INFINITE;

    printf("pvmove is %s \n", PrMove(pvMove));

    MakeMove(pos, pvMove);
    
    if(SqAttacked(pos->KingSq[pos->side],pos->side^1,pos))
	return -INFINITE;
    GenerateAllMoves(pos, list, TRUE);

    for(counter=0;counter<list->count;counter++)
    {

        int capture=list->moves[counter].move;

    	int sq=TOSQ(capture);


    	if(EvalCapture(pos, capture, pvMove))
	{

		MakeMove(pos, capture);    
		S_MOVELIST moves[1];
		score=AlphaBeta(-INFINITE, INFINITE, TRAPSEARCHDEPTH, pos, info, TRUE, moves, FALSE);
		int index = pos->posKey % pos->HashTable->numEntries;
		if( pos->HashTable->pTable[index].posKey == pos->posKey ) {
		    refutationMove=pos->HashTable->pTable[index].move;
		}


		if(score-TRAPTHRESHOLD>bestScore)
		{
		    if (! (refutationMove & MFLAGCAP))
		    {
        	    printf("capture is %s %d \n", PrMove(capture), capture);
		    printf("refutation is %s \n", PrMove(refutationMove));
		    printf("trap registered \n");
		    if(score>trapScore)
			trapScore=score;
		    }else{

		    int capturedSq=TOSQ(refutationMove);
		    if(capturedSq != sq)
		    {
			 printf("capture is %s %d \n", PrMove(capture), capture);
		    printf("refutation is %s \n", PrMove(refutationMove));
		    printf("trap registered \n");

			if(score>trapScore)
			    trapScore=score;
		    }
		    }
		}
		TakeMove(pos);
	}
    }
    TakeMove(pos);
    return trapScore;


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movl %edx, %r15d
movq %rsi, %r13
movl %edi, %ebp
callq 0x4a55
leaq 0x26e8(%rip), %rdi      # 0x7e0b
leaq 0x21d2a(%rip), %rsi     # 0x27454
xorl %eax, %eax
callq 0x1080
movl %ebp, %edi
callq 0x36cf
movslq 0x6761(%rip), %rsi      # 0xbea0
leaq 0x655a(%rip), %rdx      # 0xbca0
movl 0x1f8(%rdx,%rsi,4), %edi
xorl $0x1, %esi
callq 0x1547
movl $0xffff8ad0, %ecx       # imm = 0xFFFF8AD0
testl %eax, %eax
jne 0x58b2
movq %r13, %rdi
movl $0x1, %esi
callq 0x3966
movl 0x800(%r13), %ebx
testl %ebx, %ebx
jle 0x58a3
movl %r15d, 0x4(%rsp)
movl $0xffff8ad0, (%rsp)     # imm = 0xFFFF8AD0
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r13, 0x8(%rsp)
movl (%r13,%r15,8), %r12d
movl %r12d, %edi
movl %ebp, %esi
callq 0x591b
testl %eax, %eax
je 0x5892
movl %r12d, %edi
callq 0x36cf
movl $0xffff8ad0, %edi       # imm = 0xFFFF8AD0
movl $0x7530, %esi           # imm = 0x7530
movl $0x6, %edx
movl $0x1, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x4b1b
movl %eax, %ebx
movq 0x66e2(%rip), %rcx      # 0xbec0
movslq 0x1293b(%rip), %rsi     # 0x18120
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq 0x12924(%rip), %rax     # 0x18118
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
cmpq %rcx, (%rax,%rdx,8)
jne 0x5809
leaq (%rax,%rdx,8), %rax
movl 0x8(%rax), %r14d
leal -0x64(%rbx), %eax
cmpl 0x4(%rsp), %eax
jle 0x5886
testl $0x7c000, %r14d         # imm = 0x7C000
je 0x5828
movl %r14d, %eax
xorl %r12d, %eax
testl $0x3f80, %eax           # imm = 0x3F80
je 0x5886
movl %r12d, %edi
callq 0x4a55
leaq 0x25e3(%rip), %rdi      # 0x7e1a
movl %ebp, %r13d
leaq 0x21c13(%rip), %rbp     # 0x27454
movq %rbp, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1080
movl %r14d, %edi
callq 0x4a55
leaq 0x25d0(%rip), %rdi      # 0x7e2d
movq %rbp, %rsi
movl %r13d, %ebp
movq 0x8(%rsp), %r13
xorl %eax, %eax
callq 0x1080
leaq 0x27b5(%rip), %rdi      # 0x802b
callq 0x1060
movl (%rsp), %eax
cmpl %eax, %ebx
cmovgl %ebx, %eax
movl %eax, (%rsp)
callq 0x4889
movl 0x800(%r13), %ebx
incq %r15
movslq %ebx, %rax
cmpq %rax, %r15
jl 0x5795
jmp 0x58aa
movl $0xffff8ad0, (%rsp)     # imm = 0xFFFF8AD0
callq 0x4889
movl (%rsp), %ecx
movl %ecx, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq