// File: /workspace/github_cpp_makefile_star2_O1/SethKasmann[P]clever-girl/src/evaluation.cpp
// Function: Evaluate::evalPawns(Color)
void Evaluate::evalPawns(const Color c)
{
    const int dir = c == white ? 8 : -8;

    // Pawn evaluation.
    for (Square p : mState.getPieceList<pawn>(c))
    {
        if (p == no_sq)
            break;

        mMaterial[c] += Pawn_wt;
        // Check if the pawn is a passed pawn.
        if (!((file_bb[p] | adj_files[p]) & in_front[c][p] & mState.getPieceBB<pawn>(!c)))
            mPawnStructure[c] += Passed;
        // Look for candidate and backwards pawns since the logic is related.
        // First check for a half open file.
        else if (!(file_bb[p] & in_front[c][p] & mState.getPieceBB<pawn>(!c)))
        {
            int sentries, helpers;
            assert(p < 56 && p > 7);
            // Check, if this pawn were to push, if there are any enemy pawns
            // defending that square.
            sentries = pop_count(pawn_attacks[c][p + dir] & mState.getPieceBB<pawn>(!c));
            if (sentries > 0)
            {
                // If the enemy has defenders, check if we helper pawns defending
                // that square.
                helpers = pop_count(pawn_attacks[!c][p + dir] & mState.getPieceBB<pawn>(c));
                // If there are more helpers then sentries, we have a candidate
                // passer.
                if (helpers >= sentries)
                    mPawnStructure[c] += Candidate;
                // If there are less helpers then sentries, check for a backwards
                // pawn. First, see if there are no pawns eligible to defend it.
                else if (!(~in_front[c][p] & adj_files[p] & mState.getPieceBB<pawn>(c)))
                {
                    // Make sure the backwards pawn is defending at least 1 pawn.
                    if (pawn_attacks[c][p] & mState.getPieceBB<pawn>(c))
                    {
                        // If there are two sentries, this backwards pawn is
                        // nearly imposible to push.
                        if (sentries == 2)
                            mPawnStructure[c] += Full_backwards;
                        else
                            mPawnStructure[c] += Backwards;
                    }
                }
            }
        }

        // Check if the pawn is isolated
        if (!(adj_files[p] & mState.getPieceBB<pawn>(c)))
            mPawnStructure[c] += Isolated;
        // Check if the pawn is connected
        else if (rank_bb[p - dir] & mState.getPieceBB<pawn>(c) & adj_files[p])
            mPawnStructure[c] += Connected;

        // Check if the pawn is doubled.
        if (pop_count(file_bb[p] & mState.getPieceBB<pawn>(c)) > 1)
            mPawnStructure[c] += Doubled;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
xorl %r8d, %r8d
testl %esi, %esi
sete %r8b
movl %r8d, %r9d
shll $0x4, %r9d
addl $-0x8, %r9d
movq 0x8(%rdi), %rax
movl %esi, %edx
imulq $0xf0, %rdx, %rsi
leaq (%rax,%rsi), %rcx
addq $0x328, %rcx            # imm = 0x328
movq %r8, -0x18(%rsp)
leaq (%r8,%r8,2), %r8
shll $0x4, %r8d
leaq (%rax,%r8), %rsi
addq $0x288, %rsi            # imm = 0x288
movq %rcx, %r8
movq %r9, %rcx
leaq (%rdx,%rdx,2), %r9
shlq $0x4, %r9
addq %r9, %rax
addq $0x288, %rax            # imm = 0x288
movq %rax, -0x30(%rsp)
movq %rsi, %r9
movq $-0x28, %r10
movq %rdx, %rax
shlq $0x9, %rax
leaq 0x10bb70(%rip), %r15    # 0x119e70
addq %rax, %r15
leaq 0xead66(%rip), %rsi     # 0xf9070
movq %rax, -0x28(%rsp)
addq %rax, %rsi
movq %rsi, -0x8(%rsp)
movq %r15, -0x20(%rsp)
movl 0x28(%r8,%r10), %r14d
cmpq $0x40, %r14
je 0xe4fb
addl $0x64, 0x2c(%rdi,%rdx,4)
leaq 0xea939(%rip), %rax     # 0xf8c70
movq (%rax,%r14,8), %rbp
leaq 0x10b92e(%rip), %rax    # 0x119c70
movq (%rax,%r14,8), %r12
movq %r12, %rbx
orq %rbp, %rbx
movq (%r15,%r14,8), %rax
movq (%r9), %r11
andq %rax, %rbx
testq %r11, %rbx
je 0xe4a4
movq %r11, %rbx
andq %rax, %rbx
testq %rbp, %rbx
jne 0xe4ad
leal (%r14,%rcx), %ebx
movq -0x8(%rsp), %rsi
andq (%rsi,%rbx,8), %r11
je 0xe4ad
movq %r11, %r13
shrq %r13
movabsq $0x5555555555555555, %rsi # imm = 0x5555555555555555
andq %rsi, %r13
subq %r13, %r11
movq %r11, %r13
movabsq $0x3333333333333333, %r15 # imm = 0x3333333333333333
andq %r15, %r13
shrq $0x2, %r11
andq %r15, %r11
addq %r13, %r11
movq %r11, %r13
shrq $0x4, %r13
addq %r11, %r13
movabsq $0xf0f0f0f0f0f0f0f, %rsi # imm = 0xF0F0F0F0F0F0F0F
andq %rsi, %r13
movabsq $0x101010101010101, %rsi # imm = 0x101010101010101
imulq %rsi, %r13
shrq $0x38, %r13
movq -0x18(%rsp), %rsi
shll $0x9, %esi
addq 0x16bc7(%rip), %rsi     # 0x24fb0
movq -0x30(%rsp), %r11
movq (%r11), %r11
movq (%rsi,%rbx,8), %rsi
movq %r11, -0x10(%rsp)
andq %r11, %rsi
movq %rsi, %rbx
shrq %rbx
movabsq $0x5555555555555555, %r11 # imm = 0x5555555555555555
andq %r11, %rbx
subq %rbx, %rsi
movq %rsi, %rbx
andq %r15, %rbx
shrq $0x2, %rsi
andq %r15, %rsi
movq -0x20(%rsp), %r15
addq %rbx, %rsi
movq %r9, %r11
movq %rcx, %r9
movq %r8, %rcx
movq %rsi, %r8
shrq $0x4, %r8
addq %rsi, %r8
movabsq $0xf0f0f0f0f0f0f0f, %rsi # imm = 0xF0F0F0F0F0F0F0F
andq %rsi, %r8
movabsq $0x101010101010101, %rsi # imm = 0x101010101010101
imulq %rsi, %r8
shrq $0x38, %r8
movl $0xa, %ebx
cmpl %r13d, %r8d
movq %rcx, %r8
movq %r9, %rcx
movq %r11, %r9
jae 0xe4a9
notq %rax
andq %r12, %rax
movq -0x10(%rsp), %r11
testq %r11, %rax
jne 0xe4ad
movq -0x28(%rsp), %rax
leaq 0xeabe7(%rip), %rsi     # 0xf9070
addq %rsi, %rax
testq %r11, (%rax,%r14,8)
je 0xe4ad
movl $0xfffffff1, %ebx       # imm = 0xFFFFFFF1
cmpl $0x2, %r13d
je 0xe4a9
movl $0xfffffffb, %ebx       # imm = 0xFFFFFFFB
jmp 0xe4a9
movl $0x14, %ebx
addl %ebx, 0x24(%rdi,%rdx,4)
movq -0x30(%rsp), %rax
movq (%rax), %rax
testq %r12, %rax
je 0xe4d5
subl %ecx, %r14d
leaq 0xea9ac(%rip), %rsi     # 0xf8e70
andq (%rsi,%r14,8), %r12
movl $0xa, %r11d
testq %rax, %r12
jne 0xe4db
jmp 0xe4e0
movl $0xfffffff6, %r11d      # imm = 0xFFFFFFF6
addl %r11d, 0x24(%rdi,%rdx,4)
andq %rbp, %rax
leaq -0x1(%rax), %rsi
testq %rsi, %rax
je 0xe4f1
addl $-0x5, 0x24(%rdi,%rdx,4)
addq $0x4, %r10
jne 0xe31c
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq