// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
cmpq $0x6, 0x8(%rsi)
jae 0x64e0
movq %rsi, %r12
movq %rdi, %r14
leaq -0x68(%rbp), %rbx
movl $0x2, %ecx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2160
movq %rbx, %rdi
callq 0x876e
movl %eax, %ebx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62e2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2150
leaq -0x48(%rbp), %r15
movl $0x2, %edx
movl $0x2, %ecx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2160
movq %r15, %rdi
callq 0x876e
movl %eax, %r15d
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x631f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2150
cmpq $0x5, 0x8(%r12)
jne 0x636e
movq (%r12), %rax
movzbl 0x4(%rax), %eax
cmpl $0x70, %eax
jg 0x6351
cmpl $0x62, %eax
je 0x6407
cmpl $0x6e, %eax
jne 0x636e
movl %ebx, %edi
movl %r15d, %esi
movl $0x1, %edx
jmp 0x641d
cmpl $0x71, %eax
je 0x6413
cmpl $0x72, %eax
jne 0x636e
movl %ebx, %edi
movl %r15d, %esi
movl $0x3, %edx
jmp 0x641d
movl %ebx, %eax
xorl $0x4, %eax
movl %r15d, %ecx
xorl $0x6, %ecx
orl %eax, %ecx
jne 0x63a6
movq %r14, %rdi
movl $0x4, %esi
callq 0x4eae
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x6458
movl $0x4, %edi
movl $0x6, %esi
jmp 0x6451
movl %r15d, %ecx
xorl $0x2, %ecx
orl %ecx, %eax
jne 0x63d6
movq %r14, %rdi
movl $0x4, %esi
callq 0x4eae
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x6458
movl $0x4, %edi
movl $0x2, %esi
jmp 0x6451
movl %ebx, %eax
xorl $0x3c, %eax
movl %r15d, %ecx
xorl $0x3e, %ecx
orl %eax, %ecx
jne 0x6427
movq %r14, %rdi
movl $0x3c, %esi
callq 0x4eae
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x6458
movl $0x3c, %edi
movl $0x3e, %esi
jmp 0x6451
movl %ebx, %edi
movl %r15d, %esi
movl $0x2, %edx
jmp 0x641d
movl %ebx, %edi
movl %r15d, %esi
movl $0x4, %edx
callq 0x6a9a
jmp 0x64d3
movl %r15d, %ecx
xorl $0x3a, %ecx
orl %ecx, %eax
jne 0x6458
movq %r14, %rdi
movl $0x3c, %esi
callq 0x4eae
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x6458
movl $0x3c, %edi
movl $0x3a, %esi
movl $0x3, %edx
jmp 0x64ce
leaq 0x60(%r14), %rdi
movl %r15d, %esi
callq 0x33f8
testl %eax, %eax
je 0x648a
movq 0x10(%r14), %rsi
andq 0x8(%r14), %rsi
leaq -0x28(%rbp), %r12
movq %r12, %rdi
callq 0x3386
movq %r12, %rdi
movl %ebx, %esi
callq 0x33f8
testl %eax, %eax
jne 0x64bb
leaq 0x58(%r14), %rdi
movl %r15d, %esi
callq 0x33f8
testl %eax, %eax
je 0x64c7
movq 0x10(%r14), %rsi
andq (%r14), %rsi
leaq -0x28(%rbp), %r14
movq %r14, %rdi
callq 0x3386
movq %r14, %rdi
movl %ebx, %esi
callq 0x33f8
testl %eax, %eax
je 0x64c7
movl %ebx, %edi
movl %r15d, %esi
movl $0x2, %edx
jmp 0x64ce
movl %ebx, %edi
movl %r15d, %esi
xorl %edx, %edx
callq 0x6ab0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3357(%rip), %rdi      # 0x983e
leaq 0x3041(%rip), %rsi      # 0x952f
leaq 0x335a(%rip), %rcx      # 0x984f
movl $0x290, %edx            # imm = 0x290
callq 0x20c0
movq %rax, %rbx
leaq -0x38(%rbp), %rax
jmp 0x650f
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6523
movq (%rax), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2270
nop