// File: ATOMIC-LICHESS[P]ATOMKRAFT/evaluate.cpp
// Function: void (anonymous namespace)::init_eval_info<(Color)0, false>(Position const&, (anonymous namespace)::EvalInfo&)
void init_eval_info(const Position& pos, EvalInfo& ei) {

    const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : CpuIs64Bit ? CNT64_MAX15 : CNT32_MAX15;
    const Color Them = (Us == WHITE ? BLACK : WHITE);

    Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
    ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
    
    STARTNEW
    // init halfOpenFiles for minor pieces
	// this is done analog to pi->halfOpenFiles
    ei.halfOpenFiles_mp[WHITE] = ei.halfOpenFiles_mp[BLACK] = 0xFF;
    
    Square s;
    
    const Square* ptr = pos.piece_list_begin(Us, KNIGHT);
    while ((s = *ptr++) != SQ_NONE) {
		ei.halfOpenFiles_mp[Us] &= ~(1 << square_file(s));
    }
    
    ptr = pos.piece_list_begin(Us, BISHOP);
    while ((s = *ptr++) != SQ_NONE) {
		ei.halfOpenFiles_mp[Us] &= ~(1 << square_file(s));
    }
    ENDNEW

    // Init king safety tables only if we are going to use them
    if (   pos.piece_count(Us, QUEEN)
        && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame)
    {
        ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8));
        b &= ei.attackedBy[Us][PAWN];
        ei.kingAttackersCount[Us] = b ? count_1s<Max15>(b) / 2 : 0;
        ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0;
    } else
        ei.kingZone[Us] = ei.kingAttackersCount[Us] = 0;
  }

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl $0x3, 0x34(%rsp)
movl $0x1, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x1b440
movq 0x38(%rsp), %rcx
movq %rax, 0x80(%rcx)
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x299b0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rax
movl $0xff, 0xbc(%rax)
movq 0x38(%rsp), %rax
movl $0xff, 0xb8(%rax)
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x299d0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %eax
movl %eax, 0x24(%rsp)
cmpl $0x40, %eax
je 0x201da
movl 0x24(%rsp), %edi
callq 0xce10
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movq 0x38(%rsp), %rax
andl 0xb8(%rax), %ecx
movl %ecx, 0xb8(%rax)
jmp 0x20194
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x299d0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %eax
movl %eax, 0x24(%rsp)
cmpl $0x40, %eax
je 0x20236
movl 0x24(%rsp), %edi
callq 0xce10
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movq 0x38(%rsp), %rax
andl 0xb8(%rax), %ecx
movl %ecx, 0xb8(%rax)
jmp 0x201f0
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x164c0
cmpl $0x0, %eax
je 0x2030c
movq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x298e0
movl %eax, 0xc(%rsp)
leaq 0x4c311(%rip), %rax     # 0x6c578
movl (%rax), %edi
leaq 0x4c300(%rip), %rax     # 0x6c570
movl (%rax), %esi
callq 0x1b320
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jl 0x2030c
movq 0x28(%rsp), %rcx
movq 0x28(%rsp), %rax
shrq $0x8, %rax
orq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x90(%rax)
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
andq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x202d5
movq 0x28(%rsp), %rdi
callq 0x29a00
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x8(%rsp)
jmp 0x202dd
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0x202dd
movl 0x8(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0xa0(%rax)
movq 0x38(%rsp), %rax
movl $0x0, 0xa8(%rax)
movq 0x38(%rsp), %rax
movl $0x0, 0xb0(%rax)
jmp 0x2032b
movq 0x38(%rsp), %rax
movl $0x0, 0xa0(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x90(%rax)
addq $0x48, %rsp
retq