// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, -0x8(%rsp)
movq %r8, -0x18(%rsp)
leaq (%r8,%r8,2), %r8
shll $0x4, %r8d
addq %rax, %r8
addq $0x288, %r8             # imm = 0x288
leaq (%rdx,%rdx,2), %r9
shlq $0x4, %r9
addq %rax, %r9
addq $0x288, %r9             # imm = 0x288
movq $-0x28, %r10
movq %rdx, %rax
shlq $0x9, %rax
leaq 0x10bbac(%rip), %r15    # 0x119e70
addq %rax, %r15
leaq 0xeada2(%rip), %rsi     # 0xf9070
movq %rax, -0x20(%rsp)
addq %rax, %rsi
movq %rsi, -0x10(%rsp)
movq %r8, -0x28(%rsp)
movq %rcx, -0x30(%rsp)
movq -0x8(%rsp), %rax
movl 0x28(%rax,%r10), %r14d
cmpq $0x40, %r14
je 0xe4c0
addl $0x64, 0x2c(%rdi,%rdx,4)
leaq 0xea96b(%rip), %rax     # 0xf8c70
movq (%rax,%r14,8), %rbp
leaq 0x10b960(%rip), %rax    # 0x119c70
movq (%rax,%r14,8), %r12
movq %r12, %rbx
orq %rbp, %rbx
movq (%r15,%r14,8), %rax
movq (%r8), %r11
andq %rax, %rbx
testq %r11, %rbx
je 0xe452
movq %r11, %rbx
andq %rax, %rbx
testq %rbp, %rbx
jne 0xe45d
leal (%r14,%rcx), %ebx
movq -0x10(%rsp), %rsi
andq (%rsi,%rbx,8), %r11
je 0xe45d
movq %r11, %r13
shrq %r13
movabsq $0x5555555555555555, %rsi # imm = 0x5555555555555555
andq %rsi, %r13
subq %r13, %r11
movq %r11, %r13
movabsq $0x3333333333333333, %r8 # imm = 0x3333333333333333
andq %r8, %r13
shrq $0x2, %r11
andq %r8, %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 0x16bf9(%rip), %rsi     # 0x24fb0
movq (%r9), %r11
movq (%rsi,%rbx,8), %rsi
andq %r11, %rsi
movq %rsi, %rbx
shrq %rbx
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
andq %rcx, %rbx
subq %rbx, %rsi
movq %rsi, %rbx
andq %r8, %rbx
shrq $0x2, %rsi
andq %r8, %rsi
addq %rbx, %rsi
movq %rsi, %rbx
shrq $0x4, %rbx
addq %rsi, %rbx
movabsq $0xf0f0f0f0f0f0f0f, %rsi # imm = 0xF0F0F0F0F0F0F0F
andq %rsi, %rbx
movabsq $0x101010101010101, %rcx # imm = 0x101010101010101
imulq %rcx, %rbx
shrq $0x38, %rbx
cmpl %r13d, %ebx
jae 0xe4a8
notq %rax
andq %r12, %rax
testq %r11, %rax
movq -0x28(%rsp), %r8
movq -0x30(%rsp), %rcx
jne 0xe45d
movq -0x20(%rsp), %rax
leaq 0xeac36(%rip), %rsi     # 0xf9070
addq %rsi, %rax
testq %r11, (%rax,%r14,8)
je 0xe45d
movl 0x24(%rdi,%rdx,4), %eax
cmpl $0x2, %r13d
jne 0xe4bb
addl $-0xf, %eax
jmp 0xe459
movl 0x24(%rdi,%rdx,4), %eax
addl $0x14, %eax
movl %eax, 0x24(%rdi,%rdx,4)
movq (%r9), %rax
testq %r12, %rax
je 0xe480
subl %ecx, %r14d
leaq 0xeaa01(%rip), %rsi     # 0xf8e70
andq (%rsi,%r14,8), %r12
movl $0xa, %r11d
testq %rax, %r12
jne 0xe486
jmp 0xe48b
movl $0xfffffff6, %r11d      # imm = 0xFFFFFFF6
addl %r11d, 0x24(%rdi,%rdx,4)
andq %rbp, %rax
leaq -0x1(%rax), %rsi
testq %rsi, %rax
je 0xe49c
addl $-0x5, 0x24(%rdi,%rdx,4)
addq $0x4, %r10
jne 0xe2e5
jmp 0xe4c0
movl 0x24(%rdi,%rdx,4), %eax
addl $0xa, %eax
movq -0x28(%rsp), %r8
movq -0x30(%rsp), %rcx
jmp 0xe459
addl $-0x5, %eax
jmp 0xe459
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop