// File: /workspace/github_cpp_makefile_star2_O3/SethKasmann[P]clever-girl/src/move_generator.cpp
// Function: void MoveList::pushPawnMoves<(MoveType)2, (Color)0>()
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), %rcx
movq 0x288(%rcx), %r15
movq %r15, %r14
shlq $0x8, %r14
movabsq $-0x100000000000000, %r12 # imm = 0xFF00000000000000
andq %r14, %r12
je 0x10c9c
leaq -0x1(%r12), %r13
bsfq %r12, %rdx
leal -0x8(%rdx), %esi
movq %rbx, %rdi
callq 0x119d2
andq %r13, %r12
jne 0x10c7f
movq 0x18(%rbx), %rcx
movq 0x80(%rcx), %rax
movq 0x8(%rbx), %rdx
movq %rdx, %rdi
andq %rax, %rdi
orq 0x30(%rcx), %rdi
movq %r15, %r8
shlq $0x9, %r8
andq %rdi, %r8
shlq $0x7, %r15
movabsq $0x7f7f7f7f7f7f00, %rsi # imm = 0x7F7F7F7F7F7F00
andq %r15, %rsi
andq %rdi, %rsi
movabsq $0xfefefefefefe00, %rdi # imm = 0xFEFEFEFEFEFE00
andq %r8, %rdi
je 0x10d0d
movq 0x848(%rbx), %r8
leaq -0x1(%rdi), %r9
bsfq %rdi, %r10
leal -0x9(%r10), %r11d
shll $0x6, %r10d
orl %r11d, %r10d
movw %r10w, 0x30(%rbx,%r8,8)
incq %r8
andq %r9, %rdi
jne 0x10ce5
movq %r8, 0x848(%rbx)
testq %rsi, %rsi
je 0x10d41
movq 0x848(%rbx), %rdi
leaq -0x1(%rsi), %r8
bsfq %rsi, %r9
leal -0x7(%r9), %r10d
shll $0x6, %r9d
orl %r10d, %r9d
movw %r9w, 0x30(%rbx,%rdi,8)
incq %rdi
andq %r8, %rsi
jne 0x10d19
movq %rdi, 0x848(%rbx)
orq 0x78(%rcx), %rax
notq %rax
andq %rax, %r14
movq %r14, %rsi
andq %rdx, %rsi
shll $0x8, %r14d
andl %edx, %eax
andl %r14d, %eax
andl $0xff000000, %eax       # imm = 0xFF000000
movabsq $0xffffffffffff00, %rcx # imm = 0xFFFFFFFFFFFF00
andq %rsi, %rcx
je 0x10d9b
movq 0x848(%rbx), %rdx
leaq -0x1(%rcx), %rsi
bsfq %rcx, %rdi
leal -0x8(%rdi), %r8d
shll $0x6, %edi
orl %r8d, %edi
movw %di, 0x30(%rbx,%rdx,8)
incq %rdx
andq %rsi, %rcx
jne 0x10d75
movq %rdx, 0x848(%rbx)
testq %rax, %rax
je 0x10dcb
movq 0x848(%rbx), %rcx
leaq -0x1(%rax), %rdx
bsfq %rax, %rsi
leal -0x10(%rsi), %edi
shll $0x6, %esi
orl %edi, %esi
movw %si, 0x30(%rbx,%rcx,8)
incq %rcx
andq %rdx, %rax
jne 0x10da7
movq %rcx, 0x848(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop