// File: /workspace/github_c_makefile_star2_O3/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 0x87b2(%rip), %rbx      # 0xbea0
leaq 0x85ab(%rip), %r13      # 0xbca0
movq 0x87c4(%rip), %rax      # 0xbec0
movslq 0x87ad(%rip), %rcx      # 0xbeb0
leaq (%rcx,%rcx,2), %rcx
movq %rax, 0x280(%r13,%rcx,8)
btl $0x12, %edi
jb 0x3747
btl $0x18, %ebp
jae 0x37ad
cmpl $0x5c, %r14d
jg 0x375c
cmpl $0x17, %r14d
je 0x377e
cmpl $0x1b, %r14d
jne 0x37ad
movl $0x1, 0x877d(%rip)      # 0xbeb8
movl $0x1c, %edi
movl $0x1a, %esi
jmp 0x37a8
testl %ebx, %ebx
je 0x3751
leal 0xa(%r14), %edi
jmp 0x3755
leal -0xa(%r14), %edi
callq 0x462d
jmp 0x37ad
cmpl $0x5d, %r14d
je 0x3794
cmpl $0x61, %r14d
jne 0x37ad
movl $0x1, 0x874a(%rip)      # 0xbebc
movl $0x62, %edi
movl $0x60, %esi
jmp 0x37a8
movl $0x1, 0x8730(%rip)      # 0xbeb8
movl $0x15, %edi
movl $0x18, %esi
jmp 0x37a8
movl $0x1, 0x871e(%rip)      # 0xbebc
movl $0x5b, %edi
movl $0x5e, %esi
callq 0x470c
movl %ebp, %r15d
andl $0x7f, %r15d
movslq 0x86e9(%rip), %rdx      # 0xbea4
movq 0x86fe(%rip), %rax      # 0xbec0
cmpq $0x63, %rdx
je 0x37d3
leaq 0x208d1(%rip), %rcx     # 0x240a0
xorq (%rcx,%rdx,8), %rax
movslq 0x86da(%rip), %rsi      # 0xbeb4
leaq 0x2083f(%rip), %rdi     # 0x24020
xorq (%rdi,%rsi,8), %rax
movslq 0x86c4(%rip), %rcx      # 0xbeb0
leaq (%rcx,%rcx,2), %r8
movl %ebp, 0x270(%r13,%r8,8)
movl 0x86a9(%rip), %r9d      # 0xbea8
movl %r9d, 0x27c(%r13,%r8,8)
movl %edx, 0x278(%r13,%r8,8)
movl %esi, 0x274(%r13,%r8,8)
movl %r15d, %r12d
leaq 0x3ccf(%rip), %rdx      # 0x74f0
movl (%rdx,%r12,4), %r8d
movl %r14d, %r13d
andl (%rdx,%r13,4), %r8d
andl %esi, %r8d
movl %r8d, 0x867e(%rip)      # 0xbeb4
movl $0x63, 0x8664(%rip)     # 0xbea4
movslq %r8d, %rdx
xorq (%rdi,%rdx,8), %rax
movq %rax, 0x8672(%rip)      # 0xbec0
incl %r9d
movl %r9d, 0x8650(%rip)      # 0xbea8
testl $0x3c000, %ebp          # imm = 0x3C000
je 0x3878
movl %r14d, %edi
callq 0x462d
movl $0x0, 0x8636(%rip)      # 0xbea8
movl 0x8638(%rip), %ecx      # 0xbeb0
incl %ecx
movl %ecx, 0x8630(%rip)      # 0xbeb0
incl 0x8626(%rip)            # 0xbeac
leaq 0x8413(%rip), %rax      # 0xbca0
movl (%rax,%r12,4), %eax
cmpl $0x7, %eax
je 0x389b
cmpl $0x1, %eax
jne 0x38d3
movl $0x0, 0x8603(%rip)      # 0xbea8
btl $0x13, %ebp
jae 0x38d3
leal -0xa(%r15), %eax
leal 0xa(%r15), %ecx
testl %ebx, %ebx
cmovnel %eax, %ecx
movl %ecx, 0x85e6(%rip)      # 0xbea4
movslq %ecx, %rax
leaq 0x207d8(%rip), %rcx     # 0x240a0
movq (%rcx,%rax,8), %rax
xorq %rax, 0x85ed(%rip)      # 0xbec0
movl %r15d, %edi
movl %r14d, %esi
callq 0x470c
shrl $0x14, %ebp
andl $0xf, %ebp
je 0x38f8
movl %r14d, %edi
callq 0x462d
movl %r14d, %edi
movl %ebp, %esi
callq 0x47e5
leaq 0x83a1(%rip), %rdx      # 0xbca0
movl (%rdx,%r13,4), %eax
cmpl $0xc, %eax
je 0x390d
cmpl $0x6, %eax
jne 0x391c
movslq 0x858c(%rip), %rax      # 0xbea0
movl %r14d, 0x1f8(%rdx,%rax,4)
movl 0x857e(%rip), %esi      # 0xbea0
xorl $0x1, %esi
movl %esi, 0x8575(%rip)      # 0xbea0
movq 0x2382e(%rip), %rax     # 0x27160
xorq %rax, 0x8587(%rip)      # 0xbec0
movl 0x1f8(%rdx,%rbx,4), %edi
callq 0x1547
testl %eax, %eax
je 0x3952
callq 0x4889
xorl %eax, %eax
jmp 0x3957
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq