// File: /workspace/github_c_makefile_star2_O0/ArchLuke[P]YouSuck/Engine.c
// Function: AlphaBeta
static int AlphaBeta(int alpha, int beta, int depth, S_BOARD *pos, S_SEARCHINFO *info, int DoNull, S_MOVELIST *list, int listProvided) {
    if(depth == 0) {
        return Quiescence(alpha, beta, pos, info);
        // return EvalPosition(pos);
    }
    
    if(( info->nodes & 2047 ) == 0) {
        CheckUp(info);
    }
        
    info->nodes++;
    if(((IsRepetition(pos) && !listProvided) || pos->fiftyMove >= 100) && pos->ply) {    
        return 0;
    }
 
    if(pos->ply > MAXDEPTH - 1) {
        return EvalPosition(pos);
    }

    int InCheck = SqAttacked(pos->KingSq[pos->side],pos->side^1,pos);
    
    if(InCheck == TRUE) {
        depth++;
    }
    
    int Score = -INFINITE;
    int PvMove = NOMOVE;

    if( ProbeHashEntry(pos, &PvMove, &Score, alpha, beta, depth) == TRUE && !listProvided) {
        pos->HashTable->cut++;
        return Score;
    }

    if( DoNull && !InCheck && pos->ply && (pos->bigPce[pos->side] > 0) && depth >= 4) {
        MakeNullMove(pos);
    S_MOVELIST list2[1];    
        Score = -AlphaBeta( -beta, -beta + 1, depth-4, pos, info, FALSE, list2, FALSE);
        TakeNullMove(pos);
        if(info->stopped == TRUE) {
            return 0;
        }        
        
        if (Score >= beta && abs(Score) < ISMATE) {        
          return beta;
        }    
    }
   
    if(!listProvided)
        GenerateAllMoves(pos,list, FALSE);    
    int MoveNum = 0;
    int Legal = 0;
    int OldAlpha = alpha;
    int BestMove = NOMOVE;
    
    int BestScore = -INFINITE;
    
    Score = -INFINITE;
    
    if( PvMove != NOMOVE) {
        for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
            if( list->moves[MoveNum].move == PvMove) {
                list->moves[MoveNum].score = 2000000;
                break;
            }
        }
    }

    for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {    
            
        PickNextMove(MoveNum, list);    
        if (!MakeMove(pos,list->moves[MoveNum].move))  {
            continue;
        }
        Legal++;
    S_MOVELIST list3[1];
        Score = -AlphaBeta( -beta, -alpha, depth-1, pos, info, TRUE, list3, FALSE);
        TakeMove(pos);
        
        if(info->stopped == TRUE) {
            return 0;
        }        
        if(Score > BestScore) {
            BestScore = Score;
            BestMove = list->moves[MoveNum].move;
            if(Score > alpha) {
                if(Score >= beta) {
                    if(Legal==1) {
                        info->fhf++;
                    }
                    info->fh++;    
                    
                    if(!(list->moves[MoveNum].move & MFLAGCAP)) {
                        pos->searchKillers[1][pos->ply] = pos->searchKillers[0][pos->ply];
                        pos->searchKillers[0][pos->ply] = list->moves[MoveNum].move;
                    }
                    
                    StoreHashEntry(pos, BestMove, beta, HFBETA, depth);
                    
                    return beta;
                }
                alpha = Score;
                
                if(!(list->moves[MoveNum].move & MFLAGCAP)) {
                    pos->searchHistory[pos->pieces[FROMSQ(BestMove)]][TOSQ(BestMove)] += depth;
                }
            }
        }        
    }
    
    if(Legal == 0) {
        if(InCheck) {
            return -INFINITE + pos->ply;
        } else {
            return 0;
        }
    }
    
    if(alpha != OldAlpha) {
        StoreHashEntry(pos, BestMove, BestScore, HFEXACT, depth);
    } else {
        StoreHashEntry(pos, BestMove, alpha, HFALPHA, depth);
    }
    
    return alpha;
    
}

// Assembly:
subq $0x1068, %rsp           # imm = 0x1068
movl 0x1078(%rsp), %eax
movq 0x1070(%rsp), %rax
movl %edi, 0x1060(%rsp)
movl %esi, 0x105c(%rsp)
movl %edx, 0x1058(%rsp)
movq %rcx, 0x1050(%rsp)
movq %r8, 0x1048(%rsp)
movl %r9d, 0x1044(%rsp)
cmpl $0x0, 0x1058(%rsp)
jne 0x695c
movl 0x1060(%rsp), %edi
movl 0x105c(%rsp), %esi
movq 0x1050(%rsp), %rdx
movq 0x1048(%rsp), %rcx
callq 0x7180
movl %eax, 0x1064(%rsp)
jmp 0x709c
movq 0x1048(%rsp), %rax
movq 0x18(%rax), %rax
andq $0x7ff, %rax            # imm = 0x7FF
cmpq $0x0, %rax
jne 0x6981
movq 0x1048(%rsp), %rdi
callq 0x7440
movq 0x1048(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq 0x1050(%rsp), %rdi
callq 0x7480
cmpl $0x0, %eax
je 0x69b1
cmpl $0x0, 0x1078(%rsp)
je 0x69c2
movq 0x1050(%rsp), %rax
cmpl $0x64, 0x208(%rax)
jl 0x69e3
movq 0x1050(%rsp), %rax
cmpl $0x0, 0x20c(%rax)
je 0x69e3
movl $0x0, 0x1064(%rsp)
jmp 0x709c
movq 0x1050(%rsp), %rax
cmpl $0x3f, 0x20c(%rax)
jle 0x6a0d
movq 0x1050(%rsp), %rdi
callq 0x7510
movl %eax, 0x1064(%rsp)
jmp 0x709c
movq 0x1050(%rsp), %rax
movq 0x1050(%rsp), %rcx
movslq 0x200(%rcx), %rcx
movl 0x1f8(%rax,%rcx,4), %edi
movq 0x1050(%rsp), %rax
movl 0x200(%rax), %esi
xorl $0x1, %esi
movq 0x1050(%rsp), %rdx
callq 0x1750
movl %eax, 0x1040(%rsp)
cmpl $0x1, 0x1040(%rsp)
jne 0x6a6b
movl 0x1058(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1058(%rsp)
movl $0xffff8ad0, 0x103c(%rsp) # imm = 0xFFFF8AD0
movl $0x0, 0x1038(%rsp)
movq 0x1050(%rsp), %rdi
movl 0x1060(%rsp), %ecx
movl 0x105c(%rsp), %r8d
movl 0x1058(%rsp), %r9d
leaq 0x1038(%rsp), %rsi
leaq 0x103c(%rsp), %rdx
callq 0x76c0
cmpl $0x1, %eax
jne 0x6aee
cmpl $0x0, 0x1078(%rsp)
jne 0x6aee
movq 0x1050(%rsp), %rax
movl 0xc490(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc490(%rax)
movl 0x103c(%rsp), %eax
movl %eax, 0x1064(%rsp)
jmp 0x709c
cmpl $0x0, 0x1044(%rsp)
je 0x6c1c
cmpl $0x0, 0x1040(%rsp)
jne 0x6c1c
movq 0x1050(%rsp), %rax
cmpl $0x0, 0x20c(%rax)
je 0x6c1c
movq 0x1050(%rsp), %rax
movq 0x1050(%rsp), %rcx
movslq 0x200(%rcx), %rcx
cmpl $0x0, 0x25c(%rax,%rcx,4)
jle 0x6c1c
cmpl $0x4, 0x1058(%rsp)
jl 0x6c1c
movq 0x1050(%rsp), %rdi
callq 0x78a0
xorl %edi, %edi
subl 0x105c(%rsp), %edi
xorl %esi, %esi
subl 0x105c(%rsp), %esi
addl $0x1, %esi
movl 0x1058(%rsp), %edx
subl $0x4, %edx
movq 0x1050(%rsp), %rcx
movq 0x1048(%rsp), %r8
leaq 0x830(%rsp), %rax
xorl %r9d, %r9d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x68e0
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, 0x103c(%rsp)
movq 0x1050(%rsp), %rdi
callq 0x7a20
movq 0x1048(%rsp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x6be2
movl $0x0, 0x1064(%rsp)
jmp 0x709c
movl 0x103c(%rsp), %eax
cmpl 0x105c(%rsp), %eax
jl 0x6c1a
movl 0x103c(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x74f0, %eax           # imm = 0x74F0
jge 0x6c1a
movl 0x105c(%rsp), %eax
movl %eax, 0x1064(%rsp)
jmp 0x709c
jmp 0x6c1c
cmpl $0x0, 0x1078(%rsp)
jne 0x6c3d
movq 0x1050(%rsp), %rdi
movq 0x1070(%rsp), %rsi
xorl %edx, %edx
callq 0x45e0
movl $0x0, 0x82c(%rsp)
movl $0x0, 0x828(%rsp)
movl 0x1060(%rsp), %eax
movl %eax, 0x824(%rsp)
movl $0x0, 0x820(%rsp)
movl $0xffff8ad0, 0x81c(%rsp) # imm = 0xFFFF8AD0
movl $0xffff8ad0, 0x103c(%rsp) # imm = 0xFFFF8AD0
cmpl $0x0, 0x1038(%rsp)
je 0x6cfb
movl $0x0, 0x82c(%rsp)
movl 0x82c(%rsp), %eax
movq 0x1070(%rsp), %rcx
cmpl 0x800(%rcx), %eax
jge 0x6cf9
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %eax
cmpl 0x1038(%rsp), %eax
jne 0x6ce4
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl $0x1e8480, 0x4(%rax,%rcx,8) # imm = 0x1E8480
jmp 0x6cf9
jmp 0x6ce6
movl 0x82c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x82c(%rsp)
jmp 0x6c97
jmp 0x6cfb
movl $0x0, 0x82c(%rsp)
movl 0x82c(%rsp), %eax
movq 0x1070(%rsp), %rcx
cmpl 0x800(%rcx), %eax
jge 0x6fef
movl 0x82c(%rsp), %edi
movq 0x1070(%rsp), %rsi
callq 0x7b70
movq 0x1050(%rsp), %rdi
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %esi
callq 0x3c20
cmpl $0x0, %eax
jne 0x6d5f
jmp 0x6fd9
movl 0x828(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x828(%rsp)
xorl %edi, %edi
subl 0x105c(%rsp), %edi
xorl %esi, %esi
subl 0x1060(%rsp), %esi
movl 0x1058(%rsp), %edx
subl $0x1, %edx
movq 0x1050(%rsp), %rcx
movq 0x1048(%rsp), %r8
leaq 0x10(%rsp), %rax
movl $0x1, %r9d
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x68e0
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, 0x103c(%rsp)
movq 0x1050(%rsp), %rdi
callq 0x5ad0
movq 0x1048(%rsp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x6df3
movl $0x0, 0x1064(%rsp)
jmp 0x709c
movl 0x103c(%rsp), %eax
cmpl 0x81c(%rsp), %eax
jle 0x6fd7
movl 0x103c(%rsp), %eax
movl %eax, 0x81c(%rsp)
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, 0x820(%rsp)
movl 0x103c(%rsp), %eax
cmpl 0x1060(%rsp), %eax
jle 0x6fd5
movl 0x103c(%rsp), %eax
cmpl 0x105c(%rsp), %eax
jl 0x6f5a
cmpl $0x1, 0x828(%rsp)
jne 0x6e7b
movq 0x1048(%rsp), %rax
movss 0x4d53(%rip), %xmm0     # 0xbbc4
addss 0x28(%rax), %xmm0
movss %xmm0, 0x28(%rax)
movq 0x1048(%rsp), %rax
movss 0x4d39(%rip), %xmm0     # 0xbbc4
addss 0x24(%rax), %xmm0
movss %xmm0, 0x24(%rax)
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7c000, %eax          # imm = 0x7C000
cmpl $0x0, %eax
jne 0x6f1f
movq 0x1050(%rsp), %rax
movq 0x1050(%rsp), %rcx
movslq 0x20c(%rcx), %rcx
movl 0xde18(%rax,%rcx,4), %edx
movq 0x1050(%rsp), %rax
movq 0x1050(%rsp), %rcx
movslq 0x20c(%rcx), %rcx
movl %edx, 0xdf18(%rax,%rcx,4)
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %edx
movq 0x1050(%rsp), %rax
movq 0x1050(%rsp), %rcx
movslq 0x20c(%rcx), %rcx
movl %edx, 0xde18(%rax,%rcx,4)
movq 0x1050(%rsp), %rdi
movl 0x820(%rsp), %esi
movl 0x105c(%rsp), %edx
movl 0x1058(%rsp), %r8d
movl $0x2, %ecx
callq 0x7c30
movl 0x105c(%rsp), %eax
movl %eax, 0x1064(%rsp)
jmp 0x709c
movl 0x103c(%rsp), %eax
movl %eax, 0x1060(%rsp)
movq 0x1070(%rsp), %rax
movslq 0x82c(%rsp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7c000, %eax          # imm = 0x7C000
cmpl $0x0, %eax
jne 0x6fd3
movl 0x1058(%rsp), %edx
movq 0x1050(%rsp), %rax
addq $0xc5b8, %rax           # imm = 0xC5B8
movq 0x1050(%rsp), %rcx
movl 0x820(%rsp), %esi
andl $0x7f, %esi
movslq %esi, %rsi
movslq (%rcx,%rsi,4), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
movl 0x820(%rsp), %ecx
sarl $0x7, %ecx
andl $0x7f, %ecx
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x6fd5
jmp 0x6fd7
jmp 0x6fd9
movl 0x82c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x82c(%rsp)
jmp 0x6d06
cmpl $0x0, 0x828(%rsp)
jne 0x702c
cmpl $0x0, 0x1040(%rsp)
je 0x701f
movq 0x1050(%rsp), %rax
movl 0x20c(%rax), %eax
addl $0xffff8ad0, %eax       # imm = 0xFFFF8AD0
movl %eax, 0x1064(%rsp)
jmp 0x709c
movl $0x0, 0x1064(%rsp)
jmp 0x709c
movl 0x1060(%rsp), %eax
cmpl 0x824(%rsp), %eax
je 0x7066
movq 0x1050(%rsp), %rdi
movl 0x820(%rsp), %esi
movl 0x81c(%rsp), %edx
movl 0x1058(%rsp), %r8d
movl $0x3, %ecx
callq 0x7c30
jmp 0x708e
movq 0x1050(%rsp), %rdi
movl 0x820(%rsp), %esi
movl 0x1060(%rsp), %edx
movl 0x1058(%rsp), %r8d
movl $0x1, %ecx
callq 0x7c30
movl 0x1060(%rsp), %eax
movl %eax, 0x1064(%rsp)
movl 0x1064(%rsp), %eax
addq $0x1068, %rsp           # imm = 0x1068
retq
nopl (%rax,%rax)