// File: jswaff[P]prophet3/test/next__test.cpp
// Function: test_promotions()
void test_promotions() {
    position pos;
    set_pos(&pos,"8/4Pk1p/6p1/1r6/8/5N2/2B2PPP/b5K1 w - - ");

    move moves[MAX_MOVES_PER_PLY];
    move *endp = gen_legal_moves(moves,&pos,true,true);

    move e7e8q = to_move(PAWN,E7,E8);
    set_promopiece(&e7e8q,QUEEN);

    move e7e8r = to_move(PAWN,E7,E8);
    set_promopiece(&e7e8r,ROOK);

    move e7e8b = to_move(PAWN,E7,E8);
    set_promopiece(&e7e8b,BISHOP);

    move e7e8n = to_move(PAWN,E7,E8);
    set_promopiece(&e7e8n,KNIGHT);

    move c2g6 = to_capture(BISHOP,C2,G6,PAWN);

    assert(is_in_move_list(e7e8q,moves,endp));
    assert(is_in_move_list(e7e8r,moves,endp));
    assert(is_in_move_list(e7e8b,moves,endp));
    assert(is_in_move_list(e7e8n,moves,endp));
    assert(is_in_move_list(c2g6,moves,endp));

    move_order_dto mo_dto;
    mo_dto.startp = mo_dto.currentp = mo_dto.endp = moves;
    mo_dto.pv_move = 0;
    mo_dto.hash_move = 0;
    mo_dto.killer1 = 0;
    mo_dto.killer2 = 0;
    mo_dto.next_stage = PVMOVE;

    move *nextp;
    assert(next(&pos,&nextp,&mo_dto));
    assert(clear_score(*nextp)==e7e8q);

    assert(next(&pos,&nextp,&mo_dto));
    assert(clear_score(*nextp)==e7e8r);

    assert(next(&pos,&nextp,&mo_dto));
    assert(clear_score(*nextp)==e7e8b);

    assert(next(&pos,&nextp,&mo_dto));
    assert(clear_score(*nextp)==e7e8n);

    // NOTE: C2G6 is a losing capture - in SEE it would be at bottom
    /*for (int i=5;i<24;i++) {
        assert(next(&pos,&nextp,&mo_dto));
    }*/

    assert(next(&pos,&nextp,&mo_dto));
    assert(clear_score(*nextp)==c2g6);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xbb0, %rsp            # imm = 0xBB0
leaq -0x1c8(%rbp), %rdi
leaq 0x10f7a(%rip), %rsi     # 0x3ac23
callq 0xf3e0
leaq -0xb30(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0xac70
movq %rax, -0xb38(%rbp)
movl $0x1, %edi
movl $0xc, %esi
movl $0x4, %edx
callq 0xa830
movq %rax, -0xb40(%rbp)
leaq -0xb40(%rbp), %rdi
movl $0x5, %esi
callq 0xa9e0
movl $0x1, %edi
movl $0xc, %esi
movl $0x4, %edx
callq 0xa830
movq %rax, -0xb48(%rbp)
leaq -0xb48(%rbp), %rdi
movl $0x4, %esi
callq 0xa9e0
movl $0x1, %edi
movl $0xc, %esi
movl $0x4, %edx
callq 0xa830
movq %rax, -0xb50(%rbp)
leaq -0xb50(%rbp), %rdi
movl $0x3, %esi
callq 0xa9e0
movl $0x1, %edi
movl $0xc, %esi
movl $0x4, %edx
callq 0xa830
movq %rax, -0xb58(%rbp)
leaq -0xb58(%rbp), %rdi
movl $0x2, %esi
callq 0xa9e0
movl $0x3, %edi
movl $0x32, %esi
movl $0x16, %edx
movl $0x1, %ecx
callq 0xa890
movq %rax, -0xb60(%rbp)
movq -0xb40(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
movq -0xb38(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x29dbf
jmp 0x29dc1
jmp 0x29de0
leaq 0x16f13(%rip), %rdi     # 0x40cdb
leaq 0x1747b(%rip), %rsi     # 0x4124a
movl $0xb4, %edx
leaq 0x17717(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xb48(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
movq -0xb38(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x29e00
jmp 0x29e02
jmp 0x29e21
leaq 0x16f08(%rip), %rdi     # 0x40d11
leaq 0x1743a(%rip), %rsi     # 0x4124a
movl $0xb5, %edx
leaq 0x176d6(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xb50(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
movq -0xb38(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x29e41
jmp 0x29e43
jmp 0x29e62
leaq 0x16ee9(%rip), %rdi     # 0x40d33
leaq 0x173f9(%rip), %rsi     # 0x4124a
movl $0xb6, %edx
leaq 0x17695(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xb58(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
movq -0xb38(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x29e82
jmp 0x29e84
jmp 0x29ea3
leaq 0x16eca(%rip), %rdi     # 0x40d55
leaq 0x173b8(%rip), %rsi     # 0x4124a
movl $0xb7, %edx
leaq 0x17654(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xb60(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
movq -0xb38(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x29ec3
jmp 0x29ec5
jmp 0x29ee4
leaq 0x16eab(%rip), %rdi     # 0x40d77
leaq 0x17377(%rip), %rsi     # 0x4124a
movl $0xb8, %edx
leaq 0x17613(%rip), %rcx     # 0x414f2
callq 0x20c0
leaq -0xb30(%rbp), %rax
movq %rax, -0xb70(%rbp)
movq %rax, -0xb68(%rbp)
movq %rax, -0xb78(%rbp)
movq $0x0, -0xb98(%rbp)
movq $0x0, -0xb90(%rbp)
movq $0x0, -0xb88(%rbp)
movq $0x0, -0xb80(%rbp)
movl $0x0, -0xba0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0xba8(%rbp), %rsi
leaq -0xba0(%rbp), %rdx
callq 0xc670
testb $0x1, %al
jne 0x29f56
jmp 0x29f58
jmp 0x29f77
leaq 0x17579(%rip), %rdi     # 0x414d8
leaq 0x172e4(%rip), %rsi     # 0x4124a
movl $0xc3, %edx
leaq 0x17580(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xba8(%rbp), %rax
movq (%rax), %rdi
callq 0xac50
cmpq -0xb40(%rbp), %rax
jne 0x29f91
jmp 0x29fb0
leaq 0x17571(%rip), %rdi     # 0x41509
leaq 0x172ab(%rip), %rsi     # 0x4124a
movl $0xc4, %edx
leaq 0x17547(%rip), %rcx     # 0x414f2
callq 0x20c0
leaq -0x1c8(%rbp), %rdi
leaq -0xba8(%rbp), %rsi
leaq -0xba0(%rbp), %rdx
callq 0xc670
testb $0x1, %al
jne 0x29fd0
jmp 0x29fd2
jmp 0x29ff1
leaq 0x174ff(%rip), %rdi     # 0x414d8
leaq 0x1726a(%rip), %rsi     # 0x4124a
movl $0xc6, %edx
leaq 0x17506(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xba8(%rbp), %rax
movq (%rax), %rdi
callq 0xac50
cmpq -0xb48(%rbp), %rax
jne 0x2a00b
jmp 0x2a02a
leaq 0x17512(%rip), %rdi     # 0x41524
leaq 0x17231(%rip), %rsi     # 0x4124a
movl $0xc7, %edx
leaq 0x174cd(%rip), %rcx     # 0x414f2
callq 0x20c0
leaq -0x1c8(%rbp), %rdi
leaq -0xba8(%rbp), %rsi
leaq -0xba0(%rbp), %rdx
callq 0xc670
testb $0x1, %al
jne 0x2a04a
jmp 0x2a04c
jmp 0x2a06b
leaq 0x17485(%rip), %rdi     # 0x414d8
leaq 0x171f0(%rip), %rsi     # 0x4124a
movl $0xc9, %edx
leaq 0x1748c(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xba8(%rbp), %rax
movq (%rax), %rdi
callq 0xac50
cmpq -0xb50(%rbp), %rax
jne 0x2a085
jmp 0x2a0a4
leaq 0x174b3(%rip), %rdi     # 0x4153f
leaq 0x171b7(%rip), %rsi     # 0x4124a
movl $0xca, %edx
leaq 0x17453(%rip), %rcx     # 0x414f2
callq 0x20c0
leaq -0x1c8(%rbp), %rdi
leaq -0xba8(%rbp), %rsi
leaq -0xba0(%rbp), %rdx
callq 0xc670
testb $0x1, %al
jne 0x2a0c4
jmp 0x2a0c6
jmp 0x2a0e5
leaq 0x1740b(%rip), %rdi     # 0x414d8
leaq 0x17176(%rip), %rsi     # 0x4124a
movl $0xcc, %edx
leaq 0x17412(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xba8(%rbp), %rax
movq (%rax), %rdi
callq 0xac50
cmpq -0xb58(%rbp), %rax
jne 0x2a0ff
jmp 0x2a11e
leaq 0x17454(%rip), %rdi     # 0x4155a
leaq 0x1713d(%rip), %rsi     # 0x4124a
movl $0xcd, %edx
leaq 0x173d9(%rip), %rcx     # 0x414f2
callq 0x20c0
leaq -0x1c8(%rbp), %rdi
leaq -0xba8(%rbp), %rsi
leaq -0xba0(%rbp), %rdx
callq 0xc670
testb $0x1, %al
jne 0x2a13e
jmp 0x2a140
jmp 0x2a15f
leaq 0x17391(%rip), %rdi     # 0x414d8
leaq 0x170fc(%rip), %rsi     # 0x4124a
movl $0xd4, %edx
leaq 0x17398(%rip), %rcx     # 0x414f2
callq 0x20c0
movq -0xba8(%rbp), %rax
movq (%rax), %rdi
callq 0xac50
cmpq -0xb60(%rbp), %rax
jne 0x2a179
jmp 0x2a198
leaq 0x173f5(%rip), %rdi     # 0x41575
leaq 0x170c3(%rip), %rsi     # 0x4124a
movl $0xd5, %edx
leaq 0x1735f(%rip), %rcx     # 0x414f2
callq 0x20c0
addq $0xbb0, %rsp            # imm = 0xBB0
popq %rbp
retq
nopw %cs:(%rax,%rax)