LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/bitboard.cpp
// Function: (anonymous namespace)::sliding_attacks(int, unsigned long, int (*) [2], int, int, int, int)
Bitboard sliding_attacks(int sq, Bitboard occupied, int deltas[][2],
                           int fmin, int fmax, int rmin, int rmax) {
    int dx, dy, f, r;
    int rk = sq / 8;
    int fl = sq % 8;
    Bitboard attacks = EmptyBoardBB;

    for (int i = 0; i < 4; i++)
    {
        dx = deltas[i][0];
        dy = deltas[i][1];
        f = fl + dx;
        r = rk + dy;

        while (   (dx == 0 || (f >= fmin && f <= fmax))
               && (dy == 0 || (r >= rmin && r <= rmax)))
        {
            attacks |= (1ULL << (f + r * 8));

            if (occupied & (1ULL << (f + r * 8)))
                break;

            f += dx;
            r += dy;
        }
    }
    return attacks;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x8(%rsp)
movl 0x38(%rsp), %edx
leal 0x7(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %r10d
sarl $0x3, %r10d
movq %r10, -0x10(%rsp)
andl $-0x8, %eax
subl %eax, %edi
xorl %ebx, %ebx
xorl %eax, %eax
movq -0x8(%rsp), %r10
movl (%r10,%rbx,8), %r14d
movl 0x4(%r10,%rbx,8), %r15d
leal (%rdi,%r14), %r12d
movq -0x10(%rsp), %r10
leal (%r10,%r15), %r13d
leal (%r12,%r13,8), %r11d
leal (%r14,%r15,8), %ebp
testl %r14d, %r14d
je 0x8b39
cmpl %ecx, %r12d
jl 0x8b61
cmpl %r8d, %r12d
jg 0x8b61
testl %r15d, %r15d
je 0x8b48
cmpl %r9d, %r13d
jl 0x8b61
cmpl %edx, %r13d
jg 0x8b61
btsq %r11, %rax
movl %r11d, %r10d
addl %ebp, %r10d
addl %r15d, %r13d
addl %r14d, %r12d
btq %r11, %rsi
movl %r10d, %r11d
jae 0x8b2a
incq %rbx
cmpq $0x4, %rbx
jne 0x8b07
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::Book()
Book::Book() {

  OLD for (int i = abs(get_system_time() % 10000); i > 0; i--)
      RKiss.rand<unsigned>();
  
  STARTNEW
  // in our implementation get_system_time returns the milliseconds since program start 
  for (int i = abs(rand() % 10000); i > 0; i--)
        RKiss.rand<unsigned>();
  ENDNEW
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x54b0
leaq 0x220(%rbx), %rax
movq %rax, 0x210(%rbx)
movq $0x0, 0x218(%rbx)
movb $0x0, 0x220(%rbx)
movabsq $0x46dd577ff603b540, %rax # imm = 0x46DD577FF603B540
movq %rax, 0x238(%rbx)
movabsq $-0x3bf8842205306785, %rax # imm = 0xC4077BDDFACF987B
movq %rax, 0x240(%rbx)
movabsq $-0x440b26c48dff17a8, %rax # imm = 0xBBF4D93B7200E858
movq %rax, 0x248(%rbx)
movabsq $-0x2c1f8a302bb644e2, %rax # imm = 0xD3E075CFD449BB1E
movq %rax, 0x250(%rbx)
callq 0x5100
movslq %eax, %r8
imulq $0x68db8bad, %r8, %rax  # imm = 0x68DB8BAD
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x2c, %rax
addl %ecx, %eax
imull $0x2710, %eax, %eax     # imm = 0x2710
subl %eax, %r8d
je 0x8d98
movq 0x250(%rbx), %rax
movq 0x248(%rbx), %rcx
movq 0x238(%rbx), %rsi
movq 0x240(%rbx), %rdx
movl %r8d, %edi
negl %edi
cmpl %edi, %r8d
cmovgl %r8d, %edi
incl %edi
movq %rdx, %r8
rolq $0x7, %r8
movq %rsi, %r9
movq %rcx, %rsi
rolq $0xd, %rsi
xorq %rdx, %rsi
movq %rax, %rdx
rolq $0x25, %rdx
subq %r8, %r9
addq %rcx, %rdx
movq %rax, %rcx
addq %r9, %rcx
movq %r9, %rax
addq %rsi, %rax
decl %edi
cmpl $0x1, %edi
ja 0x8d48
movq %rsi, 0x238(%rbx)
movq %rdx, 0x240(%rbx)
movq %rcx, 0x248(%rbx)
movq %rax, 0x250(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Book::open(const string& fileName) {

  // Close old file before opening the new
  close();
  
  OLD bookFile.open(fileName.c_str(), ifstream::in | ifstream::binary);
  NEW bookFile.open(fileName.c_str(), 
		  ifstream::in | ifstream::binary | ofstream::binary | ofstream::out);

  // Silently return when asked to open a non-exsistent file
  if (!bookFile.is_open())
      return;

  // Get the book size in number of entries
  bookFile.seekg(0, ios::end);
  bookSize = long(bookFile.tellg()) / sizeof(BookEntry);

  if (!bookFile.good())
  {
      cerr << "Failed to open book file " << fileName << endl;
      exit(EXIT_FAILURE);
  }

  // Set only if successful
  bookName = fileName;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8dd2
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x1c, %edx
callq 0x5360
leaq 0x80(%r14), %rdi
callq 0x50e0
testb %al, %al
je 0x8e8b
movq %r14, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x5560
movq %r14, %rdi
callq 0x5770
shrq $0x4, %rax
movl %eax, 0x230(%r14)
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x8e93
addq $0x210, %r14            # imm = 0x210
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x5200
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x34156(%rip), %rdi     # 0x3cff0
leaq 0x28737(%rip), %rsi     # 0x315d8
callq 0x53d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5350
movq %rax, %rdi
callq 0x51c0
movl $0x1, %edi
callq 0x54e0
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::find_entry(unsigned long)
int Book::find_entry(uint64_t key) {

  int left, right, mid;

  // Binary search (finds the leftmost entry)
  left = 0;
  right = bookSize - 1;

  assert(left <= right);

  while (left < right)
  {
      mid = (left + right) / 2;

      assert(mid >= left && mid < right);

      if (key <= read_entry(mid).key)
          right = mid;
      else
          left = mid + 1;
  }

  assert(left == right);

  return read_entry(left).key == key ? left : bookSize;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl 0x230(%rdi), %r12d
xorl %r15d, %r15d
cmpl $0x2, %r12d
jl 0x90aa
decl %r12d
xorl %r15d, %r15d
leal (%r15,%r12), %ebp
shrl %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x90ce
cmpq %r14, %rax
jb 0x90a0
movl %ebp, %r12d
jmp 0x90a5
incl %ebp
movl %ebp, %r15d
cmpl %r12d, %r15d
jl 0x9086
movq %rbx, %rdi
movl %r15d, %esi
callq 0x90ce
cmpq %r14, %rax
je 0x90c1
movl 0x230(%rbx), %r15d
movl %r15d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::read_entry(int)
BookEntry Book::read_entry(int idx) {

  assert(idx >= 0 && idx < bookSize);
  assert(bookFile.is_open());

  BookEntry e;

  bookFile.seekg(idx * sizeof(BookEntry), ios_base::beg);

  get_number(e.key);
  get_number(e.move);
  get_number(e.count);
  get_number(e.learn);

  if (!bookFile.good())
  {
      cerr << "Failed to read book entry at index " << idx << endl;
      exit(EXIT_FAILURE);
  }
  return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
movl %esi, 0x4(%rsp)
movslq %esi, %rsi
shlq $0x4, %rsi
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x5560
movl $0x8, %r12d
movq %r14, %r13
shlq $0x8, %r13
movq %r15, %rdi
callq 0x54c0
movslq %eax, %r14
addq %r13, %r14
decq %r12
jne 0x90f7
movb $0x1, %r13b
xorl %ebp, %ebp
movzwl %bp, %r12d
shll $0x8, %r12d
movq %r15, %rdi
callq 0x54c0
movl %eax, %ebp
addl %r12d, %ebp
xorl %r12d, %r12d
testb $0x1, %r13b
movl $0x0, %r13d
jne 0x9116
movb $0x1, %r13b
movzwl %r12w, %ebx
shll $0x8, %ebx
movq %r15, %rdi
callq 0x54c0
movl %eax, %r12d
addl %ebx, %r12d
xorl %eax, %eax
testb $0x1, %r13b
movl $0x0, %r13d
jne 0x913d
movl $0x4, %r13d
movl %eax, %ebx
shll $0x8, %ebx
movq %r15, %rdi
callq 0x54c0
addl %ebx, %eax
decq %r13
jne 0x9166
movq (%r15), %rcx
movq -0x18(%rcx), %rcx
cmpl $0x0, 0x20(%r15,%rcx)
jne 0x91ac
shlq $0x20, %rax
shll $0x10, %r12d
orq %rax, %r12
movzwl %bp, %edx
orq %r12, %rdx
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x33e3d(%rip), %rdi     # 0x3cff0
leaq 0x28438(%rip), %rsi     # 0x315f2
callq 0x53d0
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0x5760
movq %rax, %rdi
callq 0x51c0
movl $0x1, %edi
callq 0x54e0
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::write_entry(unsigned long, Move, unsigned short)
void Book::write_entry(uint64_t key, Move move, uint16_t count) {
	// convert Move to polyglot move
	uint16_t m = make_move(move_from(move), move_to(move)) | (move_promotion_piece(move) << 12);
	uint32_t learn = 0;
	
	write_number(key);
	write_number(m);
	write_number(count);
	write_number(learn);
	
	++bookSize;
	
	if (!bookFile.good()) {
		cerr << "Failed to write book." << endl;
		exit(EXIT_FAILURE);
	}
	
//	bookFile.flush();
//	
//	if (!bookFile.good()) {
//		cerr << "Failed to flush book." << endl;
//		exit(EXIT_FAILURE);
//	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, 0x4(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movl %edx, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %edx, %ecx
andl $0xc000, %ecx           # imm = 0xC000
andl $0x3000, %edx           # imm = 0x3000
addl $0x2000, %edx           # imm = 0x2000
xorl %ebx, %ebx
cmpl $0x4000, %ecx           # imm = 0x4000
cmovel %edx, %ebx
orl %eax, %ebx
leaq 0x10(%rdi), %r14
movl $0x8, %ebp
movq %rsp, %r13
movq %r12, %rax
shrq $0x38, %rax
movb %al, (%rsp)
shlq $0x8, %r12
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x5540
decq %rbp
jne 0x9227
movb $0x1, %bpl
leaq 0x1(%rsp), %r12
movb %bh, 0x1(%rsp)
shll $0x8, %ebx
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x5540
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x9252
movb $0x1, %bpl
leaq 0x2(%rsp), %r12
movl 0x4(%rsp), %ebx
movb %bh, 0x2(%rsp)
shll $0x8, %ebx
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x5540
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x9280
movl $0x4, %r12d
leaq 0x3(%rsp), %rbx
movb $0x0, 0x3(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5540
decq %r12
jne 0x92ad
incl 0x230(%r15)
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r15,%rax)
jne 0x92ec
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x33cfd(%rip), %rdi     # 0x3cff0
leaq 0x2831c(%rip), %rsi     # 0x31616
callq 0x53d0
movq %rax, %rdi
callq 0x51c0
movl $0x1, %edi
callq 0x54e0
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/book.cpp
// Function: Book::print_all_moves(Position const&)
void Book::print_all_moves(const Position& pos) {
	  if (!bookFile.is_open() || bookSize == 0) {
		  cout << "book is empty" << endl;
		  return;
	  }
	  

	  BookEntry entry;
	  uint64_t key = book_key(pos);
	  
	  
	  // Choose a book move among the possible moves for the given position
	  for (int idx = find_entry(key); idx < bookSize; idx++)
	  {
	      entry = read_entry(idx);
	      
	      if (entry.key != key)
	          break;
	      
	      cout << "(" << move_to_string(Move(entry.move)) << " " << entry.count << ") ";
	  }
	  cout << endl;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
addq $0x80, %rdi
callq 0x50e0
testb %al, %al
je 0x945d
cmpl $0x0, 0x230(%rbx)
je 0x945d
movq %r14, %rdi
callq 0x8b78
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x9062
cmpl 0x230(%rbx), %eax
jge 0x9420
movl %eax, %ebp
movq 0x33c2e(%rip), %r15     # 0x3cfa0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x90ce
cmpq %r14, %rax
jne 0x9420
movq %rdx, %r12
movl $0x1, %edx
movq %r15, %rdi
leaq 0x282a3(%rip), %rsi     # 0x3163a
callq 0x5460
movzwl %r12w, %esi
leaq 0x8(%rsp), %rdi
callq 0x1754c
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x5460
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x282f2(%rip), %rsi     # 0x316c0
callq 0x5460
shrl $0x10, %r12d
movq %r13, %rdi
movq %r12, %rsi
callq 0x5260
movl $0x2, %edx
movq %rax, %rdi
leaq 0x292f8(%rip), %rsi     # 0x326e9
callq 0x5460
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9412
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
incl %ebp
cmpl 0x230(%rbx), %ebp
jl 0x9372
movq 0x33b79(%rip), %rbx     # 0x3cfa0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x33b3c(%rip), %rbx     # 0x3cfa0
leaq 0x281c1(%rip), %rsi     # 0x3162c
movl $0xd, %edx
movq %rbx, %rdi
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5270
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x94cc
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/create_book.cpp
// Function: printTree(MoveTreeNode*)
void printTree(MoveTreeNode* node) {

	if (node->child_count == 0) {
		cout << endl;
		return;
	}

	// print first move
	cout << move_to_string(node->child[0]->ms.move) << " ";
	printTree(node->child[0]);

	// print following moves
	for (int k = 1; k < node->child_count; ++k) {
		// indentation
		for (int s = 0; s < node->depth; ++s) {
			cout << "     ";
		}

		// print moves
		cout << move_to_string(node->child[k]->ms.move) << " ";
		printTree(node->child[k]);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x0, 0xa8(%rdi)
je 0x9b8b
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movl 0xac(%rax), %esi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x1754c
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x33520(%rip), %rdi     # 0x3cfa0
callq 0x5460
leaq 0x27c34(%rip), %rsi     # 0x316c0
movl $0x1, %edx
movq %rax, %rdi
callq 0x5460
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ab4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x8(%rbx), %rdi
callq 0x9a3d
cmpl $0x2, 0xa8(%rbx)
jl 0x9b7c
movl $0x1, %ebp
movq 0x334ca(%rip), %r14     # 0x3cfa0
leaq 0x27bdf(%rip), %r15     # 0x316bc
leaq 0x27bdc(%rip), %r13     # 0x316c0
cmpl $0x0, 0xb8(%rbx)
jle 0x9b0c
xorl %r12d, %r12d
movl $0x5, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x5460
incl %r12d
cmpl 0xb8(%rbx), %r12d
jl 0x9af0
movq 0x8(%rbx,%rbp,8), %rax
movl 0xac(%rax), %esi
leaq 0x8(%rsp), %rdi
callq 0x1754c
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x5460
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x5460
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9b5f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x8(%rbx,%rbp,8), %rdi
callq 0x9a3d
incq %rbp
movslq 0xa8(%rbx), %rax
cmpq %rax, %rbp
jl 0x9ae4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3340e(%rip), %rbx     # 0x3cfa0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5270
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x9be2
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9bf4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/create_book.cpp
// Function: numberOfNodes(MoveTreeNode*)
int numberOfNodes(MoveTreeNode* node) {

	int sum = 0;

	for (int k = 0; k < node->child_count; ++k) {
		sum += numberOfNodes(node->child[k]);
	}

	// node->ms.score was set true or false, false means not playable
	if (node->ms.score) {
		node->ms.score = 1;//sum + 1;	// a move with score 0 will never be played
	}
	return sum + 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpl $0x0, 0xa8(%rdi)
jle 0x9c30
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x8(%rbx,%r14,8), %rdi
callq 0x9bfc
addl %eax, %ebp
incq %r14
movslq 0xa8(%rbx), %rax
cmpq %rax, %r14
jl 0x9c11
incl %ebp
jmp 0x9c35
movl $0x1, %ebp
cmpl $0x0, 0xb0(%rbx)
je 0x9c48
movl $0x1, 0xb0(%rbx)
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/create_book.cpp
// Function: write_entry(_IO_FILE*, unsigned long, Move, unsigned short)
void write_entry(FILE* file, uint64_t key, Move move, uint16_t count) {
	// convert Move to polyglot move
	uint16_t m = make_move(move_from(move), move_to(move)) | (move_promotion_piece(move) << 12);
	uint32_t learn = 0;

	write_number(file, key);
	write_number(file, m);
	write_number(file, count);
	write_number(file, learn);


	if (ferror(file)) {
		cerr << "Failed to write book." << endl;
		exit(EXIT_FAILURE);
	}

//	bookFile.flush();
//
//	if (!bookFile.good()) {
//		cerr << "Failed to flush book." << endl;
//		exit(EXIT_FAILURE);
//	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %edx, %ecx
andl $0xc000, %ecx           # imm = 0xC000
andl $0x3000, %edx           # imm = 0x3000
addl $0x2000, %edx           # imm = 0x2000
xorl %r15d, %r15d
cmpl $0x4000, %ecx           # imm = 0x4000
cmovel %edx, %r15d
orl %eax, %r15d
movl $0x8, %r12d
movq %r14, %rdi
shrq $0x38, %rdi
shlq $0x8, %r14
movq %rbx, %rsi
callq 0x5500
decq %r12
jne 0x9c90
movb $0x1, %r14b
movzwl %r15w, %edi
shrl $0x8, %edi
shll $0x8, %r15d
movq %rbx, %rsi
callq 0x5500
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x9cab
movb $0x1, %r14b
movzwl %bp, %edi
shrl $0x8, %edi
shll $0x8, %ebp
movq %rbx, %rsi
callq 0x5500
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x9ccd
movl $0x4, %r14d
xorl %edi, %edi
movq %rbx, %rsi
callq 0x5500
decq %r14
jne 0x9cf0
movq %rbx, %rdi
callq 0x5810
testl %eax, %eax
jne 0x9d14
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x332d5(%rip), %rdi     # 0x3cff0
leaq 0x278f4(%rip), %rsi     # 0x31616
callq 0x53d0
movq %rax, %rdi
callq 0x51c0
movl $0x1, %edi
callq 0x54e0
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/debug.cpp
// Function: print_pos(Position const&)
void print_pos(const Position& pos) {
	Piece piece;
	
	cout << "    0   1   2   3   4   5   6   7" << endl;
	cout << "  +---+---+---+---+---+---+---+---+" << endl;
	
	for (int rank = 7; rank >= 0; --rank) {
		cout << rank + 1 << " |";
		for (int file = 0; file < 8; ++file) {
			piece = pos.piece_on(BOARDVTOI[rank][file]);
			if (piece < 0 || piece > 16) {
				cout << "ERROR" << endl;
				return;
			}
			cout << " " << PIECE_NAME[piece] << " |";
		}
		cout << " " << rank << endl;
		cout << "  +---+---+---+---+---+---+---+---+" << endl;
	}
	
	cout << "    a   b   c   d   e   f   g   h" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x31c68(%rip), %rbx     # 0x3cfa0
leaq 0x26477(%rip), %rsi     # 0x317b6
movl $0x21, %edx
movq %rbx, %rdi
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
leaq 0x2645e(%rip), %rsi     # 0x317d8
movl $0x23, %edx
movq %rbx, %rdi
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
movl $0x7, %r15d
leaq 0x26441(%rip), %r13     # 0x317fc
movl %r15d, %r12d
shlq $0x5, %r12
movq %r15, 0x10(%rsp)
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x5760
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x5460
xorl %r15d, %r15d
leaq (%r12,%r15,4), %rax
leaq 0x264af(%rip), %rcx     # 0x318a0
movslq (%rcx,%rax), %rax
movl (%r14,%rax,4), %ebp
cmpq $0x10, %rbp
ja 0xb4f9
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x262ae(%rip), %rsi     # 0x316c0
callq 0x5460
leaq 0x26582(%rip), %rax     # 0x319a0
movb (%rbp,%rax), %al
movb %al, 0xf(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
leaq 0xf(%rsp), %rsi
callq 0x5460
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x5460
incq %r15
cmpq $0x8, %r15
jne 0xb3e6
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x26260(%rip), %rsi     # 0x316c0
callq 0x5460
movq %rbx, %rdi
movq 0x10(%rsp), %r15
movl %r15d, %esi
callq 0x5760
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
movl $0x23, %edx
movq %rbx, %rdi
leaq 0x2632a(%rip), %rsi     # 0x317d8
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
subl $0x1, %r15d
jae 0xb3bb
movq 0x31ab5(%rip), %rdi     # 0x3cfa0
leaq 0x26313(%rip), %rsi     # 0x31805
movl $0x21, %edx
jmp 0xb50c
movq 0x31aa0(%rip), %rdi     # 0x3cfa0
leaq 0x262f8(%rip), %rsi     # 0x317ff
movl $0x5, %edx
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/debug.cpp
// Function: print_castleRights(Position const&)
void print_castleRights(const Position& pos) {
	cout << (pos.can_castle_queenside(BLACK) ? 1 : 0);
	cout << (pos.can_castle_queenside(WHITE) ? 1 : 0);
	cout << (pos.can_castle_kingside(BLACK) ? 1 : 0);
	cout << (pos.can_castle_kingside(WHITE) ? 1 : 0);
	cout << endl;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x1938(%rdi), %rax
movl 0x10(%rax), %esi
shrl $0x3, %esi
andl $0x1, %esi
movq 0x317d1(%rip), %rbx     # 0x3cfa0
movq %rbx, %rdi
callq 0x5760
movq 0x1938(%r14), %rax
movl 0x10(%rax), %esi
shrl $0x2, %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x5760
movq 0x1938(%r14), %rax
movl 0x10(%rax), %esi
shrl %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x5760
movq 0x1938(%r14), %rax
movl 0x10(%rax), %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x5760
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x5270
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<Value, (EndgameType)28>::apply(Position const&) const
Value Endgame<Value, KRPKP_ATOMIC>::apply(const Position& pos) const {
	// there are 6 draw pawn configurations all the others are a win for white
	
#define S(x) (1ULL << (x))
	static const Bitboard draw_pattern_white = 
		S(SQ_A3) | S(SQ_E3) | S(SQ_D3) | S(SQ_H3) | S(SQ_E4) | S(SQ_D4);
	static const Bitboard draw_pattern_black = 
		S(SQ_A6) | S(SQ_E6) | S(SQ_D6) | S(SQ_H6) | S(SQ_E5) | S(SQ_D5);
#undef S
	
	if (strongerSide == WHITE) {
		Bitboard blocked_pawn = pos.pieces(PAWN, WHITE) & draw_pattern_white;
		if ((blocked_pawn << 8) & pos.pieces(PAWN, BLACK)) {
			return VALUE_DRAW;
		}
	} else {
		Bitboard blocked_pawn = pos.pieces(PAWN, BLACK) & draw_pattern_black;
		if ((blocked_pawn >> 8) & pos.pieces(PAWN, WHITE)) {
			return VALUE_DRAW;
		}
	}
	
	// TODO: this is not always true
	return strongerSide == pos.side_to_move() ? VALUE_KNOWN_WIN : -VALUE_KNOWN_WIN;
}

// Assembly:
movl 0x8(%rdi), %eax
movq 0x108(%rsi), %rcx
testl %eax, %eax
je 0xc348
movq 0x148(%rsi), %rdx
andq %rcx, %rdx
andq 0x140(%rsi), %rcx
shrq $0x8, %rdx
andq %rdx, %rcx
movabsq $0x9918000000, %rdx     # imm = 0x9918000000
jmp 0xc368
movl 0x140(%rsi), %edx
andl %ecx, %edx
andq 0x148(%rsi), %rcx
shlq $0x8, %rdx
andq %rdx, %rcx
movabsq $0x1899000000, %rdx     # imm = 0x1899000000
testq %rdx, %rcx
je 0xc370
xorl %eax, %eax
retq
cmpl 0x1090(%rsi), %eax
movl $0x3a98, %ecx           # imm = 0x3A98
movl $0xffffc568, %eax       # imm = 0xFFFFC568
cmovel %ecx, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<Value, (EndgameType)6>::apply(Position const&) const
Value Endgame<Value, KQKR>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
  assert(pos.piece_count(strongerSide, PAWN) == 0);
  assert(pos.non_pawn_material(weakerSide) == RookValueMidgame);
  assert(pos.piece_count(weakerSide, PAWN) == 0);

  Square winnerKSq = pos.king_square(strongerSide);
  Square loserKSq = pos.king_square(weakerSide);

  Value result =  QueenValueEndgame
                - RookValueEndgame
                + MateTable[loserKSq]
                + DistanceBonus[square_distance(winnerKSq, loserKSq)];

  return strongerSide == pos.side_to_move() ? result : -result;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl 0xc(%rdi), %edx
movq %rcx, %rax
shlq $0x9, %rax
movl 0x310(%rsi,%rax), %eax
shlq $0x9, %rdx
movslq 0x310(%rsi,%rdx), %rdi
leaq 0x30ddd(%rip), %rdx     # 0x3d46c
movl (%rdx), %edx
leaq 0x30dcc(%rip), %r8      # 0x3d464
subl (%r8), %edx
leaq 0x254de(%rip), %r8      # 0x31b80
addl (%r8,%rdi,4), %edx
movl %eax, %r8d
andl $0x7, %r8d
movl %edi, %r9d
andl $0x7, %r9d
subl %r9d, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
sarl $0x3, %eax
sarl $0x3, %edi
subl %edi, %eax
movl %eax, %edi
negl %edi
cmovsl %eax, %edi
cmpl %edi, %r9d
cmoval %r9d, %edi
leaq 0x255c2(%rip), %rax     # 0x31ca0
addl (%rax,%rdi,4), %edx
movl %edx, %eax
negl %eax
cmpl 0x1090(%rsi), %ecx
cmovel %edx, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)11>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KQKRPs>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
  assert(pos.piece_count(strongerSide, QUEEN) == 1);
  assert(pos.piece_count(strongerSide, PAWN) == 0);
  assert(pos.piece_count(weakerSide, ROOK) == 1);
  assert(pos.piece_count(weakerSide, PAWN) >= 1);

  Square kingSq = pos.king_square(weakerSide);
  if (   relative_rank(weakerSide, kingSq) <= RANK_2
      && relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
      && (pos.pieces(ROOK, weakerSide) & rank_bb(relative_rank(weakerSide, RANK_3)))
      && (pos.pieces(PAWN, weakerSide) & rank_bb(relative_rank(weakerSide, RANK_2)))
      && (pos.attacks_from<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
  {
      Square rsq = pos.piece_list(weakerSide, ROOK, 0);
      if (pos.attacks_from<PAWN>(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
          return SCALE_FACTOR_ZERO;
  }
  return SCALE_FACTOR_NONE;
}

// Assembly:
pushq %rbx
movl 0xc(%rdi), %r9d
movslq %r9d, %rdx
movq %r9, %rax
shlq $0x9, %rax
movslq 0x310(%rsi,%rax), %rcx
movl %ecx, %r10d
sarl $0x3, %r10d
leaq (,%rdx,8), %r8
subq %rdx, %r8
xorl %r8d, %r10d
cmpl $0x1, %r10d
jg 0xc8d9
leaq 0x190(%rsi), %rdx
movl 0x8(%rdi), %edi
movq %rdi, %r10
shlq $0x9, %r10
movl 0x180(%rdx,%r10), %r10d
sarl $0x3, %r10d
xorl %r8d, %r10d
cmpl $0x3, %r10d
jl 0xc8d9
movq 0x120(%rsi), %r11
movq 0x140(%rsi,%r9,8), %r9
movq %r8, %rbx
xorq $0x2, %rbx
leaq 0x10cd87(%rip), %r10    # 0x119610
andq (%r10,%rbx,8), %r11
testq %r9, %r11
je 0xc8d9
andq 0x108(%rsi), %r9
xorl $0x1, %r8d
movslq %r8d, %rsi
testq %r9, (%r10,%rsi,8)
je 0xc8d9
leaq 0x10cea3(%rip), %rsi    # 0x119750
testq %r9, 0xc00(%rsi,%rcx,8)
je 0xc8d9
leal 0x1(,%rdi,8), %ecx
shlq $0x9, %rcx
addq 0x3070f(%rip), %rcx     # 0x3cfd8
movslq 0x100(%rdx,%rax), %rdx
xorl %eax, %eax
testq %r9, (%rcx,%rdx,8)
jne 0xc8de
movl $0xff, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)13>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KRPPKRP>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
  assert(pos.piece_count(strongerSide, PAWN) == 2);
  assert(pos.non_pawn_material(weakerSide) == RookValueMidgame);
  assert(pos.piece_count(weakerSide, PAWN) == 1);

  Square wpsq1 = pos.piece_list(strongerSide, PAWN, 0);
  Square wpsq2 = pos.piece_list(strongerSide, PAWN, 1);
  Square bksq = pos.king_square(weakerSide);

  // Does the stronger side have a passed pawn?
  if (   pos.pawn_is_passed(strongerSide, wpsq1)
      || pos.pawn_is_passed(strongerSide, wpsq2))
      return SCALE_FACTOR_NONE;

  Rank r = Max(relative_rank(strongerSide, wpsq1), relative_rank(strongerSide, wpsq2));

  if (   file_distance(bksq, wpsq1) <= 1
      && file_distance(bksq, wpsq2) <= 1
      && relative_rank(strongerSide, bksq) > r)
  {
      switch (r) {
      case RANK_2: return ScaleFactor(10);
      case RANK_3: return ScaleFactor(10);
      case RANK_4: return ScaleFactor(15);
      case RANK_5: return ScaleFactor(20);
      case RANK_6: return ScaleFactor(40);
      default: assert(false);
      }
  }
  return SCALE_FACTOR_NONE;
}

// Assembly:
movl 0x8(%rdi), %edx
movq %rdx, %rcx
shlq $0x9, %rcx
movslq 0x1d0(%rsi,%rcx), %r8
movq %rdx, %rax
xorq $0x1, %rax
movq 0x140(%rsi,%rax,8), %r10
andq 0x108(%rsi), %r10
leaq 0x116da9(%rip), %r11    # 0x123b50
addq %rcx, %r11
movl $0xff, %eax
testq %r10, (%r11,%r8,8)
je 0xce45
movslq 0x1d4(%rsi,%rcx), %r9
testq %r10, (%r11,%r9,8)
je 0xce45
movl 0xc(%rdi), %ecx
shlq $0x9, %rcx
movl 0x310(%rsi,%rcx), %ecx
movl %r8d, %edi
sarl $0x3, %edi
leal (,%rdx,8), %esi
subl %edx, %esi
xorl %esi, %edi
movl %r9d, %edx
sarl $0x3, %edx
xorl %esi, %edx
cmpl %edx, %edi
cmovgl %edi, %edx
movl %ecx, %edi
andl $0x7, %edi
andl $0x7, %r8d
movl %edi, %r10d
subl %r8d, %r10d
movl %r10d, %r8d
negl %r8d
cmovsl %r10d, %r8d
cmpl $0x1, %r8d
ja 0xce45
andl $0x7, %r9d
subl %r9d, %edi
movl %edi, %r8d
negl %r8d
cmovsl %edi, %r8d
cmpl $0x1, %r8d
ja 0xce45
sarl $0x3, %ecx
xorl %esi, %ecx
cmpl %edx, %ecx
jle 0xce45
decl %edx
cmpl $0x4, %edx
ja 0xce45
movl %edx, %eax
leaq 0x24e3e(%rip), %rcx     # 0x31c80
movl (%rcx,%rax,4), %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)14>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KPsK>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
  assert(pos.piece_count(strongerSide, PAWN) >= 2);
  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
  assert(pos.piece_count(weakerSide, PAWN) == 0);

  Square ksq = pos.king_square(weakerSide);
  Bitboard pawns = pos.pieces(PAWN, strongerSide);

  // Are all pawns on the 'a' file?
  if ((pawns & ~FileABB) == EmptyBoardBB)
  {
      // Does the defending king block the pawns?
      if (   square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
          || (   square_file(ksq) == FILE_A
              && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
          return SCALE_FACTOR_ZERO;
  }
  // Are all pawns on the 'h' file?
  else if ((pawns & ~FileHBB) == EmptyBoardBB)
  {
    // Does the defending king block the pawns?
    if (   square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
        || (   square_file(ksq) == FILE_H
            && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
        return SCALE_FACTOR_ZERO;
  }
  return SCALE_FACTOR_NONE;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl 0xc(%rdi), %eax
shlq $0x9, %rax
movl 0x310(%rsi,%rax), %edi
movq 0x140(%rsi,%rcx,8), %rdx
andq 0x108(%rsi), %rdx
movabsq $-0x101010101010102, %rax # imm = 0xFEFEFEFEFEFEFEFE
testq %rax, %rdx
je 0xcec6
movabsq $0x7f7f7f7f7f7f7f7f, %rax # imm = 0x7F7F7F7F7F7F7F7F
testq %rax, %rdx
jne 0xcf0e
imull $0x38, %ecx, %eax
movl %edi, %esi
andl $0x7, %esi
movl %esi, %r8d
xorl $0x7, %r8d
sarl $0x3, %edi
sarl $0x3, %eax
xorl $0x7, %eax
movl %edi, %r9d
subl %eax, %r9d
movl %r9d, %r10d
negl %r10d
cmovsl %r9d, %r10d
cmpl %r10d, %r8d
cmoval %r8d, %r10d
xorl %eax, %eax
cmpl $0x2, %r10d
jb 0xcf13
cmpl $0x7, %esi
je 0xcefa
jmp 0xcf0e
imull $0x38, %ecx, %eax
movl %edi, %esi
andl $0x7, %esi
sarl $0x3, %edi
sarl $0x3, %eax
xorl $0x7, %eax
movl %edi, %r8d
subl %eax, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %r9d, %esi
cmoval %esi, %r9d
xorl %eax, %eax
cmpl $0x2, %r9d
jb 0xcf13
testl %esi, %esi
jne 0xcf0e
movslq %edi, %rsi
shlq $0x6, %rcx
addq 0x30028(%rip), %rcx     # 0x3cf30
testq %rdx, (%rcx,%rsi,8)
je 0xcf13
movl $0xff, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)17>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KBPKN>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
  assert(pos.piece_count(strongerSide, BISHOP) == 1);
  assert(pos.piece_count(strongerSide, PAWN) == 1);
  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
  assert(pos.piece_count(weakerSide, KNIGHT) == 1);
  assert(pos.piece_count(weakerSide, PAWN) == 0);

  Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
  Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP, 0);
  Square weakerKingSq = pos.king_square(weakerSide);

  if (   square_file(weakerKingSq) == square_file(pawnSq)
      && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
      && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
          || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
      return SCALE_FACTOR_ZERO;

  return SCALE_FACTOR_NONE;
}

// Assembly:
movl 0x8(%rdi), %r8d
movl 0xc(%rdi), %edx
movq %r8, %rcx
shlq $0x9, %rcx
movl 0x1d0(%rsi,%rcx), %eax
shlq $0x9, %rdx
movl 0x310(%rsi,%rdx), %edx
movl %edx, %edi
xorl %eax, %edi
testb $0x7, %dil
jne 0xd301
sarl $0x3, %eax
leal (,%r8,8), %r9d
subl %r8d, %r9d
xorl %r9d, %eax
movl %edx, %edi
sarl $0x3, %edi
xorl %r9d, %edi
cmpl %edi, %eax
jge 0xd301
xorl %eax, %eax
cmpl $0x6, %edi
jl 0xd306
xorl 0x250(%rsi,%rcx), %edx
movl %edx, %ecx
shrl $0x3, %ecx
xorl %edx, %ecx
andl $0x1, %ecx
jne 0xd306
movl $0xff, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)18>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KNPK>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
  assert(pos.piece_count(strongerSide, KNIGHT) == 1);
  assert(pos.piece_count(strongerSide, PAWN) == 1);
  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
  assert(pos.piece_count(weakerSide, PAWN) == 0);

  Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
  Square weakerKingSq = pos.king_square(weakerSide);

  if (   pawnSq == relative_square(strongerSide, SQ_A7)
      && square_distance(weakerKingSq, relative_square(strongerSide, SQ_A8)) <= 1)
      return SCALE_FACTOR_ZERO;

  if (   pawnSq == relative_square(strongerSide, SQ_H7)
      && square_distance(weakerKingSq, relative_square(strongerSide, SQ_H8)) <= 1)
      return SCALE_FACTOR_ZERO;

  return SCALE_FACTOR_NONE;
}

// Assembly:
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %edx
imull $0x38, %eax, %ecx
movq %rax, %rdi
shlq $0x9, %rdi
shlq $0x9, %rdx
movl 0x310(%rsi,%rdx), %eax
movl 0x1d0(%rsi,%rdi), %edx
xorl %ecx, %edx
cmpl $0x37, %edx
je 0xd33a
cmpl $0x30, %edx
jne 0xd360
movl %eax, %edx
jmp 0xd33e
movl %eax, %edx
notl %edx
andl $0x7, %edx
sarl $0x3, %eax
sarl $0x3, %ecx
xorl $0x7, %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl %ecx, %edx
cmoval %edx, %ecx
cmpl $0x2, %ecx
jae 0xd360
xorl %eax, %eax
retq
movl $0xff, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: Endgame<ScaleFactor, (EndgameType)19>::apply(Position const&) const
ScaleFactor Endgame<ScaleFactor, KPKP>::apply(const Position& pos) const {

  assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
  assert(pos.piece_count(WHITE, PAWN) == 1);
  assert(pos.piece_count(BLACK, PAWN) == 1);

  Square wksq, bksq, wpsq;
  Color stm;

  if (strongerSide == WHITE)
  {
      wksq = pos.king_square(WHITE);
      bksq = pos.king_square(BLACK);
      wpsq = pos.piece_list(WHITE, PAWN, 0);
      stm = pos.side_to_move();
  }
  else
  {
      wksq = flip_square(pos.king_square(BLACK));
      bksq = flip_square(pos.king_square(WHITE));
      wpsq = flip_square(pos.piece_list(BLACK, PAWN, 0));
      stm = opposite_color(pos.side_to_move());
  }

  if (square_file(wpsq) >= FILE_E)
  {
      wksq = flop_square(wksq);
      bksq = flop_square(bksq);
      wpsq = flop_square(wpsq);
  }

  // If the pawn has advanced to the fifth rank or further, and is not a
  // rook pawn, it's too dangerous to assume that it's at least a draw.
  if (   square_rank(wpsq) >= RANK_5
      && square_file(wpsq) != FILE_A)
      return SCALE_FACTOR_NONE;

  // Probe the KPK bitbase with the weakest side's pawn removed. If it's a
  // draw, it's probably at least a draw even with the pawn.
  return probe_kpk_bitbase(wksq, wpsq, bksq, stm) ? SCALE_FACTOR_NONE : SCALE_FACTOR_ZERO;
}

// Assembly:
cmpl $0x0, 0x8(%rdi)
je 0xd398
movl 0x510(%rsi), %r8d
xorl $0x38, %r8d
movl 0x310(%rsi), %r9d
movl 0x3d0(%rsi), %r10d
xorl $0x38, %r9d
xorl $0x38, %r10d
movl 0x1090(%rsi), %ecx
xorl $0x1, %ecx
jmp 0xd3b3
movl 0x1d0(%rsi), %r10d
movl 0x310(%rsi), %r8d
movl 0x510(%rsi), %r9d
movl 0x1090(%rsi), %ecx
movl %r10d, %esi
xorl $0x7, %esi
testb $0x4, %r10b
cmovel %r10d, %esi
cmpl $0x20, %esi
setge %dl
testb $0x7, %sil
setne %dil
movl $0xff, %eax
testb %dil, %dl
jne 0xd407
pushq %rax
movl %r9d, %edx
xorl $0x7, %edx
movl %r8d, %edi
xorl $0x7, %edi
testb $0x4, %r10b
cmovel %r9d, %edx
cmovel %r8d, %edi
callq 0x7d08
movl %eax, %ecx
testl %eax, %eax
movl $0xff, %eax
cmovel %ecx, %eax
addq $0x8, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: (anonymous namespace)::mat_key(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Key mat_key(const string& keyCode) {

    assert(keyCode.length() > 0 && keyCode.length() < 8);
    assert(keyCode[0] == 'K');

    string fen;
    size_t i = 0;

    // First add white and then black pieces
    do fen += keyCode[i];                while (keyCode[++i] != 'K');
    do fen += char(tolower(keyCode[i])); while (++i < keyCode.length());

    // Add file padding and remaining empty ranks
    fen += string(1, '0' + int(8 - keyCode.length())) + "/8/8/8/8/8/8/8 w - -";

    // Build a Position out of the fen string and get its material key
    return Position(fen, false, 0).get_material_key();
  }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1988, %rsp           # imm = 0x1988
movq %rdi, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq (%rdi), %rax
movb (%rax), %al
xorl %r12d, %r12d
leaq 0x8(%rsp), %r14
movsbl %al, %esi
movq %r14, %rdi
callq 0x5330
movq (%rbx), %rax
movb 0x1(%rax,%r12), %al
incq %r12
cmpb $0x4b, %al
jne 0xd43b
leaq 0x8(%rsp), %r14
movq (%rbx), %rax
movsbl (%rax,%r12), %edi
callq 0x55d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5330
incq %r12
movq 0x8(%rbx), %rax
cmpq %rax, %r12
jb 0xd45a
movb $0x38, %cl
subb %al, %cl
leaq 0x38(%rsp), %r14
movq %r14, -0x10(%r14)
movsbl %cl, %edx
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x5480
leaq 0x246c0(%rip), %rsi     # 0x31b64
leaq 0x28(%rsp), %rdi
callq 0x5820
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0xd4d6
movq %rsi, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0xd4e1
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq %r12, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x8(%rsp), %rdi
callq 0x5130
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xd51a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0xd531
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5400
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ccf2
movq 0x1980(%rsp), %rax
movq 0x8(%rax), %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0xd567
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rax
addq $0x1988, %rsp           # imm = 0x1988
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0xd5b7
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xd59a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xd59a
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0xd5ba
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xd5ba
jmp 0xd5b7
jmp 0xd5b7
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0xd5d1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/endgame.cpp
// Function: void Endgames::add<Endgame<Value, (EndgameType)8>>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Endgames::add(const string& keyCode) {

  typedef typename T::Base F;
  typedef std::map<Key, F*> M;

  const_cast<M&>(get<F>()).insert(std::pair<Key, F*>(mat_key(keyCode), new T(WHITE)));
  const_cast<M&>(get<F>()).insert(std::pair<Key, F*>(mat_key(swap_colors(keyCode)), new T(BLACK)));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xd408
movq %rax, %r15
movl $0x10, %edi
callq 0x53f0
leaq 0x2f095(%rip), %r12     # 0x3c808
movq %r12, (%rax)
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, 0x8(%rax)
leaq 0x8(%rsp), %rsi
movq %r15, (%rsi)
movq %rax, 0x8(%rsi)
movq %rbx, %rdi
callq 0xe542
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xd5d9
movq %r15, %rdi
callq 0xd408
movq %rax, %r14
movl $0x10, %edi
callq 0x53f0
movq %r12, (%rax)
movq $0x1, 0x8(%rax)
leaq 0x28(%rsp), %rsi
movq %r14, (%rsi)
movq %rax, 0x8(%rsi)
movq %rbx, %rdi
callq 0xe542
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd7f7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0xd805
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd823
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/evaluate.cpp
// Function: (anonymous namespace)::weight_option(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Score)
Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight) {

    // Scale option value from 100 to 256
    int mg = Options[mgOpt].value<int>() * 256 / 100;
    int eg = Options[egOpt].value<int>() * 256 / 100;

    return apply_weight(make_score(mg, eg), internalWeight);
  }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %rsi
leaq 0x3bc9b8(%rip), %r15    # 0x3ce078
movq %r15, %rdi
callq 0x15b38
movq 0x20(%rax), %rdi
callq 0x5660
shll $0x8, %eax
cltq
imulq $0x51eb851f, %rax, %r12 # imm = 0x51EB851F
movq %r12, %rax
shrq $0x3f, %rax
shrq $0x25, %r12
addl %eax, %r12d
movq %r15, %rdi
movq %r14, %rsi
callq 0x15b38
movq 0x20(%rax), %rdi
callq 0x5660
shll $0x8, %eax
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x25, %rcx
addl %eax, %ecx
shll $0x10, %r12d
movl $0x8000, %esi           # imm = 0x8000
addl %ecx, %r12d
addl %esi, %r12d
sarl $0x10, %r12d
leal (%rbx,%rsi), %edi
sarl $0x10, %edi
imull %r12d, %edi
movl $0xff, %edx
leal (%rdi,%rdx), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl $0x7fff, %edi           # imm = 0x7FFF
movl %ecx, %r8d
andl %edi, %r8d
andl %esi, %ecx
subl %ecx, %r8d
andl %ebx, %edi
andl %esi, %ebx
subl %ebx, %edi
imull %r8d, %edi
addl %edi, %edx
testl %edi, %edi
cmovnsl %edi, %edx
sarl $0x8, %edx
shll $0x8, %eax
andl $0xffff0000, %eax       # imm = 0xFFFF0000
addl %edx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/main_uci.cpp
// Function: main_uci(int)
void main_uci(int argc) {

	if (argc < 2)
	{
		// Print copyright notice
		//cout << engine_name() << " by " << engine_authors() << endl;

		//if (CpuHasPOPCNT)
		//	cout << "Good! CPU has hardware POPCNT." << endl;

		// Wait for a command from the user, and passes this command to
		// execute_uci_command() and also intercepts EOF from stdin to
		// ensure that we exit gracefully if the GUI dies unexpectedly.
		string cmd;
		while (getline(cin, cmd) && execute_uci_command(cmd)) {}
	}

	Threads.exit();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
cmpl $0x1, %edi
jg 0x164c3
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq 0x26b62(%rip), %rbx     # 0x3cfd0
movq %rsp, %r14
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x57e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x164ad
movq %r14, %rdi
callq 0x2abf8
testb %al, %al
jne 0x16471
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x164c3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5400
leaq 0x3ab5c6(%rip), %rdi    # 0x3c1a90
callq 0x29560
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x164f2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790
nop
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/./tt.h
// Function: SimpleHash<MaterialInfo, 8192>::init()
void init() {

    if (entries)
        return;

    entries = new (std::nothrow) Entry[HashSize];
    if (!entries)
    {
        std::cerr << "Failed to allocate " << HashSize * sizeof(Entry)
                  << " bytes for hash table." << std::endl;
        exit(EXIT_FAILURE);
    }
    memset(entries, 0, HashSize * sizeof(Entry));
  }

// Assembly:
pushq %rbx
cmpq $0x0, 0x8(%rdi)
je 0x1680c
popq %rbx
retq
movq %rdi, %rbx
movq 0x26712(%rip), %rsi     # 0x3cf28
movl $0x60000, %edi          # imm = 0x60000
callq 0x5700
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x16839
movl $0x60000, %edx          # imm = 0x60000
movq %rax, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x5210
movq 0x267b0(%rip), %rdi     # 0x3cff0
leaq 0x1bdde(%rip), %rsi     # 0x32625
callq 0x53d0
movl $0x60000, %esi          # imm = 0x60000
movq %rax, %rdi
callq 0x50f0
leaq 0x1bdd9(%rip), %rsi     # 0x32639
movq %rax, %rdi
callq 0x53d0
movq %rax, %rdi
callq 0x51c0
movl $0x1, %edi
callq 0x54e0
// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/material.cpp
// Function: int MaterialInfoTable::imbalance<(Color)0>(int const (*) [8])
int MaterialInfoTable::imbalance(const int pieceCount[][8]) {

  const Color Them = (Us == WHITE ? BLACK : WHITE);

  int pt1, pt2, pc, v;
  int value = 0;

  // Redundancy of major pieces, formula based on Kaufman's paper
  // "The Evaluation of Material Imbalances in Chess"
  if (pieceCount[Us][ROOK] > 0)
      value -=  RedundantRookPenalty * (pieceCount[Us][ROOK] - 1)
              + RedundantQueenPenalty * pieceCount[Us][QUEEN];

  // Second-degree polynomial material imbalance by Tord Romstad
  for (pt1 = PIECE_TYPE_NONE; pt1 <= QUEEN; pt1++)
  {
      pc = pieceCount[Us][pt1];
      if (!pc)
          continue;

      v = LinearCoefficients[pt1];

      for (pt2 = PIECE_TYPE_NONE; pt2 <= pt1; pt2++)
          v +=  QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2]
              + QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2];

      value += pc * v;
  }
  return value;
}

// Assembly:
movl 0x10(%rdi), %eax
testl %eax, %eax
jle 0x16899
imull $0xfffffdd6, %eax, %eax # imm = 0xFFFFFDD6
movl 0x14(%rdi), %ecx
shll $0x6, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addl $0x22a, %eax            # imm = 0x22A
jmp 0x1689b
xorl %eax, %eax
pushq %rbp
pushq %rbx
movl $0x1, %ecx
leaq 0x1bbb7(%rip), %rdx     # 0x32460
leaq 0x1bc70(%rip), %rsi     # 0x32520
xorl %r8d, %r8d
leaq 0x1bb86(%rip), %r9      # 0x32440
movl (%rdi,%r8,4), %r10d
testl %r10d, %r10d
je 0x168ef
movl (%r9,%r8,4), %r11d
xorl %ebx, %ebx
movl (%rdi,%rbx,4), %ebp
imull (%rdx,%rbx,4), %ebp
addl %r11d, %ebp
movl 0x20(%rdi,%rbx,4), %r11d
imull (%rsi,%rbx,4), %r11d
addl %ebp, %r11d
incq %rbx
cmpq %rbx, %rcx
jne 0x168c9
imull %r10d, %r11d
addl %r11d, %eax
incq %r8
incq %rcx
addq $0x20, %rdx
addq $0x20, %rsi
cmpq $0x6, %r8
jne 0x168ba
popq %rbx
popq %rbp
retq