// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
leaq 0x1d38b(%rip), %rdi     # 0x2c654
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x2190
cmpl $-0x1, %eax
je 0xf40f
leaq 0xb963b(%rip), %rsi     # 0xc8920
leaq 0x4(%rsp), %rdi
callq 0xe195
testq %rax, %rax
je 0xf3c0
movq %rax, %rbx
leaq 0xe(%rsp), %rsi
movq %rax, %rdi
callq 0xe0f5
leaq 0xb9611(%rip), %rdi     # 0xc8920
leaq 0xb97da(%rip), %rdx     # 0xc8af0
movq %rbx, %rsi
callq 0x30e3
cmpb $0x0, 0x32e8b(%rip)     # 0x421b0
jne 0xf40f
leaq 0x86d80e(%rip), %rdi    # 0x87cb40
callq 0x2290
leaq 0x1df6a(%rip), %rdi     # 0x2d2a8
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x652d
leaq 0x1dfb1(%rip), %r14     # 0x2d300
callq 0xd31c
movl %eax, %ebp
movq %r14, %rsi
testb %al, %al
je 0xf370
callq 0xd323
cmpq %rax, %rbx
sete %r15b
leaq 0x1df8b(%rip), %rsi     # 0x2d2fb
leaq 0x1df84(%rip), %rax     # 0x2d2fb
testb %r15b, %r15b
cmovneq %rax, %r14
leaq 0x1df54(%rip), %rdi     # 0x2d2d9
movq %r14, %rdx
xorl %eax, %eax
callq 0x652d
andb %r15b, %bpl
cmpb $0x1, %bpl
jne 0xf3d5
callq 0xd343
xorl %edi, %edi
callq 0xd337
leaq 0x86d795(%rip), %rdi    # 0x87cb40
callq 0x20e0
leaq 0x1df4f(%rip), %rdi     # 0x2d306
xorl %eax, %eax
callq 0x652d
jmp 0xf40f
leaq 0x1decf(%rip), %rdi     # 0x2d296
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x640d
jmp 0xf40f
movl $0x1, %edi
callq 0xd32b
leaq 0x86d75a(%rip), %rdi    # 0x87cb40
callq 0x20e0
leaq 0x1df14(%rip), %rdi     # 0x2d306
xorl %eax, %eax
callq 0x652d
leaq 0xe9190(%rip), %rax     # 0xf8590
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2130
callq 0xec29
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq