// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0x1984f(%rip), %rax     # 0x1e9c0
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0x5196
xorl %edx, %edx
cmpq $0x40, %rdx
je 0x518b
andq $0x0, (%rax,%rdx,8)
incq %rdx
jmp 0x517b
incq %rcx
addq $0x200, %rax            # imm = 0x200
jmp 0x5173
pushq $-0x2
popq %rax
movq %rax, 0x40(%rsp)
pushq $0x2
popq %r12
pushq $0x8
popq %r15
pushq $-0x8
popq %rax
movq %rax, 0x30(%rsp)
pushq $0x9
popq %rax
pushq $0x7
popq %rcx
pushq $-0x7
popq %rdx
movq %rdx, 0x18(%rsp)
pushq $-0x9
popq %rdx
movq %rdx, 0x10(%rsp)
pushq $-0x1
popq %rdx
xorl %ebx, %ebx
pushq $0x1
popq %r13
movl %edx, 0xc(%rsp)
movq %r12, 0x38(%rsp)
cmpq $0x40, %rbx
je 0x5585
movq %rax, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movl %ebx, %edi
callq 0x50da
cmpl $0x2, %eax
jl 0x5244
movq %rbx, %rcx
shlq $0x9, %rcx
leaq 0x197bc(%rip), %rax     # 0x1e9c0
addq %rax, %rcx
movq %rcx, (%rsp)
pushq $-0x1
popq %rbp
movq 0x40(%rsp), %r14
movq (%rsp), %rax
leaq (%rax,%r14,8), %rax
movl %ebp, %edx
movl 0xc(%rsp), %ecx
testl %edx, %edx
je 0x5234
movq %r13, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
decl %ecx
incl %edx
jmp 0x5221
decq %r14
movl %ecx, %edi
callq 0x50da
decl %ebp
testl %eax, %eax
jne 0x5213
movl %ebx, %edi
callq 0x50da
cmpl $0x5, %eax
jg 0x529a
movq %r13, %r14
movq 0x38(%rsp), %rdi
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x1975a(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
leaq (%rax,%rdi,8), %rax
xorl %edx, %edx
cmpq %rdx, %r14
je 0x5286
leaq (%rbx,%rdx), %rcx
movq %r12, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
incq %rdx
jmp 0x526f
leaq 0x1(%rdi), %rbp
callq 0x50da
incq %r14
movq %rbp, %rdi
cmpl $0x7, %eax
jne 0x5258
movl %ebx, %edi
callq 0x50b1
cmpl $0x5, %eax
jg 0x52f4
pushq $0x8
popq %rbp
movq %r15, %r14
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x19706(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
leaq (%rax,%r14,8), %rax
addq $0x40, %rax
addq $0x8, %r14
xorl %edx, %edx
cmpq %rdx, %rbp
je 0x52e3
leaq (%r15,%rdx), %rcx
movq %r13, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
addq $0x8, %rdx
jmp 0x52cb
movl %r14d, %edi
callq 0x50b1
addq $0x8, %rbp
cmpl $0x7, %eax
jne 0x52ac
movl %ebx, %edi
callq 0x50b1
cmpl $0x2, %eax
jl 0x534f
pushq $-0x8
popq %rbp
movq 0x30(%rsp), %r14
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x196aa(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
leaq (%rax,%r14,8), %rax
addq $-0x40, %rax
addq $-0x8, %r14
movl %ebp, %edx
movq 0x30(%rsp), %rcx
testl %edx, %edx
je 0x5341
movq %r13, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
addl $-0x8, %ecx
addl $0x8, %edx
jmp 0x532c
movl %ecx, %edi
callq 0x50b1
addl $-0x8, %ebp
testl %eax, %eax
jne 0x5308
movl %ebx, %edi
callq 0x50b1
cmpl $0x5, %eax
jg 0x53c9
movl %ebx, %edi
callq 0x50da
cmpl $0x5, %eax
jg 0x53c9
pushq $0x9
popq %rbp
movq 0x20(%rsp), %r14
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x19643(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
leaq (%rax,%r14,8), %rax
addq $0x48, %rax
addq $0x9, %r14
xorl %edx, %edx
movq 0x20(%rsp), %rdi
cmpq %rdx, %rbp
je 0x53ab
leaq (%rdi,%rdx), %rcx
movq %r13, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
addq $0x9, %rdx
jmp 0x5393
movl %r14d, %edi
callq 0x50b1
cmpl $0x7, %eax
je 0x53c9
movl %r14d, %edi
callq 0x50da
addq $0x9, %rbp
cmpl $0x7, %eax
jne 0x536f
movl %ebx, %edi
callq 0x50b1
cmpl $0x5, %eax
jg 0x5442
movl %ebx, %edi
callq 0x50da
cmpl $0x2, %eax
jl 0x5442
pushq $0x7
popq %rbp
movq 0x28(%rsp), %r14
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x195c9(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
leaq (%rax,%r14,8), %rax
addq $0x38, %rax
addq $0x7, %r14
xorl %edx, %edx
movq 0x28(%rsp), %rdi
cmpq %rdx, %rbp
je 0x5425
leaq (%rdi,%rdx), %rcx
movq %r13, %rsi
shlq %cl, %rsi
orq %rsi, (%rax)
addq $0x7, %rdx
jmp 0x540d
movl %r14d, %edi
callq 0x50b1
cmpl $0x7, %eax
je 0x5442
movl %r14d, %edi
callq 0x50da
addq $0x7, %rbp
testl %eax, %eax
jne 0x53e9
movl %ebx, %edi
callq 0x50b1
cmpl $0x2, %eax
jl 0x54c8
movl %ebx, %edi
callq 0x50da
cmpl $0x5, %eax
jg 0x54c8
pushq $-0x7
popq %r14
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x1954b(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
movq (%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addq $-0x38, %rax
addq $-0x7, %rcx
movq %rcx, (%rsp)
movl %r14d, %edx
movq 0x18(%rsp), %rcx
movl %ecx, %ebp
testl %edx, %edx
je 0x54ad
movq %r13, %rsi
movl %ebp, %ecx
shlq %cl, %rsi
orq %rsi, (%rax)
addl $-0x7, %ebp
addl $0x7, %edx
jmp 0x5496
movl %ebp, %edi
callq 0x50b1
testl %eax, %eax
je 0x54c8
movl %ebp, %edi
callq 0x50da
addl $-0x7, %r14d
cmpl $0x7, %eax
jne 0x5467
movl %ebx, %edi
callq 0x50b1
cmpl $0x2, %eax
jl 0x554d
movl %ebx, %edi
callq 0x50da
cmpl $0x2, %eax
jl 0x554d
pushq $-0x9
popq %r14
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rax
shlq $0x9, %rax
leaq 0x194c5(%rip), %rcx     # 0x1e9c0
addq %rcx, %rax
movq (%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addq $-0x48, %rax
addq $-0x9, %rcx
movq %rcx, (%rsp)
movl %r14d, %edx
movq 0x10(%rsp), %rcx
movl %ecx, %ebp
testl %edx, %edx
je 0x5533
movq %r13, %rsi
movl %ebp, %ecx
shlq %cl, %rsi
orq %rsi, (%rax)
addl $-0x9, %ebp
addl $0x9, %edx
jmp 0x551c
movl %ebp, %edi
callq 0x50b1
testl %eax, %eax
je 0x554d
movl %ebp, %edi
callq 0x50da
addl $-0x9, %r14d
testl %eax, %eax
jne 0x54ed
incq %rbx
incq 0x40(%rsp)
incq 0x38(%rsp)
incq %r15
incq 0x30(%rsp)
movq 0x20(%rsp), %rax
incq %rax
movq 0x28(%rsp), %rcx
incq %rcx
incq 0x18(%rsp)
incq 0x10(%rsp)
incl 0xc(%rsp)
jmp 0x51d6
leaq 0x21434(%rip), %r15     # 0x269c0
xorl %ebx, %ebx
cmpq $0x40, %rbx
je 0x55cf
movl %ebx, %edi
callq 0x50da
movl %eax, %r14d
andq $0x0, (%r15)
testl %eax, %eax
jle 0x55b8
leal -0x1(%r14), %edi
callq 0x566c
orq %rax, (%r15)
cmpl $0x6, %r14d
ja 0x55c6
incl %r14d
movl %r14d, %edi
callq 0x566c
orq %rax, (%r15)
incq %rbx
addq $0x8, %r15
jmp 0x558e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq