// File: codeandkey[P]neocortex/src/bitboard.cpp
// Function: neocortex::bb::init()
void bb::init() {
	/* zero lookup buf */
	for (int i = 0; i < 64; ++i) {
		for (int j = 0; j < 64; ++j) {
			BETWEEN[i][j] = 0ULL;
		}
	}

	/* construct lookup */
	for (int src = 0; src < 64; ++src) {
		/* west */
		if (square::file(src) > 1) {
			int t = src - 2;

			do {
				for (int j = src - 1; j != t; --j) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::file(t--) != 0);
		}

		/* east */
		if (square::file(src) < 6) {
			int t = src + 2;

			do {
				for (int j = src + 1; j != t; ++j) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::file(t++) != 7);
		}

		/* north */
		if (square::rank(src) < 6) {
			int t = src + NORTH;

			do {
				t += NORTH;

				for (int j = src + NORTH; j != t; j += NORTH) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 7);
		}

		/* south */
		if (square::rank(src) > 1) {
			int t = src + SOUTH;

			do {
				t += SOUTH;

				for (int j = src + SOUTH; j != t; j += SOUTH) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 0);
		}
		
		/* northeast */
		if (square::rank(src) < 6 && square::file(src) < 6) {
			int t = src + NORTHEAST;

			do {
				t += NORTHEAST;

				for (int j = src + NORTHEAST; j != t; j += NORTHEAST) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 7 && square::file(t) != 7);
		}

		/* northwest */
		if (square::rank(src) < 6 && square::file(src) > 1) {
			int t = src + NORTHWEST;

			do {
				t += NORTHWEST;

				for (int j = src + NORTHWEST; j != t; j += NORTHWEST) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 7 && square::file(t) != 0);
		}

		/* southeast */
		if (square::rank(src) > 1 && square::file(src) < 6) {
			int t = src + SOUTHEAST;

			do {
				t += SOUTHEAST;

				for (int j = src + SOUTHEAST; j != t; j += SOUTHEAST) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 0 && square::file(t) != 7);
		}

		/* southwest */
		if (square::rank(src) > 1 && square::file(src) > 1) {
			int t = src + SOUTHWEST;

			do {
				t += SOUTHWEST;

				for (int j = src + SOUTHWEST; j != t; j += SOUTHWEST) {
					BETWEEN[src][t] |= 1ULL << j;
				}
			} while (square::rank(t) != 0 && square::file(t) != 0);
		}
	}

	// generate neighbor files
	for (int sq = 0; sq < 64; ++sq) {
		int f = square::file(sq);
		NEIGHBOR_FILES[sq] = 0ULL;

		if (f > 0) {
			NEIGHBOR_FILES[sq] |= bb::file(f - 1);
		}

		if (f < 7) {
			NEIGHBOR_FILES[sq] |= bb::file(f + 1);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x40, -0x4(%rbp)
jge 0x6d98
movl $0x0, -0x8(%rbp)
cmpl $0x40, -0x8(%rbp)
jge 0x6d8b
movslq -0x4(%rbp), %rcx
leaq 0x2dd13(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x6d5c
jmp 0x6d8d
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x6d4f
movl $0x0, -0xc(%rbp)
cmpl $0x40, -0xc(%rbp)
jge 0x723f
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x1, %eax
jle 0x6e1f
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
je 0x6e06
movl -0x14(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2dc98(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x6dc8
jmp 0x6e08
movl -0x10(%rbp), %edi
movl %edi, %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
callq 0x6b80
cmpl $0x0, %eax
jne 0x6dbf
jmp 0x6e1f
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x6, %eax
jge 0x6e95
movl -0xc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x6e7c
movl -0x1c(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2dc22(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6e3e
jmp 0x6e7e
movl -0x18(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
callq 0x6b80
cmpl $0x7, %eax
jne 0x6e35
jmp 0x6e95
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x6, %eax
jge 0x6f0c
movl -0xc(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x20(%rbp)
movl -0xc(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x6efb
movl -0x24(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2dba3(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x24(%rbp)
jmp 0x6ebd
jmp 0x6efd
movl -0x20(%rbp), %edi
callq 0x6b30
cmpl $0x7, %eax
jne 0x6eab
jmp 0x6f0c
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x1, %eax
jle 0x6f83
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x28(%rbp)
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x6f72
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2db2c(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x2c(%rbp)
jmp 0x6f34
jmp 0x6f74
movl -0x28(%rbp), %edi
callq 0x6b30
cmpl $0x0, %eax
jne 0x6f22
jmp 0x6f83
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x6, %eax
jge 0x702e
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x6, %eax
jge 0x702e
movl -0xc(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x30(%rbp)
movl -0xc(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x6ffe
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2daa0(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x30(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x34(%rbp)
jmp 0x6fc0
jmp 0x7000
movl -0x30(%rbp), %edi
callq 0x6b30
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x7, %ecx
movb %al, -0x55(%rbp)
je 0x7025
movl -0x30(%rbp), %edi
callq 0x6b80
cmpl $0x7, %eax
setne %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x6fae
jmp 0x702e
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x6, %eax
jge 0x70d9
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x1, %eax
jle 0x70d9
movl -0xc(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x70a9
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2d9f5(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x3c(%rbp)
jmp 0x706b
jmp 0x70ab
movl -0x38(%rbp), %edi
callq 0x6b30
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x7, %ecx
movb %al, -0x56(%rbp)
je 0x70d0
movl -0x38(%rbp), %edi
callq 0x6b80
cmpl $0x0, %eax
setne %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %al
testb $0x1, %al
jne 0x7059
jmp 0x70d9
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x1, %eax
jle 0x7184
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x6, %eax
jge 0x7184
movl -0xc(%rbp), %eax
addl $-0x7, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
addl $-0x7, %eax
movl %eax, -0x40(%rbp)
movl -0xc(%rbp), %eax
addl $-0x7, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x7154
movl -0x44(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2d94a(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $-0x7, %eax
movl %eax, -0x44(%rbp)
jmp 0x7116
jmp 0x7156
movl -0x40(%rbp), %edi
callq 0x6b30
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x57(%rbp)
je 0x717b
movl -0x40(%rbp), %edi
callq 0x6b80
cmpl $0x7, %eax
setne %al
movb %al, -0x57(%rbp)
movb -0x57(%rbp), %al
testb $0x1, %al
jne 0x7104
jmp 0x7184
movl -0xc(%rbp), %edi
callq 0x6b30
cmpl $0x1, %eax
jle 0x722f
movl -0xc(%rbp), %edi
callq 0x6b80
cmpl $0x1, %eax
jle 0x722f
movl -0xc(%rbp), %eax
addl $-0x9, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
addl $-0x9, %eax
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
addl $-0x9, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x71ff
movl -0x4c(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movslq -0xc(%rbp), %rcx
leaq 0x2d89f(%rip), %rax     # 0x34a80
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x48(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $-0x9, %eax
movl %eax, -0x4c(%rbp)
jmp 0x71c1
jmp 0x7201
movl -0x48(%rbp), %edi
callq 0x6b30
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x58(%rbp)
je 0x7226
movl -0x48(%rbp), %edi
callq 0x6b80
cmpl $0x0, %eax
setne %al
movb %al, -0x58(%rbp)
movb -0x58(%rbp), %al
testb $0x1, %al
jne 0x71af
jmp 0x722f
jmp 0x7231
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x6d9f
movl $0x0, -0x50(%rbp)
cmpl $0x40, -0x50(%rbp)
jge 0x72da
movl -0x50(%rbp), %edi
callq 0x6b80
movl %eax, -0x54(%rbp)
movslq -0x50(%rbp), %rcx
leaq 0x3581a(%rip), %rax     # 0x3ca80
movq $0x0, (%rax,%rcx,8)
cmpl $0x0, -0x54(%rbp)
jle 0x729c
movl -0x54(%rbp), %edi
subl $0x1, %edi
callq 0x73e0
movq %rax, %rdx
movslq -0x50(%rbp), %rcx
leaq 0x357f3(%rip), %rax     # 0x3ca80
orq (%rax,%rcx,8), %rdx
leaq 0x357e8(%rip), %rax     # 0x3ca80
movq %rdx, (%rax,%rcx,8)
cmpl $0x7, -0x54(%rbp)
jge 0x72ca
movl -0x54(%rbp), %edi
addl $0x1, %edi
callq 0x73e0
movq %rax, %rdx
movslq -0x50(%rbp), %rcx
leaq 0x357c5(%rip), %rax     # 0x3ca80
orq (%rax,%rcx,8), %rdx
leaq 0x357ba(%rip), %rax     # 0x3ca80
movq %rdx, (%rax,%rcx,8)
jmp 0x72cc
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x7246
addq $0x60, %rsp
popq %rbp
retq