// File: niekh1234[P]nnchesslib/board.cpp
// Function: nnchesslib::ChessBoard::fromUci(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Move ChessBoard::fromUci(std::string move)
{
    assert(move.size() <= 5);

    int from = getSquareInt(move.substr(0,2));
    int to = getSquareInt(move.substr(2,2));

    // promotion ("e7e8q"), these moves are different because they have a size of 5
    if(move.size() == 5)
    {
        char promotedTo = move.back();

        switch(promotedTo)
        {
            case 'q':
                return createMove(from, to, QUEEN);
                break;
            case 'n':
                return createMove(from, to, KNIGHT);
                break;
            case 'b':
                return createMove(from, to, BISHOP);
                break;
            case 'r':
                return createMove(from, to, ROOK);
                break;
        }
    }
    // castling moves: check if the move is on the castling squares and if the king is moved.
    if(from == E1 && to == G1 && (getPieceOnSquare(from)->board & boardinfo.kings.board)) return createMove(from, to, CASTLING);
    else if(from == E1 && to == C1 && (getPieceOnSquare(from)->board & boardinfo.kings.board)) return createMove(from, to, CASTLING);
    else if(from == E8 && to == G8 && (getPieceOnSquare(from)->board & boardinfo.kings.board)) return createMove(from, to, CASTLING);
    else if(from == E8 && to == C8 && (getPieceOnSquare(from)->board & boardinfo.kings.board)) return createMove(from, to, CASTLING);

    // en passant moves
    if(boardinfo.blackEnPassantTarget.get(to) && getBoard(BLACK, PAWN).get(from)) return createMove(from, to, ENPASSANT);
    else if(boardinfo.whiteEnPassantTarget.get(to) && getBoard(WHITE, PAWN).get(from)) return createMove(from, to, ENPASSANT);

    // normal move
    return createMove(from, to, NORMAL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rsi, -0xa0(%rbp)
movq %rdi, %rax
movq -0xa0(%rbp), %rdi
movq %rdi, -0x98(%rbp)
movq %rax, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x3180
cmpq $0x5, %rax
ja 0x9473
jmp 0x9492
leaq 0x5544(%rip), %rdi      # 0xe9be
leaq 0x514e(%rip), %rsi      # 0xe5cf
movl $0x290, %edx            # imm = 0x290
leaq 0x5542(%rip), %rcx      # 0xe9cf
callq 0x3150
movq -0x98(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
movl $0x2, %ecx
callq 0x3280
movq -0xb0(%rbp), %rdi
callq 0xd820
movl %eax, -0xa4(%rbp)
jmp 0x94c6
leaq -0x40(%rbp), %rdi
callq 0x34a8
movl -0xa4(%rbp), %eax
movq -0x98(%rbp), %rsi
movl %eax, -0x1c(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
movl $0x2, %ecx
movq %rcx, %rdx
callq 0x3280
movq -0xc0(%rbp), %rdi
callq 0xd820
movl %eax, -0xb4(%rbp)
jmp 0x950b
leaq -0x70(%rbp), %rdi
callq 0x34a8
movl -0xb4(%rbp), %eax
movq -0x98(%rbp), %rdi
movl %eax, -0x50(%rbp)
callq 0x3180
cmpq $0x5, %rax
jne 0x960a
movq -0x98(%rbp), %rdi
callq 0x31a0
movb (%rax), %al
movb %al, -0x71(%rbp)
movsbl -0x71(%rbp), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0xc8(%rbp)
subl $0x10, %eax
ja 0x9608
movq -0xc8(%rbp), %rax
leaq 0x5279(%rip), %rcx      # 0xe7e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x34a8
jmp 0x9834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x34a8
jmp 0x9834
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x4, %edx
callq 0xaad0
movl %eax, -0x4(%rbp)
jmp 0x9828
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x1, %edx
callq 0xaad0
movl %eax, -0x4(%rbp)
jmp 0x9828
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x2, %edx
callq 0xaad0
movl %eax, -0x4(%rbp)
jmp 0x9828
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x3, %edx
callq 0xaad0
movl %eax, -0x4(%rbp)
jmp 0x9828
jmp 0x960a
cmpl $0x4, -0x1c(%rbp)
jne 0x9651
cmpl $0x6, -0x50(%rbp)
jne 0x9651
movq -0x90(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7920
movq -0x90(%rbp), %rcx
movq (%rax), %rax
andq 0x38(%rcx), %rax
cmpq $0x0, %rax
je 0x9651
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
cmpl $0x4, -0x1c(%rbp)
jne 0x9698
cmpl $0x2, -0x50(%rbp)
jne 0x9698
movq -0x90(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7920
movq -0x90(%rbp), %rcx
movq (%rax), %rax
andq 0x38(%rcx), %rax
cmpq $0x0, %rax
je 0x9698
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
cmpl $0x3c, -0x1c(%rbp)
jne 0x96df
cmpl $0x3e, -0x50(%rbp)
jne 0x96df
movq -0x90(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7920
movq -0x90(%rbp), %rcx
movq (%rax), %rax
andq 0x38(%rcx), %rax
cmpq $0x0, %rax
je 0x96df
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
cmpl $0x3c, -0x1c(%rbp)
jne 0x9726
cmpl $0x3a, -0x50(%rbp)
jne 0x9726
movq -0x90(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x7920
movq -0x90(%rbp), %rcx
movq (%rax), %rax
andq 0x38(%rcx), %rax
cmpq $0x0, %rax
je 0x9726
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
jmp 0x9728
jmp 0x972a
jmp 0x972c
movq -0x90(%rbp), %rdi
addq $0x60, %rdi
movl -0x50(%rbp), %esi
callq 0x4ce0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xc9(%rbp)
je 0x977a
movq -0x90(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x76f0
movq %rax, -0x80(%rbp)
movl -0x1c(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x4ce0
cmpl $0x0, %eax
setne %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x9786
jmp 0x979e
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x2, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
movq -0x90(%rbp), %rdi
addq $0x58, %rdi
movl -0x50(%rbp), %esi
callq 0x4ce0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xca(%rbp)
je 0x97f5
movq -0x90(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x76f0
movq %rax, -0x88(%rbp)
movl -0x1c(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x4ce0
cmpl $0x0, %eax
setne %al
movb %al, -0xca(%rbp)
movb -0xca(%rbp), %al
testb $0x1, %al
jne 0x9801
jmp 0x9816
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
movl $0x2, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
jmp 0x9828
jmp 0x9818
movl -0x1c(%rbp), %edi
movl -0x50(%rbp), %esi
xorl %edx, %edx
callq 0xab00
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3410
nopl (%rax)