// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x868, %rsp            # imm = 0x868
movq %rdi, 0x858(%rsp)
movl %esi, 0x854(%rsp)
movq %rdx, 0x848(%rsp)
movl %ecx, 0x844(%rsp)
movl $0xffff8ad0, 0x83c(%rsp) # imm = 0xFFFF8AD0
movl $0x0, 0x838(%rsp)
movl $0x0, 0x834(%rsp)
movl $0xffff8ad0, 0x830(%rsp) # imm = 0xFFFF8AD0
movl 0x854(%rsp), %edi
callq 0x6040
movq %rax, %rsi
leaq 0x3e35(%rip), %rdi      # 0xbe7c
movb $0x0, %al
callq 0x1060
movq 0x858(%rsp), %rdi
movl 0x854(%rsp), %esi
callq 0x3c20
movq 0x858(%rsp), %rax
movq 0x858(%rsp), %rcx
movslq 0x200(%rcx), %rcx
movl 0x1f8(%rax,%rcx,4), %edi
movq 0x858(%rsp), %rax
movl 0x200(%rax), %esi
xorl $0x1, %esi
movq 0x858(%rsp), %rdx
callq 0x1750
cmpl $0x0, %eax
je 0x80b3
movl $0xffff8ad0, 0x864(%rsp) # imm = 0xFFFF8AD0
jmp 0x8385
movq 0x858(%rsp), %rdi
movq 0x848(%rsp), %rsi
movl $0x1, %edx
callq 0x45e0
movl $0x0, 0x840(%rsp)
movl 0x840(%rsp), %eax
movq 0x848(%rsp), %rcx
cmpl 0x800(%rcx), %eax
jge 0x836a
movq 0x848(%rsp), %rax
movslq 0x840(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, 0x82c(%rsp)
movl 0x82c(%rsp), %eax
sarl $0x7, %eax
andl $0x7f, %eax
movl %eax, 0x828(%rsp)
movq 0x858(%rsp), %rdi
movl 0x82c(%rsp), %esi
movl 0x854(%rsp), %edx
callq 0x8460
cmpl $0x0, %eax
je 0x8352
movq 0x858(%rsp), %rdi
movl 0x82c(%rsp), %esi
callq 0x3c20
movq 0x858(%rsp), %rcx
leaq 0x20(%rsp), %rax
movl $0xffff8ad0, %edi       # imm = 0xFFFF8AD0
movl $0x7530, %esi           # imm = 0x7530
movl $0x6, %edx
leaq 0x22fe4(%rip), %r8      # 0x2b160
movl $0x1, %r9d
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x68e0
movl %eax, 0x83c(%rsp)
movq 0x858(%rsp), %rax
movq 0x220(%rax), %rax
movq 0x858(%rsp), %rcx
movslq 0xc480(%rcx), %rcx
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, 0x1c(%rsp)
movq 0x858(%rsp), %rax
movq 0xc478(%rax), %rax
movslq 0x1c(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x858(%rsp), %rcx
cmpq 0x220(%rcx), %rax
jne 0x821a
movq 0x858(%rsp), %rax
movq 0xc478(%rax), %rax
movslq 0x1c(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, 0x834(%rsp)
movl 0x83c(%rsp), %eax
subl $0x64, %eax
cmpl 0x844(%rsp), %eax
jle 0x8345
movl 0x834(%rsp), %eax
andl $0x7c000, %eax          # imm = 0x7C000
cmpl $0x0, %eax
jne 0x82b4
movl 0x82c(%rsp), %edi
callq 0x6040
movq %rax, %rsi
movl 0x82c(%rsp), %edx
leaq 0x3c2c(%rip), %rdi      # 0xbe8b
movb $0x0, %al
callq 0x1060
movl 0x834(%rsp), %edi
callq 0x6040
movq %rax, %rsi
leaq 0x3c22(%rip), %rdi      # 0xbe9e
movb $0x0, %al
callq 0x1060
leaq 0x3c27(%rip), %rdi      # 0xbeb1
movb $0x0, %al
callq 0x1060
movl 0x83c(%rsp), %eax
cmpl 0x830(%rsp), %eax
jle 0x82af
movl 0x83c(%rsp), %eax
movl %eax, 0x830(%rsp)
jmp 0x8343
movl 0x834(%rsp), %eax
sarl $0x7, %eax
andl $0x7f, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x828(%rsp), %eax
je 0x8341
movl 0x82c(%rsp), %edi
callq 0x6040
movq %rax, %rsi
movl 0x82c(%rsp), %edx
leaq 0x3b9c(%rip), %rdi      # 0xbe8b
movb $0x0, %al
callq 0x1060
movl 0x834(%rsp), %edi
callq 0x6040
movq %rax, %rsi
leaq 0x3b92(%rip), %rdi      # 0xbe9e
movb $0x0, %al
callq 0x1060
leaq 0x3b97(%rip), %rdi      # 0xbeb1
movb $0x0, %al
callq 0x1060
movl 0x83c(%rsp), %eax
cmpl 0x830(%rsp), %eax
jle 0x833f
movl 0x83c(%rsp), %eax
movl %eax, 0x830(%rsp)
jmp 0x8341
jmp 0x8343
jmp 0x8345
movq 0x858(%rsp), %rdi
callq 0x5ad0
jmp 0x8354
movl 0x840(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x840(%rsp)
jmp 0x80d8
movq 0x858(%rsp), %rdi
callq 0x5ad0
movl 0x830(%rsp), %eax
movl %eax, 0x864(%rsp)
movl 0x864(%rsp), %eax
addq $0x868, %rsp            # imm = 0x868
retq
nopw %cs:(%rax,%rax)