// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d4c3(%rip), %rdi     # 0x2c6d4
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x2190
cmpl $-0x1, %eax
je 0xf35a
leaq 0xb96f3(%rip), %rsi     # 0xc8920
leaq 0x4(%rsp), %rdi
callq 0xe13f
testq %rax, %rax
je 0xf2f3
movq %rax, %rbx
leaq 0xe(%rsp), %rsi
movq %rax, %rdi
callq 0xe09f
leaq 0xb96c9(%rip), %rdi     # 0xc8920
leaq 0xb9892(%rip), %rdx     # 0xc8af0
movq %rbx, %rsi
callq 0x30e1
cmpb $0x0, 0x32f43(%rip)     # 0x421b0
jne 0xf35a
leaq 0x86d8c6(%rip), %rdi    # 0x87cb40
callq 0x2290
leaq 0x1e0a2(%rip), %rdi     # 0x2d328
xorl %eax, %eax
callq 0x65d9
callq 0xd30c
testb %al, %al
je 0xf308
movl %eax, %ebp
callq 0xd313
cmpq %rax, %rbx
sete %bl
leaq 0x1e0d1(%rip), %rsi     # 0x2d37b
leaq 0x1e0cf(%rip), %rdx     # 0x2d380
cmoveq %rsi, %rdx
leaq 0x1e09d(%rip), %rdi     # 0x2d359
xorl %eax, %eax
callq 0x65d9
andb %bpl, %bl
cmpb $0x1, %bl
jne 0xf320
callq 0xd333
xorl %edi, %edi
callq 0xd327
leaq 0x86d862(%rip), %rdi    # 0x87cb40
callq 0x20e0
leaq 0x1e09c(%rip), %rdi     # 0x2d386
xorl %eax, %eax
callq 0x65d9
jmp 0xf35a
leaq 0x1e01c(%rip), %rdi     # 0x2d316
leaq 0x4(%rsp), %rsi
xorl %eax, %eax
callq 0x64b9
jmp 0xf35a
leaq 0x1e04a(%rip), %rdi     # 0x2d359
leaq 0x1e06a(%rip), %rdx     # 0x2d380
movq %rdx, %rsi
xorl %eax, %eax
callq 0x65d9
movl $0x1, %edi
callq 0xd31b
leaq 0x86d80f(%rip), %rdi    # 0x87cb40
callq 0x20e0
leaq 0x1e049(%rip), %rdi     # 0x2d386
xorl %eax, %eax
callq 0x65d9
leaq 0xe9245(%rip), %rax     # 0xf8590
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2130
callq 0xeb75
addq $0x18, %rsp
popq %rbx
popq %rbp
retq