// File: niekh1234[P]nnchesslib/movegen.cpp
// Function: nnchesslib::genWhiteSinglePawnMoves(nnchesslib::ChessBoard, std::vector<unsigned int, std::allocator<unsigned int>>&, nnchesslib::BitBoard)
void nnchesslib::genWhiteSinglePawnMoves(ChessBoard board, MoveList& moveList, BitBoard blockers)
{
    BitBoard pawns = board.getBoard(WHITE, PAWN);
    // making a move and checking if pawns have been blocked
    BitBoard pawnsMoved = (pawns.board << 8) & ~blockers.board;

    BitBoard promotedPawns = pawnsMoved.board & rank_bb[RANK_8];
    // make a copy because we still want to use promotedpawns bitboard after lsb has been popped.
    BitBoard promotedPawnsCopy = promotedPawns;
    int promotedPawnCount = __builtin_popcountll(promotedPawns.board);

    for(int _ =  0; _ < promotedPawnCount; _++)
    {
        int index = popLsb(promotedPawnsCopy.board);
        // genPromotions function only works for a single index in the bitboard.
        BitBoard singlePawnBoard;
        singlePawnBoard.set(index, true);

        genPromotions(index - 8, moveList, WHITE, singlePawnBoard);
    }

    pawnsMoved.board &= ~rank_bb[RANK_8];

    int validPawnCount = __builtin_popcountll(pawnsMoved.board);

    for(int _ = 0; _ < validPawnCount; _++)
    {
        // finding current index of pawn.
        int index = popLsb(pawnsMoved.board);

        if (index == -1)
            continue;
        // adding to pseudo legal movelist. 
        Move move = createMove(index - 8, index);
        moveList.push_back(move);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, %rax
leaq 0x10(%rbp), %rdi
movq %rsi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movl $0x1, %esi
xorl %edx, %edx
callq 0x76f0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rsi
shlq $0x8, %rsi
movq -0x8(%rbp), %rax
xorq $-0x1, %rax
andq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x4bc0
movq -0x20(%rbp), %rsi
andq 0x33aa(%rip), %rsi      # 0xeb98
leaq -0x28(%rbp), %rdi
callq 0x4bc0
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, %rax
shrq %rax
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
andq %rdx, %rax
subq %rax, %rcx
movabsq $0x3333333333333333, %rdx # imm = 0x3333333333333333
movq %rcx, %rax
andq %rdx, %rax
shrq $0x2, %rcx
andq %rdx, %rcx
addq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
addq %rcx, %rax
movabsq $0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F
andq %rcx, %rax
movabsq $0x101010101010101, %rcx # imm = 0x101010101010101
imulq %rcx, %rax
shrq $0x38, %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xb8bf
leaq -0x30(%rbp), %rdi
callq 0xc970
movl %eax, -0x3c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4ba0
movl -0x3c(%rbp), %esi
leaq -0x48(%rbp), %rdi
movl $0x1, %edx
callq 0x4c40
movl -0x3c(%rbp), %edi
subl $0x8, %edi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movl $0x1, %edx
callq 0xc9c0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb866
movq 0x32d2(%rip), %rax      # 0xeb98
xorq $-0x1, %rax
andq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, %rax
shrq %rax
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
andq %rdx, %rax
subq %rax, %rcx
movabsq $0x3333333333333333, %rdx # imm = 0x3333333333333333
movq %rcx, %rax
andq %rdx, %rax
shrq $0x2, %rcx
andq %rdx, %rcx
addq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
addq %rcx, %rax
movabsq $0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F
andq %rcx, %rax
movabsq $0x101010101010101, %rcx # imm = 0x101010101010101
imulq %rcx, %rax
shrq $0x38, %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xb97e
leaq -0x20(%rbp), %rdi
callq 0xc970
movl %eax, -0x5c(%rbp)
cmpl $-0x1, -0x5c(%rbp)
jne 0xb955
jmp 0xb973
movl -0x5c(%rbp), %edi
subl $0x8, %edi
movl -0x5c(%rbp), %esi
callq 0xaab0
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xcbd0
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xb939
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)