// File: ATOMIC-LICHESS[P]ATOMKRAFT/position.cpp
// Function: Position::find_checkers()
void Position::find_checkers() {
  Color us = side_to_move();
  OLD st->checkersBB = attackers_to(king_square(us)) & pieces_of_color(opposite_color(us));
  
  STARTNEW
  if (piece_count(us, KING)) {
	  Square ksq = king_square(us);
	  assert(piece_count(opposite_color(us), KING));
	  Square opp_ksq = king_square(opposite_color(us));
	  
	  // if both kings directly face each other there is no check
	  if (squares_touch[ksq][opp_ksq]) {
		  st->checkersBB = EmptyBoardBB;
		  return;
	  }
	  
	  Bitboard att_to =   (attacks_from<PAWN>(ksq, BLACK) & pieces(PAWN, WHITE))
                		| (attacks_from<PAWN>(ksq, WHITE) & pieces(PAWN, BLACK))
                		| (attacks_from<KNIGHT>(ksq)      & pieces(KNIGHT))
                		| (attacks_from<ROOK>(ksq)        & pieces(ROOK, QUEEN))
                		| (attacks_from<BISHOP>(ksq)      & pieces(BISHOP, QUEEN));
	  
	  st->checkersBB = att_to & pieces_of_color(opposite_color(us));
  } else {
	  st->checkersBB = EmptyBoardBB;
  }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xf5d0
movq 0x50(%rsp), %rdi
movl %eax, 0x6c(%rsp)
movl 0x6c(%rsp), %esi
movl $0x6, %edx
callq 0x164c0
cmpl $0x0, %eax
je 0x37613
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x1b250
movl %eax, 0x68(%rsp)
movl 0x6c(%rsp), %edi
callq 0x122b0
movq 0x50(%rsp), %rdi
movl %eax, %esi
callq 0x1b250
movl %eax, 0x64(%rsp)
movslq 0x68(%rsp), %rcx
leaq 0x36421(%rip), %rax     # 0x6d8a0
shlq $0x6, %rcx
addq %rcx, %rax
movslq 0x64(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x374aa
movq 0x50(%rsp), %rax
movq 0x1938(%rax), %rax
movq $0x0, 0x40(%rax)
jmp 0x37627
movq 0x50(%rsp), %rdi
movl 0x68(%rsp), %esi
movl $0x1, %edx
callq 0x1b460
movq 0x50(%rsp), %rdi
movq %rax, (%rsp)
movl $0x1, %esi
xorl %edx, %edx
callq 0x16530
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movq (%rsp), %rax
andq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0x68(%rsp), %esi
xorl %edx, %edx
callq 0x1b460
movq 0x50(%rsp), %rdi
movq %rax, 0x8(%rsp)
movl $0x1, %edx
movl %edx, %esi
callq 0x16530
movq 0x8(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq %rax, %rdx
movq 0x10(%rsp), %rax
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x68(%rsp), %esi
callq 0x29aa0
movq 0x50(%rsp), %rdi
movq %rax, 0x18(%rsp)
movl $0x2, %esi
callq 0x33a70
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq %rax, %rdx
movq 0x20(%rsp), %rax
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x30(%rsp)
movl 0x68(%rsp), %esi
callq 0x29d40
movq 0x50(%rsp), %rdi
movq %rax, 0x28(%rsp)
movl $0x4, %esi
movl $0x5, %edx
callq 0x33a90
movq 0x28(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq %rax, %rdx
movq 0x30(%rsp), %rax
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x40(%rsp)
movl 0x68(%rsp), %esi
callq 0x1b550
movq 0x50(%rsp), %rdi
movq %rax, 0x38(%rsp)
movl $0x3, %esi
movl $0x5, %edx
callq 0x33a90
movq 0x38(%rsp), %rcx
movq %rax, %rdx
movq 0x40(%rsp), %rax
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x6c(%rsp), %edi
callq 0x122b0
movq 0x50(%rsp), %rdi
movl %eax, %esi
callq 0x298c0
movq 0x48(%rsp), %rcx
movq %rax, %rdx
movq 0x50(%rsp), %rax
andq %rdx, %rcx
movq 0x1938(%rax), %rax
movq %rcx, 0x40(%rax)
jmp 0x37627
movq 0x50(%rsp), %rax
movq 0x1938(%rax), %rax
movq $0x0, 0x40(%rax)
addq $0x78, %rsp
retq
nopl (%rax)