// File: ATOMIC-LICHESS[P]ATOMKRAFT/pawns.cpp
// Function: PawnInfoTable::get_pawn_info(Position const&) const
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {

  assert(pos.is_ok());

  Key key = pos.get_pawn_key();
  PawnInfo* pi = probe(key);

  // If pi->key matches the position's pawn hash key, it means that we
  // have analysed this pawn structure before, and we can simply return
  // the information we found the last time instead of recomputing it.
  if (pi->key == key)
      return pi;

  // Initialize PawnInfo entry
  pi->key = key;
  pi->passedPawns[WHITE] = pi->passedPawns[BLACK] = 0;
  pi->kingSquares[WHITE] = pi->kingSquares[BLACK] = SQ_NONE;
  pi->halfOpenFiles[WHITE] = pi->halfOpenFiles[BLACK] = 0xFF;

  // Calculate pawn attacks
  Bitboard wPawns = pos.pieces(PAWN, WHITE);
  Bitboard bPawns = pos.pieces(PAWN, BLACK);
  pi->pawnAttacks[WHITE] = ((wPawns << 9) & ~FileABB) | ((wPawns << 7) & ~FileHBB);
  pi->pawnAttacks[BLACK] = ((bPawns >> 7) & ~FileABB) | ((bPawns >> 9) & ~FileHBB);

  // Evaluate pawns for both colors and weight the result
  pi->value =  evaluate_pawns<WHITE>(pos, wPawns, bPawns, pi)
             - evaluate_pawns<BLACK>(pos, bPawns, wPawns, pi);

  pi->value = apply_weight(pi->value, PawnStructureWeight);

  return pi;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x34c20
movq 0x8(%rsp), %rdi
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rsi
callq 0x34c40
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpq 0x28(%rsp), %rax
jne 0x34a29
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x34b8e
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x20(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x20(%rsp), %rax
movl $0x40, 0x2c(%rax)
movq 0x20(%rsp), %rax
movl $0x40, 0x28(%rax)
movq 0x20(%rsp), %rax
movl $0xff, 0x38(%rax)
movq 0x20(%rsp), %rax
movl $0xff, 0x34(%rax)
movq 0x30(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x16530
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x16530
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rcx
shlq $0x9, %rcx
movabsq $-0x101010101010102, %rax # imm = 0xFEFEFEFEFEFEFEFE
andq %rax, %rcx
movq 0x18(%rsp), %rax
shlq $0x7, %rax
movabsq $0x7f7f7f7f7f7f7f7f, %rdx # imm = 0x7F7F7F7F7F7F7F7F
andq %rdx, %rax
orq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rcx
shrq $0x7, %rcx
movabsq $-0x101010101010102, %rax # imm = 0xFEFEFEFEFEFEFEFE
andq %rax, %rcx
movq 0x10(%rsp), %rax
shrq $0x9, %rax
movabsq $0x7f7f7f7f7f7f7f7f, %rdx # imm = 0x7F7F7F7F7F7F7F7F
andq %rdx, %rax
orq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x34c70
movl %eax, 0x4(%rsp)
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x350e0
movl 0x4(%rsp), %edi
movl %eax, %esi
callq 0x29740
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x30(%rax)
movq 0x20(%rsp), %rax
movl 0x30(%rax), %edi
movl 0x3ae5eb(%rip), %esi    # 0x3e3160
callq 0x34ba0
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x30(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax,%rax)