// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
leaq -0xa(%rbp), %rsi
leaq 0x22a04(%rip), %rdi     # 0x38607
movb $0x0, %al
callq 0x2190
cmpl $-0x1, %eax
jne 0x15c14
jmp 0x15d71
leaq -0xa(%rbp), %rdi
leaq 0xbdec1(%rip), %rsi     # 0xd3ae0
callq 0x14400
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x15c46
leaq -0xa(%rbp), %rsi
leaq 0x234d4(%rip), %rdi     # 0x3910e
movb $0x0, %al
callq 0x8c60
jmp 0x15d71
movq -0x18(%rbp), %rdi
leaq -0x22(%rbp), %rsi
callq 0x14350
movq -0x18(%rbp), %rsi
leaq 0xbde82(%rip), %rdi     # 0xd3ae0
leaq 0xbe04b(%rip), %rdx     # 0xd3cb0
callq 0x3620
testb $0x1, 0x376ff(%rip)     # 0x4d370
jne 0x15d6f
leaq 0x872082(%rip), %rdi    # 0x887d00
callq 0x2290
leaq 0x23496(%rip), %rdi     # 0x39120
movb $0x0, %al
callq 0x8db0
callq 0x13090
andb $0x1, %al
movb %al, -0x23(%rbp)
xorl %eax, %eax
testb $0x1, -0x23(%rbp)
movb %al, -0x26(%rbp)
je 0x15cc3
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
callq 0x130a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
sete %al
movb %al, -0x26(%rbp)
movb -0x26(%rbp), %al
andb $0x1, %al
movb %al, -0x24(%rbp)
movb -0x23(%rbp), %cl
leaq 0x234a3(%rip), %rsi     # 0x39178
leaq 0x23497(%rip), %rax     # 0x39173
testb $0x1, %cl
cmovneq %rax, %rsi
movb -0x24(%rbp), %cl
leaq 0x2348b(%rip), %rdx     # 0x39178
leaq 0x2347f(%rip), %rax     # 0x39173
testb $0x1, %cl
cmovneq %rax, %rdx
leaq 0x2344f(%rip), %rdi     # 0x39151
movb $0x0, %al
callq 0x8db0
testb $0x1, -0x23(%rbp)
je 0x15d27
testb $0x1, -0x24(%rbp)
je 0x15d27
callq 0x13110
xorl %edi, %edi
callq 0x130e0
movb $0x0, -0x25(%rbp)
jmp 0x15d35
movl $0x1, %edi
callq 0x130b0
movb $0x1, -0x25(%rbp)
leaq 0x871fc4(%rip), %rdi    # 0x887d00
callq 0x20d0
leaq 0x23436(%rip), %rdi     # 0x3917e
movb $0x0, %al
callq 0x8db0
testb $0x1, -0x25(%rbp)
je 0x15d6d
leaq 0xed9f4(%rip), %rax     # 0x103750
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2120
callq 0x15440
jmp 0x15d6f
jmp 0x15d71
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)