// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x288(%rax), %r15
movq %r15, %r14
shlq $0x8, %r14
movabsq $-0x100000000000000, %rax # imm = 0xFF00000000000000
andq %r14, %rax
testq %rax, %rax
je 0xdd06
leaq -0x1(%rax), %r12
andq %rax, %r12
bsfq %rax, %rdx
leal -0x8(%rdx), %esi
movq %rbx, %rdi
callq 0xe9dc
movq %r12, %rax
jmp 0xdce6
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdi
movq 0x80(%rdi), %rsi
movq %rax, %r9
andq %rsi, %r9
orq 0x30(%rdi), %r9
movq %r15, %rcx
shlq $0x9, %rcx
movabsq $0xfefefefefefe00, %r10 # imm = 0xFEFEFEFEFEFE00
andq %rcx, %r10
andq %r9, %r10
shlq $0x7, %r15
movabsq $0x7f7f7f7f7f7f00, %r8  # imm = 0x7F7F7F7F7F7F00
andq %r15, %r8
movq 0x848(%rbx), %rcx
leaq (%rbx,%rcx,8), %rdx
addq $0x30, %rdx
incq %rcx
testq %r10, %r10
je 0xdd8b
leaq -0x1(%r10), %r11
andq %r10, %r11
bsfq %r10, %r10
leal -0x9(%r10), %ebp
shll $0x6, %r10d
orl %ebp, %r10d
movq %rcx, 0x848(%rbx)
movw %r10w, (%rdx)
incq %rcx
addq $0x8, %rdx
movq %r11, %r10
jmp 0xdd59
andq %r9, %r8
testq %r8, %r8
je 0xddc0
leaq -0x1(%r8), %r9
andq %r8, %r9
bsfq %r8, %r8
leal -0x7(%r8), %r10d
shll $0x6, %r8d
orl %r10d, %r8d
movq %rcx, 0x848(%rbx)
movw %r8w, (%rdx)
incq %rcx
addq $0x8, %rdx
movq %r9, %r8
jmp 0xdd8e
orq 0x78(%rdi), %rsi
notq %rsi
andq %rsi, %r14
movl %r14d, %r8d
shll $0x8, %r8d
movabsq $0xffffffffffff00, %rdi # imm = 0xFFFFFFFFFFFF00
andq %rax, %rdi
andq %r14, %rdi
andl %r8d, %eax
andl $0xff000000, %eax       # imm = 0xFF000000
testq %rdi, %rdi
je 0xde19
leaq -0x1(%rdi), %r8
andq %rdi, %r8
bsfq %rdi, %rdi
leal -0x8(%rdi), %r9d
shll $0x6, %edi
orl %r9d, %edi
movq %rcx, 0x848(%rbx)
movw %di, (%rdx)
incq %rcx
addq $0x8, %rdx
movq %r8, %rdi
jmp 0xdde9
andl %esi, %eax
testq %rax, %rax
je 0xde49
leaq -0x1(%rax), %rsi
andq %rax, %rsi
bsfq %rax, %rax
leal -0x10(%rax), %edi
shll $0x6, %eax
orl %edi, %eax
movq %rcx, 0x848(%rbx)
movw %ax, (%rdx)
incq %rcx
addq $0x8, %rdx
movq %rsi, %rax
jmp 0xde1b
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq