// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movq %rsi, %r13
movl %edi, %ebp
callq 0x4aa4
leaq 0x25ee(%rip), %rdi      # 0x7e0f
leaq 0x21c2c(%rip), %rsi     # 0x27454
xorl %eax, %eax
callq 0x1080
movl %ebp, %edi
callq 0x3701
movslq 0x6663(%rip), %rsi      # 0xbea0
leaq 0x645c(%rip), %rdx      # 0xbca0
movl 0x1f8(%rdx,%rsi,4), %edi
xorl $0x1, %esi
callq 0x1543
movl $0xffff8ad0, %ecx       # imm = 0xFFFF8AD0
testl %eax, %eax
jne 0x59ab
movq %r13, %rdi
movl $0x1, %esi
callq 0x39ab
cmpl $0x0, 0x800(%r13)
jle 0x599c
movl %ebx, 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 0x5a19
testl %eax, %eax
je 0x5987
movl %r12d, %edi
callq 0x3701
movl $0xffff8ad0, %edi       # imm = 0xFFFF8AD0
movl $0x7530, %esi           # imm = 0x7530
movl $0x6, %edx
movl $0x1, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x4b6a
movl %eax, %ebx
movq 0x65e6(%rip), %rcx      # 0xbec0
movslq 0x1283f(%rip), %rsi     # 0x18120
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq 0x12828(%rip), %rax     # 0x18118
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
cmpq %rcx, (%rax,%rdx,8)
jne 0x5905
leaq (%rax,%rdx,8), %rax
movl 0x8(%rax), %r14d
leal -0x64(%rbx), %eax
cmpl 0x4(%rsp), %eax
jle 0x5982
testl $0x7c000, %r14d         # imm = 0x7C000
je 0x5924
movl %r14d, %eax
xorl %r12d, %eax
testl $0x3f80, %eax           # imm = 0x3F80
je 0x5982
movl %r12d, %edi
callq 0x4aa4
leaq 0x24eb(%rip), %rdi      # 0x7e1e
movl %ebp, %r13d
leaq 0x21b17(%rip), %rbp     # 0x27454
movq %rbp, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1080
movl %r14d, %edi
callq 0x4aa4
leaq 0x24d8(%rip), %rdi      # 0x7e31
movq %rbp, %rsi
movl %r13d, %ebp
movq 0x8(%rsp), %r13
xorl %eax, %eax
callq 0x1080
leaq 0x26bd(%rip), %rdi      # 0x802f
callq 0x1060
movl (%rsp), %eax
cmpl %eax, %ebx
cmovgl %ebx, %eax
movl %eax, (%rsp)
callq 0x48bd
incq %r15
movslq 0x800(%r13), %rax
cmpq %rax, %r15
jl 0x5891
jmp 0x59a3
movl $0xffff8ad0, (%rsp)     # imm = 0xFFFF8AD0
callq 0x48bd
movl (%rsp), %ecx
movl %ecx, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq