// File: jswaff[P]prophet3/test/next__test.cpp
// Function: test_best_at_top()
void test_best_at_top() {
    position pos;
    reset_pos(&pos);

    move moves[20];
    move *endp = gen_legal_moves(moves,&pos,true,true);
    assert(endp-moves==20);

    set_move_score(moves+4,1000);
    set_move_score(moves+11,900);
    set_move_score(moves+7,-1500);
    move mv1 = moves[4];
    move mv2 = moves[11];
    move mv3 = moves[7];

    int i=0;
    for (move *mp=moves;mp<endp;mp++) {
        if (*mp != mv1 && *mp != mv2 && *mp != mv3) {
            assert(get_move_score(mp)==0);
        }
        best_at_top(mp,endp);

        if (i==0) {
            assert(*mp==mv1);
        } else if (i==1) {
            assert(*mp==mv2);
        } else if (i==19) {
            assert(*mp==mv3);
        }
        i++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
leaq -0x1c8(%rbp), %rdi
callq 0xf390
leaq -0x270(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0xac70
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
leaq -0x270(%rbp), %rcx
subq %rcx, %rax
sarq $0x3, %rax
cmpq $0x14, %rax
jne 0x29265
jmp 0x29284
leaq 0x17fcf(%rip), %rdi     # 0x4123b
leaq 0x17fd7(%rip), %rsi     # 0x4124a
movl $0x12, %edx
leaq 0x17fdf(%rip), %rcx     # 0x4125e
callq 0x20c0
leaq -0x270(%rbp), %rdi
addq $0x20, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0xabe0
leaq -0x270(%rbp), %rdi
addq $0x58, %rdi
movl $0x384, %esi            # imm = 0x384
callq 0xabe0
leaq -0x270(%rbp), %rdi
addq $0x38, %rdi
movl $0xfffffa24, %esi       # imm = 0xFFFFFA24
callq 0xabe0
movq -0x250(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x218(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x238(%rbp), %rax
movq %rax, -0x290(%rbp)
movl $0x0, -0x294(%rbp)
leaq -0x270(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
cmpq -0x278(%rbp), %rax
jae 0x29483
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x280(%rbp), %rax
je 0x29386
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x288(%rbp), %rax
je 0x29386
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x290(%rbp), %rax
je 0x29386
movq -0x2a0(%rbp), %rdi
callq 0xab90
cmpl $0x0, %eax
jne 0x29365
jmp 0x29384
leaq 0xed19(%rip), %rdi      # 0x38085
leaq 0x17ed7(%rip), %rsi     # 0x4124a
movl $0x1e, %edx
leaq 0x17edf(%rip), %rcx     # 0x4125e
callq 0x20c0
jmp 0x29386
movq -0x2a0(%rbp), %rdi
movq -0x278(%rbp), %rsi
callq 0xd4b0
cmpl $0x0, -0x294(%rbp)
jne 0x293db
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x280(%rbp), %rax
jne 0x293b7
jmp 0x293d6
leaq 0x17eb8(%rip), %rdi     # 0x41276
leaq 0x17e85(%rip), %rsi     # 0x4124a
movl $0x23, %edx
leaq 0x17e8d(%rip), %rcx     # 0x4125e
callq 0x20c0
jmp 0x2945d
cmpl $0x1, -0x294(%rbp)
jne 0x2941a
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x288(%rbp), %rax
jne 0x293f9
jmp 0x29418
leaq 0x17e7f(%rip), %rdi     # 0x4127f
leaq 0x17e43(%rip), %rsi     # 0x4124a
movl $0x25, %edx
leaq 0x17e4b(%rip), %rcx     # 0x4125e
callq 0x20c0
jmp 0x2945b
cmpl $0x13, -0x294(%rbp)
jne 0x29459
movq -0x2a0(%rbp), %rax
movq (%rax), %rax
cmpq -0x290(%rbp), %rax
jne 0x29438
jmp 0x29457
leaq 0x17e49(%rip), %rdi     # 0x41288
leaq 0x17e04(%rip), %rsi     # 0x4124a
movl $0x27, %edx
leaq 0x17e0c(%rip), %rcx     # 0x4125e
callq 0x20c0
jmp 0x29459
jmp 0x2945b
jmp 0x2945d
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
movq -0x2a0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x2a0(%rbp)
jmp 0x29305
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
nopl (%rax)