// File: /workspace/github_cpp_makefile_star2_O1/cpirc[P]Monochrome/src/move.cpp
// Function: lan_to_move(Position const&, char const*, unsigned int&)
bool lan_to_move(const Position& pos, const char* lan_str, Move& move) {
    assert(lan_str);

    Square from = (Square)((lan_str[0] - 'a') + ((lan_str[1] - '1') * 8)),
           to = (Square)((lan_str[2] - 'a') + ((lan_str[3] - '1') * 8));
    Piece promo = NO_PIECE;

    switch (lan_str[4]) {
        case '\0':
            break;
        case 'n':
            promo = KNIGHT;
            break;
        case 'b':
            promo = BISHOP;
            break;
        case 'r':
            promo = ROOK;
            break;
        case 'q':
            promo = QUEEN;
            break;
        default:
            break;
    }

    SearchStack ss[1];
    clear_ss(ss, 1);

    int movecount;
    movecount = generate(pos, ss->ml);

    Move current_move;
    while ((current_move = next_move(ss, movecount))) {
        if (pos.flipped) {
            current_move = flip_move(current_move);
        }

        if (from_square(current_move) == from &&
            to_square(current_move) == to) {
            // FIX ME: This is very ugly
            if (promo != NO_PIECE && promotion_type(current_move) != promo) {
                continue;
            }
            move = current_move;
            return true;
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x838, %rsp            # imm = 0x838
testq %rsi, %rsi
je 0x5137
movq %rdx, %r12
movq %rdi, %r14
movb 0x1(%rsi), %r13b
movb 0x3(%rsi), %bl
shlb $0x3, %r13b
shlb $0x3, %bl
movzbl 0x4(%rsi), %eax
movl $0x6, -0x2c(%rbp)
movb $0x1, %cl
movl %ecx, -0x30(%rbp)
cmpl $0x70, %eax
jg 0x504f
cmpl $0x62, %eax
je 0x5062
cmpl $0x6e, %eax
jne 0x5079
movl $0x1, -0x2c(%rbp)
jmp 0x5072
cmpl $0x71, %eax
je 0x506b
cmpl $0x72, %eax
jne 0x5079
movl $0x3, -0x2c(%rbp)
jmp 0x5072
movl $0x2, -0x2c(%rbp)
jmp 0x5072
movl $0x4, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
addb (%rsi), %r13b
addb 0x2(%rsi), %bl
leaq -0x860(%rbp), %r15
movq %r15, %rdi
movl $0x1, %esi
callq 0x7ed9
leaq -0x85c(%rbp), %rsi
movq %r14, %rdi
callq 0x608e
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x7b5f
movl %eax, %ecx
testl %eax, %eax
setne %al
je 0x5123
movq %r12, -0x40(%rbp)
addb $0x17, %r13b
addb $0x17, %bl
leaq -0x34(%rbp), %r12
movl %ecx, %edx
andl $0x3ffff, %edx          # imm = 0x3FFFF
xorl $0xe38, %edx            # imm = 0xE38
cmpb $0x0, 0x41(%r14)
cmovel %ecx, %edx
movl %edx, %ecx
andb $0x3f, %cl
cmpb %r13b, %cl
jne 0x5107
movl %edx, %ecx
shrl $0x6, %ecx
andb $0x3f, %cl
cmpb %bl, %cl
jne 0x5107
cmpb $0x0, -0x30(%rbp)
jne 0x511d
movl %edx, %ecx
shrl $0xf, %ecx
andl $0x7, %ecx
cmpl %ecx, -0x2c(%rbp)
je 0x511d
movq %r15, %rdi
movq %r12, %rsi
callq 0x7b5f
movl %eax, %ecx
testl %eax, %eax
setne %al
jne 0x50c8
jmp 0x5123
movq -0x40(%rbp), %rcx
movl %edx, (%rcx)
andb $0x1, %al
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7752(%rip), %rdi      # 0xc890
leaq 0x7753(%rip), %rsi      # 0xc898
leaq 0x777e(%rip), %rcx      # 0xc8ca
movl $0xaa, %edx
callq 0x3100