// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movl 0x24(%rsp), %eax
andl $0x7f, %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
sarl $0x7, %eax
andl $0x7f, %eax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movl 0x200(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq 0x220(%rax), %rcx
movq 0x28(%rsp), %rax
addq $0x270, %rax            # imm = 0x270
movq 0x28(%rsp), %rdx
movslq 0x210(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movl 0x24(%rsp), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x3cc1
cmpl $0x0, 0x18(%rsp)
je 0x3cab
movl 0x1c(%rsp), %edi
addl $0xa, %edi
movq 0x28(%rsp), %rsi
callq 0x5540
jmp 0x3cbc
movl 0x1c(%rsp), %edi
subl $0xa, %edi
movq 0x28(%rsp), %rsi
callq 0x5540
jmp 0x3da0
movl 0x24(%rsp), %eax
andl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x0, %eax
je 0x3d9e
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0x17, %eax
je 0x3d06
jmp 0x3ce2
movl 0xc(%rsp), %eax
subl $0x1b, %eax
je 0x3d50
jmp 0x3ced
movl 0xc(%rsp), %eax
subl $0x5d, %eax
je 0x3d2b
jmp 0x3cf8
movl 0xc(%rsp), %eax
subl $0x61, %eax
je 0x3d75
jmp 0x3d9a
movq 0x28(%rsp), %rax
movl $0x1, 0x218(%rax)
movq 0x28(%rsp), %rdx
movl $0x15, %edi
movl $0x18, %esi
callq 0x5740
jmp 0x3d9c
movq 0x28(%rsp), %rax
movl $0x1, 0x21c(%rax)
movq 0x28(%rsp), %rdx
movl $0x5b, %edi
movl $0x5e, %esi
callq 0x5740
jmp 0x3d9c
movq 0x28(%rsp), %rax
movl $0x1, 0x218(%rax)
movq 0x28(%rsp), %rdx
movl $0x1c, %edi
movl $0x1a, %esi
callq 0x5740
jmp 0x3d9c
movq 0x28(%rsp), %rax
movl $0x1, 0x21c(%rax)
movq 0x28(%rsp), %rdx
movl $0x62, %edi
movl $0x60, %esi
callq 0x5740
jmp 0x3d9c
jmp 0x3d9c
jmp 0x3d9e
jmp 0x3da0
movq 0x28(%rsp), %rax
cmpl $0x63, 0x204(%rax)
je 0x3dd8
movq 0x28(%rsp), %rax
movslq 0x204(%rax), %rcx
leaq 0x242cf(%rip), %rax     # 0x28090
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
xorq 0x220(%rax), %rcx
movq %rcx, 0x220(%rax)
movq 0x28(%rsp), %rax
movslq 0x214(%rax), %rcx
leaq 0x24225(%rip), %rax     # 0x28010
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
xorq 0x220(%rax), %rcx
movq %rcx, 0x220(%rax)
movl 0x24(%rsp), %ecx
movq 0x28(%rsp), %rax
addq $0x270, %rax            # imm = 0x270
movq 0x28(%rsp), %rdx
movslq 0x210(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq 0x28(%rsp), %rax
movl 0x208(%rax), %ecx
movq 0x28(%rsp), %rax
addq $0x270, %rax            # imm = 0x270
movq 0x28(%rsp), %rdx
movslq 0x210(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq 0x28(%rsp), %rax
movl 0x204(%rax), %ecx
movq 0x28(%rsp), %rax
addq $0x270, %rax            # imm = 0x270
movq 0x28(%rsp), %rdx
movslq 0x210(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq 0x28(%rsp), %rax
movl 0x214(%rax), %ecx
movq 0x28(%rsp), %rax
addq $0x270, %rax            # imm = 0x270
movq 0x28(%rsp), %rdx
movslq 0x210(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movslq 0x20(%rsp), %rcx
leaq 0x762a(%rip), %rax      # 0xb4e0
movl (%rax,%rcx,4), %ecx
movq 0x28(%rsp), %rax
andl 0x214(%rax), %ecx
movl %ecx, 0x214(%rax)
movslq 0x1c(%rsp), %rcx
leaq 0x760a(%rip), %rax      # 0xb4e0
movl (%rax,%rcx,4), %ecx
movq 0x28(%rsp), %rax
andl 0x214(%rax), %ecx
movl %ecx, 0x214(%rax)
movq 0x28(%rsp), %rax
movl $0x63, 0x204(%rax)
movq 0x28(%rsp), %rax
movslq 0x214(%rax), %rcx
leaq 0x24104(%rip), %rax     # 0x28010
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
xorq 0x220(%rax), %rcx
movq %rcx, 0x220(%rax)
movl 0x24(%rsp), %eax
sarl $0xe, %eax
andl $0xf, %eax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rax
movl 0x208(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x208(%rax)
cmpl $0x0, 0x14(%rsp)
je 0x3f69
movl 0x1c(%rsp), %edi
movq 0x28(%rsp), %rsi
callq 0x5540
movq 0x28(%rsp), %rax
movl $0x0, 0x208(%rax)
movq 0x28(%rsp), %rax
movl 0x210(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x210(%rax)
movq 0x28(%rsp), %rax
movl 0x20c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20c(%rax)
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x79ea(%rip), %rax      # 0xb990
cmpl $0x0, (%rax,%rcx,4)
je 0x4022
movq 0x28(%rsp), %rax
movl $0x0, 0x208(%rax)
movl 0x24(%rsp), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x4020
cmpl $0x0, 0x18(%rsp)
jne 0x3fe4
movl 0x20(%rsp), %ecx
addl $0xa, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x204(%rax)
jmp 0x3ff6
movl 0x20(%rsp), %ecx
subl $0xa, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x204(%rax)
movq 0x28(%rsp), %rax
movslq 0x204(%rax), %rcx
leaq 0x24087(%rip), %rax     # 0x28090
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
xorq 0x220(%rax), %rcx
movq %rcx, 0x220(%rax)
jmp 0x4022
movl 0x20(%rsp), %edi
movl 0x1c(%rsp), %esi
movq 0x28(%rsp), %rdx
callq 0x5740
movl 0x24(%rsp), %eax
sarl $0x14, %eax
andl $0xf, %eax
movl %eax, 0x10(%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x4069
movl 0x1c(%rsp), %edi
movq 0x28(%rsp), %rsi
callq 0x5540
movl 0x1c(%rsp), %edi
movq 0x28(%rsp), %rsi
movl 0x10(%rsp), %edx
callq 0x5970
movq 0x28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x79d2(%rip), %rax      # 0xba50
cmpl $0x0, (%rax,%rcx,4)
je 0x40a0
movl 0x1c(%rsp), %edx
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movslq 0x200(%rcx), %rcx
movl %edx, 0x1f8(%rax,%rcx,4)
movq 0x28(%rsp), %rax
movl 0x200(%rax), %ecx
xorl $0x1, %ecx
movl %ecx, 0x200(%rax)
movq 0x27095(%rip), %rcx     # 0x2b150
movq 0x28(%rsp), %rax
xorq 0x220(%rax), %rcx
movq %rcx, 0x220(%rax)
movq 0x28(%rsp), %rax
movslq 0x18(%rsp), %rcx
movl 0x1f8(%rax,%rcx,4), %edi
movq 0x28(%rsp), %rax
movl 0x200(%rax), %esi
movq 0x28(%rsp), %rdx
callq 0x1750
cmpl $0x0, %eax
je 0x410d
movq 0x28(%rsp), %rdi
callq 0x5ad0
movl $0x0, 0x34(%rsp)
jmp 0x4115
movl $0x1, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nop