// File: /workspace/github_cpp_makefile_star2_O2/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, %ecx
shll $0x4, %ecx
addl $-0x8, %ecx
movq 0x8(%rdi), %rax
movl %esi, %edx
imulq $0xf0, %rdx, %rsi
addq %rax, %rsi
addq $0x328, %rsi            # imm = 0x328
movq %r8, -0x10(%rsp)
imulq $0x30, %r8, %r8
addq %rax, %r8
addq $0x288, %r8             # imm = 0x288
imulq $0x30, %rdx, %r9
addq %rax, %r9
addq $0x288, %r9             # imm = 0x288
movabsq $-0x28, %r10
movq %rdx, %rax
shlq $0x9, %rax
leaq 0x13c3c4(%rip), %r15    # 0x147e80
addq %rax, %r15
leaq 0x11b5ba(%rip), %r11    # 0x127080
movq %rax, -0x18(%rsp)
addq %rax, %r11
movq %r11, -0x8(%rsp)
movq %r8, -0x30(%rsp)
movq %rsi, -0x20(%rsp)
movq %rcx, -0x28(%rsp)
testq %r10, %r10
je 0xbcc9
movl 0x28(%rsi,%r10), %r12d
cmpq $0x40, %r12
je 0xbcc9
addl $0x64, 0x2c(%rdi,%rdx,4)
leaq 0x11b17a(%rip), %rax    # 0x126c80
movq (%rax,%r12,8), %r14
leaq 0x13c16f(%rip), %rax    # 0x147c80
movq (%rax,%r12,8), %rax
movq %rax, %r11
orq %r14, %r11
movq (%r15,%r12,8), %r13
movq (%r8), %rbx
andq %r13, %r11
testq %rbx, %r11
je 0xbc5e
movq %rbx, %r11
andq %r13, %r11
testq %r14, %r11
jne 0xbc69
leal (%r12,%rcx), %ebp
movq -0x8(%rsp), %r11
andq (%r11,%rbp,8), %rbx
je 0xbc69
movq %rbx, %r11
shrq %r11
movabsq $0x5555555555555555, %r8 # imm = 0x5555555555555555
andq %r8, %r11
subq %r11, %rbx
movq %rbx, %r11
movabsq $0x3333333333333333, %rsi # imm = 0x3333333333333333
andq %rsi, %r11
shrq $0x2, %rbx
andq %rsi, %rbx
addq %r11, %rbx
movq %rbx, %r11
shrq $0x4, %r11
addq %rbx, %r11
movabsq $0xf0f0f0f0f0f0f0f, %r8 # imm = 0xF0F0F0F0F0F0F0F
andq %r8, %r11
movabsq $0x101010101010101, %r8 # imm = 0x101010101010101
imulq %r8, %r11
shrq $0x38, %r11
movq -0x10(%rsp), %r8
shll $0x9, %r8d
addq 0x173ef(%rip), %r8      # 0x22fa8
movq (%r9), %rbx
movq (%r8,%rbp,8), %r8
andq %rbx, %r8
movq %r8, %rbp
shrq %rbp
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
andq %rcx, %rbp
subq %rbp, %r8
movq %r8, %rbp
andq %rsi, %rbp
shrq $0x2, %r8
andq %rsi, %r8
addq %rbp, %r8
movq %r8, %rbp
shrq $0x4, %rbp
addq %r8, %rbp
movabsq $0xf0f0f0f0f0f0f0f, %rsi # imm = 0xF0F0F0F0F0F0F0F
andq %rsi, %rbp
movabsq $0x101010101010101, %rcx # imm = 0x101010101010101
imulq %rcx, %rbp
shrq $0x38, %rbp
cmpl %r11d, %ebp
jae 0xbcac
notq %r13
andq %rax, %r13
testq %rbx, %r13
movq -0x30(%rsp), %r8
movq -0x20(%rsp), %rsi
movq -0x28(%rsp), %rcx
jne 0xbc69
movq -0x18(%rsp), %r8
leaq 0x11b43f(%rip), %r13    # 0x127080
addq %r13, %r8
testq %rbx, (%r8,%r12,8)
movq -0x30(%rsp), %r8
je 0xbc69
movl 0x24(%rdi,%rdx,4), %ebx
cmpl $0x2, %r11d
jne 0xbcc4
addl $-0xf, %ebx
jmp 0xbc65
movl 0x24(%rdi,%rdx,4), %ebx
addl $0x14, %ebx
movl %ebx, 0x24(%rdi,%rdx,4)
movq (%r9), %r11
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
testq %rax, %r11
je 0xbc8e
subl %ecx, %r12d
leaq 0x11b200(%rip), %rbx    # 0x126e80
andq (%rbx,%r12,8), %rax
movl $0xa, %ebx
testq %r11, %rax
je 0xbc92
addl %ebx, 0x24(%rdi,%rdx,4)
andq %r14, %r11
leaq -0x1(%r11), %rax
testq %rax, %r11
je 0xbca3
addl $-0x5, 0x24(%rdi,%rdx,4)
addq $0x4, %r10
jmp 0xbae2
movl 0x24(%rdi,%rdx,4), %ebx
addl $0xa, %ebx
movq -0x30(%rsp), %r8
movq -0x20(%rsp), %rsi
movq -0x28(%rsp), %rcx
jmp 0xbc65
addl $-0x5, %ebx
jmp 0xbc65
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq