// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/position.cpp
// Function: CheckInfo::CheckInfo(Position const&)
CheckInfo::CheckInfo(const Position& pos) {

  Color us = pos.side_to_move();
  Color them = opposite_color(us);
  
  STARTNEW
  // FIXME: this cuts the possibility of detecting errors
  // but seems to be the easiest way to handle calls in qsearch and search
  if (pos.piece_count(them, KING) == 0 || pos.piece_count(us, KING) == 0) {
	  return;
  }
  ENDNEW
  
  NEW assert(pos.piece_count(them, KING));
  NEW assert(pos.piece_count(us, KING));
  NEW Square us_ksq = pos.king_square(us);
  ksq = pos.king_square(them);
  dcCandidates = pos.discovered_check_candidates(us);
  
  STARTNEW if (squares_touch[ksq][us_ksq]) {
	  checkSq[PAWN] 	= EmptyBoardBB;
	  checkSq[KNIGHT] 	= EmptyBoardBB;
	  checkSq[BISHOP] 	= EmptyBoardBB;
	  checkSq[ROOK] 	= EmptyBoardBB;
	  checkSq[QUEEN] 	= EmptyBoardBB;
	  checkSq[KING] 	= EmptyBoardBB;
  ENDNEW } else {
	  checkSq[PAWN] 	= pos.attacks_from<PAWN>(ksq, them);
	  checkSq[KNIGHT] 	= pos.attacks_from<KNIGHT>(ksq);
	  checkSq[BISHOP] 	= pos.attacks_from<BISHOP>(ksq);
	  checkSq[ROOK] 	= pos.attacks_from<ROOK>(ksq);
	  checkSq[QUEEN] 	= checkSq[BISHOP] | checkSq[ROOK];
	  checkSq[KING] 	= EmptyBoardBB;
  NEW }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl 0x1090(%rsi), %esi
movq %rsi, %r15
xorq $0x1, %r15
movq %r15, %rax
shlq $0x5, %rax
cmpl $0x0, 0x168(%r14,%rax)
je 0x1cc50
leaq 0x150(%r14), %rax
movq %rsi, %rcx
shlq $0x5, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
je 0x1cc50
movq %rdi, %rbx
movq %rsi, %rax
shlq $0x9, %rax
movslq 0x310(%r14,%rax), %r12
movq %r15, %rax
shlq $0x9, %rax
movl 0x310(%r14,%rax), %eax
movl %eax, 0x48(%rdi)
movq %r14, %rdi
callq 0x21464
movq %rax, (%rbx)
movslq 0x48(%rbx), %rax
movq %rax, %rcx
shlq $0x6, %rcx
addq 0x20428(%rip), %rcx     # 0x3cf78
cmpb $0x0, (%r12,%rcx)
je 0x1cb6b
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
jmp 0x1cc50
leal 0x1(,%r15,8), %ecx
shlq $0x9, %rcx
leaq 0xfcbd2(%rip), %rdx     # 0x119750
leaq (%rdx,%rax,8), %rsi
movq (%rcx,%rsi), %rcx
movq %rcx, 0x10(%rbx)
movq 0x400(%rdx,%rax,8), %rcx
movq %rcx, 0x18(%rbx)
leaq 0xf1f03(%rip), %rcx     # 0x10eaa0
movq (%rcx,%rax,8), %rcx
andq 0x100(%r14), %rcx
leaq 0x12811(%rip), %rdx     # 0x2f3c0
movq (%rdx,%rax,8), %rdx
movl %edx, %esi
imull %ecx, %esi
shrq $0x20, %rcx
shrq $0x20, %rdx
imull %ecx, %edx
xorl %esi, %edx
leaq 0x12bf4(%rip), %rcx     # 0x2f7c0
movb (%rcx,%rax,4), %cl
shrl %cl, %edx
leaq 0xf20c8(%rip), %rcx     # 0x10eca0
addl (%rcx,%rax,4), %edx
leaq 0xf21be(%rip), %rcx     # 0x10eda0
movq (%rcx,%rdx,8), %rdx
movq %rdx, 0x20(%rbx)
leaq 0x29baf(%rip), %rcx     # 0x467a0
movq (%rcx,%rax,8), %rcx
andq 0x100(%r14), %rcx
leaq 0x29d9d(%rip), %rsi     # 0x469a0
leaq 0x129b6(%rip), %rdi     # 0x2f5c0
movq (%rdi,%rax,8), %rdi
movl %edi, %r8d
imull %ecx, %r8d
shrq $0x20, %rcx
shrq $0x20, %rdi
imull %ecx, %edi
xorl %r8d, %edi
leaq 0x12c96(%rip), %rcx     # 0x2f8c0
movb (%rcx,%rax,4), %cl
shrl %cl, %edi
addl (%rsi,%rax,4), %edi
leaq 0x29e67(%rip), %rax     # 0x46aa0
movq (%rax,%rdi,8), %rax
movq %rax, 0x28(%rbx)
orq %rdx, %rax
movq %rax, 0x30(%rbx)
movq $0x0, 0x38(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq