// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpq $0x6, 0x8(%rsi)
jae 0x55af
movq %rsi, %r12
movq %rdi, %r15
leaq -0x70(%rbp), %r13
pushq $0x2
popq %rcx
movq %r13, %rdi
xorl %edx, %edx
callq 0x21b0
movq %r13, %rdi
callq 0x757a
movl %eax, %ebx
leaq -0x70(%rbp), %rdi
callq 0x2308
leaq -0x50(%rbp), %r13
pushq $0x2
popq %rcx
movq %r13, %rdi
movq %r12, %rsi
movq %rcx, %rdx
callq 0x21b0
movq %r13, %rdi
callq 0x757a
movl %eax, %r14d
leaq -0x50(%rbp), %rdi
callq 0x2308
cmpq $0x5, 0x8(%r12)
jne 0x546a
movq (%r12), %rax
movzbl 0x4(%rax), %eax
cmpl $0x62, %eax
je 0x54f2
cmpl $0x6e, %eax
je 0x54ea
cmpl $0x71, %eax
je 0x54ee
cmpl $0x72, %eax
jne 0x546a
pushq $0x3
jmp 0x54f4
movl %ebx, %eax
xorl $0x4, %eax
movl %r14d, %ecx
xorl $0x6, %ecx
orl %eax, %ecx
jne 0x549b
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x4488
movq 0x38(%r15), %rcx
testq %rcx, (%rax)
je 0x552d
pushq $0x4
popq %rdi
pushq $0x6
jmp 0x5527
movl %r14d, %ecx
xorl $0x2, %ecx
orl %ecx, %eax
jne 0x54c0
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x4488
movq 0x38(%r15), %rcx
testq %rcx, (%rax)
je 0x552d
pushq $0x4
popq %rdi
pushq $0x2
jmp 0x5527
movl %ebx, %eax
xorl $0x3c, %eax
movl %r14d, %ecx
xorl $0x3e, %ecx
orl %eax, %ecx
jne 0x5504
pushq $0x3c
popq %rsi
movq %r15, %rdi
callq 0x4488
movq 0x38(%r15), %rcx
testq %rcx, (%rax)
je 0x552d
pushq $0x3c
popq %rdi
pushq $0x3e
jmp 0x5527
pushq $0x1
jmp 0x54f4
pushq $0x4
jmp 0x54f4
pushq $0x2
popq %rdx
movl %ebx, %edi
movl %r14d, %esi
callq 0x5c16
jmp 0x55a0
movl %r14d, %ecx
xorl $0x3a, %ecx
orl %ecx, %eax
jne 0x552d
pushq $0x3c
popq %rsi
movq %r15, %rdi
callq 0x4488
movq 0x38(%r15), %rcx
testq %rcx, (%rax)
je 0x552d
pushq $0x3c
popq %rdi
pushq $0x3a
popq %rsi
pushq $0x3
popq %rdx
jmp 0x559b
leaq 0x60(%r15), %rdi
movl %r14d, %esi
callq 0x30a4
testl %eax, %eax
je 0x555b
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4388
leaq -0x30(%rbp), %rdi
movq %rax, (%rdi)
movl %ebx, %esi
callq 0x30a4
testl %eax, %eax
jne 0x558a
leaq 0x58(%r15), %rdi
movl %r14d, %esi
callq 0x30a4
testl %eax, %eax
je 0x5594
pushq $0x1
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x4388
leaq -0x30(%rbp), %rdi
movq %rax, (%rdi)
movl %ebx, %esi
callq 0x30a4
testl %eax, %eax
je 0x5594
pushq $0x2
popq %rdx
movl %ebx, %edi
movl %r14d, %esi
jmp 0x559b
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x5c2c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x32a8(%rip), %rdi      # 0x885e
leaq 0x2f92(%rip), %rsi      # 0x854f
leaq 0x32ab(%rip), %rcx      # 0x886f
movl $0x290, %edx            # imm = 0x290
callq 0x2100
jmp 0x55d0
movq %rax, %rbx
movq %r13, %rdi
callq 0x2308
movq %rbx, %rdi
callq 0x2290
nop