// File: /workspace/github_cpp_makefile_star2_O1/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 0x64ea
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 0x87ea
movl %eax, %ebx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62f8
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 0x87ea
movl %eax, %r15d
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6335
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2150
movq 0x8(%r12), %rax
cmpq $0x5, %rax
jne 0x6392
movq (%r12), %rcx
movzbl -0x1(%rcx,%rax), %edx
movb $0x1, %cl
cmpl $0x70, %edx
jg 0x6361
cmpl $0x62, %edx
je 0x6372
cmpl $0x6e, %edx
jne 0x638a
movl $0x1, %edx
jmp 0x637e
cmpl $0x71, %edx
je 0x6379
cmpl $0x72, %edx
jne 0x638a
movl $0x3, %edx
jmp 0x637e
movl $0x2, %edx
jmp 0x637e
movl $0x4, %edx
movl %ebx, %edi
movl %r15d, %esi
callq 0x6a96
xorl %ecx, %ecx
testb %cl, %cl
je 0x645f
movl %ebx, %r12d
xorl $0x4, %r12d
movl %r15d, %eax
xorl $0x6, %eax
orl %r12d, %eax
jne 0x63c9
movq %r14, %rdi
movl $0x4, %esi
callq 0x4e9a
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x63c9
movl $0x4, %edi
movl $0x6, %esi
jmp 0x6455
movl %r15d, %eax
xorl $0x2, %eax
orl %eax, %r12d
jne 0x63f6
movq %r14, %rdi
movl $0x4, %esi
callq 0x4e9a
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x63f6
movl $0x4, %edi
movl $0x2, %esi
jmp 0x6455
movl %ebx, %r12d
xorl $0x3c, %r12d
movl %r15d, %eax
xorl $0x3e, %eax
orl %r12d, %eax
jne 0x642a
movq %r14, %rdi
movl $0x3c, %esi
callq 0x4e9a
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x642a
movl $0x3c, %edi
movl $0x3e, %esi
jmp 0x6455
movl %r15d, %eax
xorl $0x3a, %eax
orl %eax, %r12d
jne 0x646c
movq %r14, %rdi
movl $0x3c, %esi
callq 0x4e9a
movq 0x38(%r14), %rcx
testq %rcx, (%rax)
je 0x646c
movl $0x3c, %edi
movl $0x3a, %esi
movl $0x3, %edx
callq 0x6aac
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%r14), %rdi
movl %r15d, %esi
callq 0x33bc
testl %eax, %eax
je 0x649e
movq 0x10(%r14), %rsi
andq 0x8(%r14), %rsi
leaq -0x28(%rbp), %r12
movq %r12, %rdi
callq 0x334a
movq %r12, %rdi
movl %ebx, %esi
callq 0x33bc
testl %eax, %eax
jne 0x64cf
leaq 0x58(%r14), %rdi
movl %r15d, %esi
callq 0x33bc
testl %eax, %eax
je 0x64de
movq 0x10(%r14), %rsi
andq (%r14), %rsi
leaq -0x28(%rbp), %r14
movq %r14, %rdi
callq 0x334a
movq %r14, %rdi
movl %ebx, %esi
callq 0x33bc
testl %eax, %eax
je 0x64de
movl %ebx, %edi
movl %r15d, %esi
movl $0x2, %edx
jmp 0x645a
movl %ebx, %edi
movl %r15d, %esi
xorl %edx, %edx
jmp 0x645a
leaq 0x334d(%rip), %rdi      # 0x983e
leaq 0x3037(%rip), %rsi      # 0x952f
leaq 0x3350(%rip), %rcx      # 0x984f
movl $0x290, %edx            # imm = 0x290
callq 0x20c0
movq %rax, %rbx
leaq -0x38(%rbp), %rax
jmp 0x6519
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x652d
movq (%rax), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2270
nop