// File: /workspace/github_cpp_makefile_star2_O2/jswaff[P]prophet3/src/xboard.cpp
// Function: handle_usermove()
void handle_usermove() {
    char mv_text[MAX_CHARS_PER_MOVE];
    if (scanf("%s",mv_text) == EOF) return;
    move mv = str_to_move(mv_text,&gpos);
    if (mv==BADMOVE) {
        print("Illegal move: %s\n",mv_text);
    } else {
        char mv_buffer[MAX_CHARS_PER_MOVE];
        move_to_str(mv,mv_buffer);
        apply_move(&gpos,mv,gundos);

        if (!force_mode) {

            // we might be in a ponder search
            extern pthread_mutex_t ponder_mutex;
            pthread_mutex_lock(&ponder_mutex);
            printd("# handle_usermove acquired lock on ponder_mutex\n");

            bool pondering = is_pondering();
            bool predicted = pondering && (mv == get_ponder_move());
            printd("# pondering?: %s, predicted?: %s\n",(pondering?"true":"false"),(predicted?"true":"false"));

            // if we are pondering and have correctly predicted the opponent's move, we just transition into
            // a regular search by setting the search time limit and setting ponder=false.
            bool start_new_search;
            if (pondering && predicted) {
                calculate_search_times();
                set_ponder_mode(false);
                start_new_search = false;
            } else {
                set_abort_iterator(true);
                start_new_search = true;
            }

            pthread_mutex_unlock(&ponder_mutex);
            printd("# handle_usermove released lock on ponder_mutex\n");

            if (start_new_search) {
                pthread_join(think_thread,NULL);
                think_and_make_move();
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x18, %rsp
leaq 0x1c13f(%rip), %rdi     # 0x2a684
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x2190
cmpl $-0x1, %eax
je 0xe682
leaq 0xbd3bf(%rip), %rsi     # 0xcb920
leaq 0x4(%rsp), %rdi
callq 0xd66a
testq %rax, %rax
je 0xe5e7
movq %rax, %rbx
leaq 0xe(%rsp), %rsi
movq %rax, %rdi
callq 0xd5f6
leaq 0xbd399(%rip), %rdi     # 0xcb920
leaq 0xbd562(%rip), %rdx     # 0xcbaf0
movq %rbx, %rsi
callq 0x2fa5
cmpb $0x0, 0x36c13(%rip)     # 0x451b0
jne 0xe682
leaq 0x871596(%rip), %rdi    # 0x87fb40
callq 0x2290
leaq 0x1cd22(%rip), %rdi     # 0x2b2d8
xorl %eax, %eax
callq 0x60fd
callq 0xc908
movl %eax, %ebp
testb %al, %al
je 0xe5ff
callq 0xc90f
cmpq %rax, %rbx
setne %bl
leaq 0x1cd56(%rip), %rdx     # 0x2b330
leaq 0x1cd4a(%rip), %rsi     # 0x2b32b
cmoveq %rsi, %rdx
jmp 0xe60b
leaq 0x1ccd8(%rip), %rdi     # 0x2b2c6
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x5fdd
jmp 0xe682
leaq 0x1cd2a(%rip), %rsi     # 0x2b330
movb $0x1, %bl
movq %rsi, %rdx
leaq 0x1ccf7(%rip), %rdi     # 0x2b309
xorl %eax, %eax
callq 0x60fd
xorb $0x1, %bpl
orb %bl, %bpl
je 0xe65c
pushq $0x1
popq %rdi
callq 0xc917
leaq 0x87150f(%rip), %rdi    # 0x87fb40
callq 0x20d0
leaq 0x1ccf9(%rip), %rdi     # 0x2b336
xorl %eax, %eax
callq 0x60fd
leaq 0xecf45(%rip), %rax     # 0xfb590
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2120
callq 0xdf4f
jmp 0xe682
callq 0xc92f
xorl %edi, %edi
callq 0xc923
leaq 0x8714d1(%rip), %rdi    # 0x87fb40
callq 0x20d0
leaq 0x1ccbb(%rip), %rdi     # 0x2b336
xorl %eax, %eax
callq 0x60fd
addq $0x18, %rsp
popq %rbx
popq %rbp
retq