// File: jswaff[P]prophet3/test/search__test.cpp
// Function: test_search_last_pv_first()
void test_search_last_pv_first() {
    position pos;
    reset_pos(&pos);
    clear_hash_table(&htbl);

    // create an artificial PV and ensure the search examines it first
    search_stats stats;
    stats.last_pv.n=4;
    move c2c4 = stats.last_pv.mv[0] = to_move(PAWN,C2,C4);
    move b7b5 = stats.last_pv.mv[1] = to_move(PAWN,B7,B5);
    move c4b5 = to_move(PAWN,C4,B5);
    set_capture(&c4b5,PAWN);
    stats.last_pv.mv[2] = c4b5;
    move g8h6 = stats.last_pv.mv[3] = to_move(KNIGHT,G8,H6);

    char pv_text[100];
    line_to_str(&stats.last_pv,pv_text);
    //print("last pv: %s\n",pv_text);

    stats.nodes=0;
    start_timer(10000);
    stats.first_line_searched.n=0;
    for (int i=0;i<MAX_PLY;i++) {
        stats.first_line_searched.mv[i] = BADMOVE;
    }
    move_line pv; pv.n=0;
    search(&pos,&pv,-INF,INF,5,&stats,move_stack,gundos,false);

    line_to_str(&stats.first_line_searched,pv_text);
    //print("first line length: %d\n",stats.first_line_searched.n);
    //print("first line: %s\n",pv_text);

    assert(stats.first_line_searched.mv[0]==c2c4);
    assert(stats.first_line_searched.mv[1]==b7b5);
    assert(stats.first_line_searched.mv[2]==c4b5);
    assert(stats.first_line_searched.mv[3]==g8h6);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc20, %rsp            # imm = 0xC20
leaq -0x1c8(%rbp), %rdi
callq 0xf390
leaq 0xd31e2(%rip), %rdi     # 0x1030b0
callq 0x88c0
movl $0x4, -0x820(%rbp)
movl $0x1, %edi
movl $0x32, %esi
movl $0x22, %edx
callq 0xa830
movq %rax, -0x818(%rbp)
movq %rax, -0x850(%rbp)
movl $0x1, %edi
movl $0x9, %esi
movl $0x19, %edx
callq 0xa830
movq %rax, -0x810(%rbp)
movq %rax, -0x858(%rbp)
movl $0x1, %edi
movl $0x22, %esi
movl $0x19, %edx
callq 0xa830
movq %rax, -0x860(%rbp)
leaq -0x860(%rbp), %rdi
movl $0x1, %esi
callq 0xa920
movq -0x860(%rbp), %rax
movq %rax, -0x808(%rbp)
movl $0x2, %edi
movl $0x6, %esi
movl $0x17, %edx
callq 0xa830
movq %rax, -0x800(%rbp)
movq %rax, -0x868(%rbp)
leaq -0x848(%rbp), %rdi
addq $0x28, %rdi
leaq -0x8d0(%rbp), %rsi
callq 0x14270
movq $0x0, -0x830(%rbp)
movl $0x2710, %edi           # imm = 0x2710
callq 0x2f8b0
movl $0x0, -0x4f8(%rbp)
movl $0x0, -0x8d4(%rbp)
cmpl $0x64, -0x8d4(%rbp)
jge 0x2ffea
movslq -0x8d4(%rbp), %rax
movq $0x0, -0x4f0(%rbp,%rax,8)
movl -0x8d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d4(%rbp)
jmp 0x2ffbd
movl $0x0, -0xc00(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0xc00(%rbp), %rsi
movl $0xfffcf2c0, %edx       # imm = 0xFFFCF2C0
movl $0x30d40, %ecx          # imm = 0x30D40
movl $0x5, %r8d
leaq -0x848(%rbp), %r9
leaq 0x890f60(%rip), %r10    # 0x8c0f80
leaq 0xa3c89(%rip), %rax     # 0xd3cb0
xorl %r11d, %r11d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x10350
leaq -0x848(%rbp), %rdi
addq $0x350, %rdi            # imm = 0x350
leaq -0x8d0(%rbp), %rsi
callq 0x14270
movq -0x4f0(%rbp), %rax
cmpq -0x850(%rbp), %rax
jne 0x3006c
jmp 0x3008b
leaq 0x132b2(%rip), %rdi     # 0x43325
leaq 0x1312c(%rip), %rsi     # 0x431a6
movl $0x91, %edx
leaq 0x132c5(%rip), %rcx     # 0x4334b
callq 0x20c0
movq -0x4e8(%rbp), %rax
cmpq -0x858(%rbp), %rax
jne 0x3009d
jmp 0x300bc
leaq 0x132c8(%rip), %rdi     # 0x4336c
leaq 0x130fb(%rip), %rsi     # 0x431a6
movl $0x92, %edx
leaq 0x13294(%rip), %rcx     # 0x4334b
callq 0x20c0
movq -0x4e0(%rbp), %rax
cmpq -0x860(%rbp), %rax
jne 0x300ce
jmp 0x300ed
leaq 0x132bd(%rip), %rdi     # 0x43392
leaq 0x130ca(%rip), %rsi     # 0x431a6
movl $0x93, %edx
leaq 0x13263(%rip), %rcx     # 0x4334b
callq 0x20c0
movq -0x4d8(%rbp), %rax
cmpq -0x868(%rbp), %rax
jne 0x300ff
jmp 0x3011e
leaq 0x132b2(%rip), %rdi     # 0x433b8
leaq 0x13099(%rip), %rsi     # 0x431a6
movl $0x94, %edx
leaq 0x13232(%rip), %rcx     # 0x4334b
callq 0x20c0
addq $0xc20, %rsp            # imm = 0xC20
popq %rbp
retq
nopw (%rax,%rax)