// File: /workspace/github_cpp_makefile_star2_O1/SethKasmann[P]clever-girl/src/move_generator.cpp
// Function: void MoveList::pushPawnMoves<(MoveType)2, (Color)1>()
void MoveList::pushPawnMoves()
{
    constexpr int U = C == white ? 8 : -8;
    constexpr int L = C == white ? 9 : -7;
    constexpr int R = C == white ? 7 : -9;

    U64 promo, pawns;
    Square dst;

    pawns = mState.getPieceBB<pawn>(C);

    promo = (C == white ? pawns << 8 : pawns >> 8) & RankPromo;

    while (promo)
    {
        dst = pop_lsb(promo);
        pushPromotion<T>(dst - U, dst);
    }

    if (T == MoveType::Attacks || T == MoveType::Evasions || T == MoveType::All)
    {
        U64 occ = ((T == MoveType::Evasions ? mState.getOccupancyBB(!C) & mValid
                                            : mState.getOccupancyBB(!C))
                  | mState.getEnPassantBB()) & ~RankPromo;

        U64 left  = C == white ? (pawns & Not_a_file) << 9 & occ 
                               : (pawns & Not_a_file) >> 7 & occ;
        U64 right = C == white ? (pawns & Not_h_file) << 7 & occ
                               : (pawns & Not_h_file) >> 9 & occ;

        while (left)
        {
            dst = pop_lsb(left);
            push(makeMove(dst - L, dst));
        }

        while (right)
        {
            dst = pop_lsb(right);
            push(makeMove(dst - R, dst));
        }
    }

    if (T != MoveType::Attacks)
    {
        U64 empty = mState.getEmptyBB() & ~RankPromo;

        U64 up  = (C == white ? pawns << 8 : pawns >> 8) & empty;
        U64 dbl = (C == white ? (up & Rank_3) << 8 
                              : (up & Rank_6) >> 8) & empty;

        if (T == MoveType::Evasions)
        {
            up  &= mValid;
            dbl &= mValid;
        }

        if (T == MoveType::QuietChecks)
        {
            U64 dis;

            up  &= mState.getCheckSquaresBB(pawn);
            dbl &= mState.getCheckSquaresBB(pawn);

            dis = mDiscover & pawns & ~file_bb[mState.getKingSquare(!C)];
            dis = (C == white ? dis << 8 : dis >> 8) & empty;
            up  |= dis;
            dbl |= (C == white ? (dis & Rank_3) << 8 
                               : (dis & Rank_6) >> 8) & empty;
        }

        while (up)
        {
            dst = pop_lsb(up);
            push(makeMove(dst - U, dst));
        }

        while (dbl)
        {
            dst = pop_lsb(dbl);
            push(makeMove(dst - U - U, dst));
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x2b8(%rax), %r15
movq %r15, %r14
shrq $0x8, %r14
movq %r14, %r12
andq $0xff, %r12
je 0x10e1d
leaq -0x1(%r12), %r13
bsfq %r12, %rdx
leal 0x8(%rdx), %esi
movq %rbx, %rdi
callq 0x119d4
andq %r13, %r12
jne 0x10e04
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdx
movq 0x78(%rdx), %rcx
movq %rax, %rdi
andq %rcx, %rdi
orq 0x30(%rdx), %rdi
movq %r15, %r8
shrq $0x7, %r8
andq %rdi, %r8
shrq $0x9, %r15
movabsq $0x7f7f7f7f7f7f00, %rsi # imm = 0x7F7F7F7F7F7F00
andq %r15, %rsi
andq %rdi, %rsi
movabsq $0xfefefefefefe00, %rdi # imm = 0xFEFEFEFEFEFE00
andq %r8, %rdi
je 0x10e8f
movq 0x848(%rbx), %r8
leaq -0x1(%rdi), %r9
bsfq %rdi, %r10
leal 0x7(%r10), %r11d
shll $0x6, %r10d
orl %r11d, %r10d
movw %r10w, 0x30(%rbx,%r8,8)
incq %r8
andq %r9, %rdi
jne 0x10e67
movq %r8, 0x848(%rbx)
testq %rsi, %rsi
je 0x10ec3
movq 0x848(%rbx), %rdi
leaq -0x1(%rsi), %r8
bsfq %rsi, %r9
leal 0x9(%r9), %r10d
shll $0x6, %r9d
orl %r10d, %r9d
movw %r9w, 0x30(%rbx,%rdi,8)
incq %rdi
andq %r8, %rsi
jne 0x10e9b
movq %rdi, 0x848(%rbx)
orq 0x80(%rdx), %rcx
notq %rcx
andq %rcx, %r14
andq $-0x100, %r14
movq %r14, %rsi
shrq $0x8, %rsi
andq %rax, %rcx
movabsq $0xff00000000, %rdx     # imm = 0xFF00000000
andq %rcx, %rdx
andq %rsi, %rdx
andq %rax, %r14
je 0x10f21
movq 0x848(%rbx), %rax
leaq -0x1(%r14), %rcx
bsfq %r14, %rsi
leal 0x8(%rsi), %edi
shll $0x6, %esi
orl %edi, %esi
movw %si, 0x30(%rbx,%rax,8)
incq %rax
andq %rcx, %r14
jne 0x10efd
movq %rax, 0x848(%rbx)
testq %rdx, %rdx
je 0x10f51
movq 0x848(%rbx), %rax
leaq -0x1(%rdx), %rcx
bsfq %rdx, %rsi
leal 0x10(%rsi), %edi
shll $0x6, %esi
orl %edi, %esi
movw %si, 0x30(%rbx,%rax,8)
incq %rax
andq %rcx, %rdx
jne 0x10f2d
movq %rax, 0x848(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop