// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movl %esi, 0xac(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x78(%rsp)
movl 0xac(%rsp), %esi
movl $0xfffffff8, %ecx       # imm = 0xFFFFFFF8
movl $0x8, %edx
cmpl $0x0, %esi
cmovel %edx, %ecx
movl %ecx, 0xa8(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24d80
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x24dc0
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x24dd0
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rax
cmpq 0x90(%rsp), %rax
je 0x225fe
movq 0x98(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x8c(%rsp)
cmpl $0x40, 0x8c(%rsp)
jne 0x22129
jmp 0x225fe
movq 0x78(%rsp), %rdi
addq $0x2c, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movq %rax, %rcx
movq 0x78(%rsp), %rax
movl (%rcx), %edx
addl $0x64, %edx
movl %edx, (%rcx)
movl 0x8c(%rsp), %ecx
movl %ecx, %edx
leaq 0x132bb1(%rip), %rcx    # 0x154d10
movq (%rcx,%rdx,8), %rcx
movl 0x8c(%rsp), %edx
movl %edx, %esi
leaq 0x153b9d(%rip), %rdx    # 0x175d10
orq (%rdx,%rsi,8), %rcx
movl 0xac(%rsp), %edx
movl %edx, %esi
leaq 0x153d89(%rip), %rdx    # 0x175f10
shlq $0x9, %rsi
addq %rsi, %rdx
movl 0x8c(%rsp), %esi
andq (%rdx,%rsi,8), %rcx
movq %rcx, 0x70(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x68(%rsp)
movl 0xac(%rsp), %edi
callq 0x24ce0
movq 0x68(%rsp), %rdi
movl %eax, %esi
callq 0x24b80
movq %rax, %rcx
movq 0x70(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x221f3
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $0x14, %ecx
movl %ecx, (%rax)
jmp 0x224a0
movq 0x78(%rsp), %rax
movl 0x8c(%rsp), %ecx
movl %ecx, %edx
leaq 0x132b08(%rip), %rcx    # 0x154d10
movq (%rcx,%rdx,8), %rcx
movl 0xac(%rsp), %edx
movl %edx, %esi
leaq 0x153cf4(%rip), %rdx    # 0x175f10
shlq $0x9, %rsi
addq %rsi, %rdx
movl 0x8c(%rsp), %esi
andq (%rdx,%rsi,8), %rcx
movq %rcx, 0x60(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x58(%rsp)
movl 0xac(%rsp), %edi
callq 0x24ce0
movq 0x58(%rsp), %rdi
movl %eax, %esi
callq 0x24b80
movq %rax, %rcx
movq 0x60(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x2249e
movl 0xac(%rsp), %eax
movl %eax, %ecx
leaq 0x132e97(%rip), %rax    # 0x155110
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movl 0x8c(%rsp), %edi
movl 0xa8(%rsp), %esi
callq 0x24e60
movq 0x40(%rsp), %rcx
movl %eax, %edx
movq 0x78(%rsp), %rax
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x50(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movl 0xac(%rsp), %edi
callq 0x24ce0
movq 0x48(%rsp), %rdi
movl %eax, %esi
callq 0x24b80
movq 0x50(%rsp), %rdi
andq %rax, %rdi
callq 0x24df0
movl %eax, 0x88(%rsp)
cmpl $0x0, 0x88(%rsp)
jle 0x2249c
movl 0xac(%rsp), %edi
callq 0x24ce0
movl %eax, %eax
movl %eax, %ecx
leaq 0x132e07(%rip), %rax    # 0x155110
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movl 0x8c(%rsp), %edi
movl 0xa8(%rsp), %esi
callq 0x24e60
movq 0x30(%rsp), %rcx
movl %eax, %edx
movq 0x78(%rsp), %rax
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq 0x38(%rsp), %rdi
andq %rax, %rdi
callq 0x24df0
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0x88(%rsp), %eax
jl 0x22396
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $0xa, %ecx
movl %ecx, (%rax)
jmp 0x2249a
movq 0x78(%rsp), %rax
movl 0xac(%rsp), %ecx
movl %ecx, %edx
leaq 0x153b65(%rip), %rcx    # 0x175f10
shlq $0x9, %rdx
addq %rdx, %rcx
movl 0x8c(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
xorq $-0x1, %rcx
movl 0x8c(%rsp), %edx
movl %edx, %esi
leaq 0x15393f(%rip), %rdx    # 0x175d10
andq (%rdx,%rsi,8), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq %rax, %rcx
movq 0x28(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x22498
movq 0x78(%rsp), %rax
movl 0xac(%rsp), %ecx
movl %ecx, %edx
leaq 0x132cfc(%rip), %rcx    # 0x155110
shlq $0x9, %rdx
addq %rdx, %rcx
movl 0x8c(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq %rax, %rcx
movq 0x20(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
je 0x22496
cmpl $0x2, 0x88(%rsp)
jne 0x22476
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $-0xf, %ecx
movl %ecx, (%rax)
jmp 0x22494
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $-0x5, %ecx
movl %ecx, (%rax)
jmp 0x22496
jmp 0x22498
jmp 0x2249a
jmp 0x2249c
jmp 0x2249e
jmp 0x224a0
movq 0x78(%rsp), %rax
movl 0x8c(%rsp), %ecx
movl %ecx, %edx
leaq 0x15385b(%rip), %rcx    # 0x175d10
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq %rax, %rcx
movq 0x18(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x22502
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $-0xa, %ecx
movl %ecx, (%rax)
jmp 0x22585
movl 0x8c(%rsp), %edi
movl 0xa8(%rsp), %esi
callq 0x24e80
movl %eax, %ecx
movq 0x78(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x1329e9(%rip), %rcx    # 0x154f10
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq %rax, %rcx
movq 0x10(%rsp), %rax
andq %rcx, %rax
movl 0x8c(%rsp), %ecx
movl %ecx, %edx
leaq 0x1537b5(%rip), %rcx    # 0x175d10
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x22583
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $0xa, %ecx
movl %ecx, (%rax)
jmp 0x22585
movq 0x78(%rsp), %rax
movl 0x8c(%rsp), %ecx
movl %ecx, %edx
leaq 0x132776(%rip), %rcx    # 0x154d10
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%rax), %rdi
movl 0xac(%rsp), %esi
callq 0x24b80
movq 0x8(%rsp), %rdi
andq %rax, %rdi
callq 0x24df0
cmpl $0x1, %eax
jle 0x225e3
movq 0x78(%rsp), %rdi
addq $0x24, %rdi
movl 0xac(%rsp), %eax
movl %eax, %esi
callq 0x24cb0
movl (%rax), %ecx
addl $-0x5, %ecx
movl %ecx, (%rax)
jmp 0x225e5
movq 0x98(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x98(%rsp)
jmp 0x220f3
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)