// File: /workspace/github_c_makefile_star2_O1/ArchLuke[P]YouSuck/Engine.c
// Function: MakeMove
static
int MakeMove(S_BOARD *pos, int move) {

    int from = FROMSQ(move);
    int to = TOSQ(move);
    int side = pos->side;
    
    pos->history[pos->hisPly].posKey = pos->posKey;
    
    if(move & MFLAGEP) {
        if(side) {
            ClearPiece(to+10,pos);
        } else {
            ClearPiece(to-10,pos);
        }
    } else if (move & MFLAGCA) {
        switch(to) {
            case C1:
        pos->isCastled[WHITE]=TRUE;
                MovePiece(A1, D1, pos);
            break;
            case C8:
        pos->isCastled[BLACK]=TRUE;
                MovePiece(A8, D8, pos);
            break;
            case G1:
        pos->isCastled[WHITE]=TRUE;
                MovePiece(H1, F1, pos);
            break;
            case G8:
        pos->isCastled[BLACK]=TRUE;
                MovePiece(H8, F8, pos);
            break;
            default: break;
        }
    }    
    
    if(pos->enPas != NO_SQ) HASH_EP;
    HASH_CA;
    
    pos->history[pos->hisPly].move = move;
    pos->history[pos->hisPly].fiftyMove = pos->fiftyMove;
    pos->history[pos->hisPly].enPas = pos->enPas;
    pos->history[pos->hisPly].castlePerm = pos->castlePerm;

    pos->castlePerm &= CastlePerm[from];
    pos->castlePerm &= CastlePerm[to];
    pos->enPas = NO_SQ;

    HASH_CA;
    
    int captured = CAPTURED(move);
    pos->fiftyMove++;
    
    if(captured != EMPTY) {
        ClearPiece(to, pos);
        pos->fiftyMove = 0;
    }
    
    pos->hisPly++;
    pos->ply++;
    
    if(PiecePawn[pos->pieces[from]]) {
        pos->fiftyMove = 0;
        if(move & MFLAGPS) {
            if(side==WHITE) {
                pos->enPas=from+10;
            } else {
                pos->enPas=from-10;
            }
            HASH_EP;
        }
    }
    
    MovePiece(from, to, pos);
    
    int prPce = PROMOTED(move);
    if(prPce != EMPTY)   {
        ClearPiece(to, pos);
        AddPiece(to, pos, prPce);
    }
    
    if(PieceKing[pos->pieces[to]]) {
        pos->KingSq[pos->side] = to;
    }
    
    pos->side ^= 1;
    HASH_SIDE;

    
        
    if(SqAttacked(pos->KingSq[side],pos->side,pos))  {
        TakeMove(pos);
        return FALSE;
    }
    
    return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebp
movl %edi, %r14d
shrl $0x7, %r14d
andl $0x7f, %r14d
movslq 0x8780(%rip), %rbx      # 0xbea0
leaq 0x8579(%rip), %r12      # 0xbca0
movq 0x8792(%rip), %rax      # 0xbec0
movslq 0x877b(%rip), %rcx      # 0xbeb0
leaq (%rcx,%rcx,2), %rcx
movq %rax, 0x280(%r12,%rcx,8)
btl $0x12, %edi
jb 0x3779
btl $0x18, %ebp
jae 0x37df
cmpl $0x5c, %r14d
jg 0x378e
cmpl $0x17, %r14d
je 0x37b0
cmpl $0x1b, %r14d
jne 0x37df
movl $0x1, 0x874b(%rip)      # 0xbeb8
movl $0x1c, %edi
movl $0x1a, %esi
jmp 0x37da
testl %ebx, %ebx
je 0x3783
leal 0xa(%r14), %edi
jmp 0x3787
leal -0xa(%r14), %edi
callq 0x465a
jmp 0x37df
cmpl $0x5d, %r14d
je 0x37c6
cmpl $0x61, %r14d
jne 0x37df
movl $0x1, 0x8718(%rip)      # 0xbebc
movl $0x62, %edi
movl $0x60, %esi
jmp 0x37da
movl $0x1, 0x86fe(%rip)      # 0xbeb8
movl $0x15, %edi
movl $0x18, %esi
jmp 0x37da
movl $0x1, 0x86ec(%rip)      # 0xbebc
movl $0x5b, %edi
movl $0x5e, %esi
callq 0x4739
movl %ebp, %r15d
andl $0x7f, %r15d
movslq 0x86b7(%rip), %rax      # 0xbea4
cmpq $0x63, %rax
je 0x3805
leaq 0x208a6(%rip), %rcx     # 0x240a0
movq (%rcx,%rax,8), %rcx
xorq %rcx, 0x86bb(%rip)      # 0xbec0
movslq 0x86a8(%rip), %rcx      # 0xbeb4
leaq 0x2080d(%rip), %rdx     # 0x24020
movq 0x86a6(%rip), %rsi      # 0xbec0
xorq (%rdx,%rcx,8), %rsi
movq %rsi, 0x869b(%rip)      # 0xbec0
movslq 0x8684(%rip), %rdi      # 0xbeb0
leaq (%rdi,%rdi,2), %rdi
movl %ebp, 0x270(%r12,%rdi,8)
movl 0x8669(%rip), %r8d      # 0xbea8
movl %r8d, 0x27c(%r12,%rdi,8)
movl %eax, 0x278(%r12,%rdi,8)
movl %ecx, 0x274(%r12,%rdi,8)
movl %r15d, %r12d
leaq 0x3c8f(%rip), %rax      # 0x74f0
movl (%rax,%r12,4), %edi
andl %ecx, %edi
movslq %edi, %rcx
movl %r14d, %r13d
movslq (%rax,%r13,4), %rax
andq %rcx, %rax
movl %eax, 0x863a(%rip)      # 0xbeb4
movl $0x63, 0x8620(%rip)     # 0xbea4
xorq (%rdx,%rax,8), %rsi
movq %rsi, 0x8631(%rip)      # 0xbec0
incl %r8d
movl %r8d, 0x860f(%rip)      # 0xbea8
testl $0x3c000, %ebp          # imm = 0x3C000
je 0x38b3
movl %r14d, %edi
callq 0x465a
movl $0x0, 0x85f5(%rip)      # 0xbea8
movq 0x85f1(%rip), %xmm0     # 0xbeac
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x85e1(%rip)     # 0xbeac
leaq 0x83ce(%rip), %rax      # 0xbca0
movl (%rax,%r12,4), %eax
cmpl $0x7, %eax
je 0x38e0
cmpl $0x1, %eax
jne 0x3918
movl $0x0, 0x85be(%rip)      # 0xbea8
btl $0x13, %ebp
jae 0x3918
leal -0xa(%r15), %eax
leal 0xa(%r15), %ecx
testl %ebx, %ebx
cmovnel %eax, %ecx
movl %ecx, 0x85a1(%rip)      # 0xbea4
movslq %ecx, %rax
leaq 0x20793(%rip), %rcx     # 0x240a0
movq (%rcx,%rax,8), %rax
xorq %rax, 0x85a8(%rip)      # 0xbec0
movl %r15d, %edi
movl %r14d, %esi
callq 0x4739
shrl $0x14, %ebp
andl $0xf, %ebp
je 0x393d
movl %r14d, %edi
callq 0x465a
movl %r14d, %edi
movl %ebp, %esi
callq 0x4819
leaq 0x835c(%rip), %rdx      # 0xbca0
movl (%rdx,%r13,4), %eax
cmpl $0xc, %eax
je 0x3952
cmpl $0x6, %eax
jne 0x3961
movslq 0x8547(%rip), %rax      # 0xbea0
movl %r14d, 0x1f8(%rdx,%rax,4)
movl 0x8539(%rip), %esi      # 0xbea0
xorl $0x1, %esi
movl %esi, 0x8530(%rip)      # 0xbea0
movq 0x237e9(%rip), %rax     # 0x27160
xorq %rax, 0x8542(%rip)      # 0xbec0
movl 0x1f8(%rdx,%rbx,4), %edi
callq 0x1543
testl %eax, %eax
je 0x3997
callq 0x48bd
xorl %eax, %eax
jmp 0x399c
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq