// File: /workspace/github_cpp_makefile_star2_O2/codeandkey[P]neocortex/src/attacks.cpp
// Function: neocortex::attacks::init()
void attacks::init() {
	for (int sq = 0; sq < 64; ++sq) {
		int src_r = square::rank(sq), src_f = square::file(sq);

		/* white pawn spans */
		for (int rr = src_r + 1; rr < 8; ++rr) {
			pawn_frontspans_list[piece::WHITE][sq] |= bb::mask(square::at(rr, src_f));

			if (src_f > 0) {
				pawn_attackspans_list[piece::WHITE][sq] |= bb::mask(square::at(rr, src_f - 1));
			}

			if (src_f < 7) {
				pawn_attackspans_list[piece::WHITE][sq] |= bb::mask(square::at(rr, src_f + 1));
			}
		}

		/* black pawn spans */
		for (int rr = src_r - 1; rr >= 0; --rr) {
			pawn_frontspans_list[piece::BLACK][sq] |= bb::mask(square::at(rr, src_f));

			if (src_f > 0) {
				pawn_attackspans_list[piece::BLACK][sq] |= bb::mask(square::at(rr, src_f - 1));
			}

			if (src_f < 7) {
				pawn_attackspans_list[piece::BLACK][sq] |= bb::mask(square::at(rr, src_f + 1));
			}
		}

		if (src_r < 7) {
			pawn_attacks[piece::WHITE][sq] = bb::shift(bb::mask(sq) & ~FILE_A, NORTHWEST) | bb::shift(bb::mask(sq) & ~FILE_H, NORTHEAST);
		} else {
			pawn_attacks[piece::WHITE][sq] = 0;
		}

		if (src_r > 0) {
			pawn_attacks[piece::BLACK][sq] = bb::shift(bb::mask(sq) & ~FILE_A, SOUTHWEST) | bb::shift(bb::mask(sq) & ~FILE_H, SOUTHEAST);
		}
		else {
			pawn_attacks[piece::BLACK][sq] = 0;
		}

		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_H), EAST);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_A), WEST);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_8), NORTH);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_1), SOUTH);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_H & ~RANK_8), NORTHEAST);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_A & ~RANK_8), NORTHWEST);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_H & ~RANK_1), SOUTHEAST);
		king_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_A & ~RANK_1), SOUTHWEST);

		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_H & ~FILE_G & ~RANK_8), EAST * 2 + NORTH);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_H & ~FILE_G & ~RANK_1), EAST * 2 + SOUTH);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_B & ~FILE_A & ~RANK_8), WEST * 2 + NORTH);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~FILE_B & ~FILE_A & ~RANK_1), WEST * 2 + SOUTH);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_1 & ~RANK_2 & ~FILE_A), SOUTH * 2 + WEST);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_1 & ~RANK_2 & ~FILE_H), SOUTH * 2 + EAST);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_7 & ~RANK_8 & ~FILE_A), NORTH * 2 + WEST);
		knight_attacks[sq] |= bb::shift((bb::mask(sq) & ~RANK_7 & ~RANK_8 & ~FILE_H), NORTH * 2 + EAST);

		int num_rook_roccs = 1 << magic::rook_bits[sq];

		rook_attacks[sq] = new bitboard[num_rook_roccs];

		for (int i = 0; i < num_rook_roccs; ++i) {
			rook_attacks[sq][i] = 0;
		}

		for (int i = 0; i < num_rook_roccs; ++i) {
			bitboard rocc = make_rocc(i, magic::rook_masks[sq], magic::rook_bits[sq]);
			int mindex = magic_index(rocc, magic::rook_magics[sq], magic::rook_bits[sq]);

			assert(!rook_attacks[sq][mindex]);

			bitboard* dst = &rook_attacks[sq][mindex];

			/* west */
			for (int f = src_f - 1; f >= 0; --f) {
				bitboard mask = bb::mask(square::at(src_r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* east */
			for (int f = src_f + 1; f < 8; ++f) {
				bitboard mask = bb::mask(square::at(src_r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* north */
			for (int r = src_r + 1; r < 8; ++r) {
				bitboard mask = bb::mask(square::at(r, src_f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* south */
			for (int r = src_r - 1; r >= 0; --r) {
				bitboard mask = bb::mask(square::at(r, src_f));
				*dst |= (bitboard) mask;
				if (rocc & mask) break;
			}
		}

		int num_bishop_roccs = 1 << magic::bishop_bits[sq];

		bishop_attacks[sq] = new bitboard[num_bishop_roccs];

		for (int i = 0; i < num_bishop_roccs; ++i) {
			bishop_attacks[sq][i] = 0;
		}

		for (int i = 0; i < num_bishop_roccs; ++i) {
			bitboard rocc = make_rocc(i, magic::bishop_masks[sq], magic::bishop_bits[sq]);
			int mindex = magic_index(rocc, magic::bishop_magics[sq], magic::bishop_bits[sq]);

			assert(!bishop_attacks[sq][mindex]);

			bitboard* dst = &bishop_attacks[sq][mindex];

			/* northwest */
			for (int f = src_f - 1, r = src_r + 1; f >= 0 && r < 8; --f, ++r) {
				bitboard mask = bb::mask(square::at(r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* northeast */
			for (int f = src_f + 1, r = src_r + 1; f < 8 && r < 8; ++f, ++r) {
				bitboard mask = bb::mask(square::at(r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* southeast */
			for (int f = src_f + 1, r = src_r - 1; f < 8 && r >= 0; ++f, --r) {
				bitboard mask = bb::mask(square::at(r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}

			/* southwest */
			for (int f = src_f - 1, r = src_r - 1; f >= 0 && r >= 0; --f, --r) {
				bitboard mask = bb::mask(square::at(r, f));
				*dst |= mask;
				if (rocc & mask) break;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movabsq $-0x101010101010200, %rax # imm = 0xFEFEFEFEFEFEFE00
movabsq $0x7f7f7f7f7f7f7f00, %rcx # imm = 0x7F7F7F7F7F7F7F00
movabsq $0xfefefefefefefe, %r13 # imm = 0xFEFEFEFEFEFEFE
leaq 0x19881(%rip), %rbx     # 0x1e1c0
addq $0xfe, %rax
movq %rax, 0x38(%rsp)
leaq 0x7f(%rcx), %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
cmpq $0x40, %r14
je 0x4fff
movl %r14d, %edi
callq 0x50b1
movl %eax, %r15d
movl %r14d, %edi
callq 0x50da
movl %eax, %r12d
leal 0x1(%r15), %ebp
leal -0x1(%r12), %eax
movl %eax, 0x14(%rsp)
leal 0x1(%r12), %eax
movl %eax, 0xc(%rsp)
movl %ebp, 0x18(%rsp)
cmpl $0x8, %ebp
jge 0x49ec
movl %ebp, %edi
movl %r12d, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
leaq 0x19413(%rip), %rcx     # 0x1ddc0
orq %rax, (%rcx,%r14,8)
testl %r12d, %r12d
jle 0x49d2
movl %ebp, %edi
movl 0x14(%rsp), %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14,8)
cmpl $0x6, %r12d
ja 0x49e8
movl %ebp, %edi
movl 0xc(%rsp), %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14,8)
incl %ebp
jmp 0x4990
leal -0x1(%r15), %ebp
movl %ebp, 0x10(%rsp)
testl %ebp, %ebp
js 0x4a5b
movl %ebp, %edi
movl %r12d, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
leaq 0x193b0(%rip), %rcx     # 0x1ddc0
orq %rax, 0x200(%rcx,%r14,8)
testl %r12d, %r12d
jle 0x4a3d
movl %ebp, %edi
movl 0x14(%rsp), %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, 0x200(%rbx,%r14,8)
cmpl $0x6, %r12d
ja 0x4a57
movl %ebp, %edi
movl 0xc(%rsp), %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, 0x200(%rbx,%r14,8)
decl %ebp
jmp 0x49f4
cmpl $0x7, %r15d
movq %r14, (%rsp)
jge 0x4ac0
movl %r14d, %edi
callq 0x5103
movq %rax, %r14
shlq $0x7, %r14
movabsq $0x7f7f7f7f7f7f7f00, %rax # imm = 0x7F7F7F7F7F7F7F00
andq %rax, %r14
movq (%rsp), %rdi
callq 0x5103
shlq $0x9, %rax
movabsq $-0x101010101010200, %rcx # imm = 0xFEFEFEFEFEFEFE00
andq %rcx, %rax
orq %r14, %rax
movq (%rsp), %r14
leaq 0x18f17(%rip), %rcx     # 0x1d9c0
movq %rax, (%rcx,%r14,8)
testl %r15d, %r15d
jg 0x4acc
xorl %eax, %eax
movabsq $0x7f7f7f7f7f7f7f, %rbp # imm = 0x7F7F7F7F7F7F7F
jmp 0x4aff
leaq 0x18ef9(%rip), %rax     # 0x1d9c0
andq $0x0, (%rax,%r14,8)
movl %r14d, %edi
callq 0x5103
movq %rax, %r14
shrq $0x9, %r14
movabsq $0x7f7f7f7f7f7f7f, %rbp # imm = 0x7F7F7F7F7F7F7F
andq %rbp, %r14
movq (%rsp), %rdi
callq 0x5103
shrq $0x7, %rax
andq %r13, %rax
orq %r14, %rax
movq (%rsp), %r14
leaq 0x18eba(%rip), %rcx     # 0x1d9c0
movq %rax, 0x200(%rcx,%r14,8)
movl %r14d, %edi
callq 0x5103
addq %rax, %rax
andq 0x38(%rsp), %rax
leaq 0x18a9b(%rip), %r13     # 0x1d5c0
orq %rax, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shrq %rax
andq 0x30(%rsp), %rax
orq %rax, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shlq $0x8, %rax
orq %rax, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shrq $0x8, %rax
orq %rax, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shlq $0x9, %rax
movabsq $-0x101010101010200, %rbx # imm = 0xFEFEFEFEFEFEFE00
andq %rbx, %rax
orq %rax, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shlq $0x7, %rax
movabsq $0x7f7f7f7f7f7f7f00, %r14 # imm = 0x7F7F7F7F7F7F7F00
andq %r14, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0x7, %rax
movabsq $0xfefefefefefefe, %rcx # imm = 0xFEFEFEFEFEFEFE
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0x9, %rax
andq %rbp, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shlq $0xa, %rax
movabsq $-0x303030303030400, %rcx # imm = 0xFCFCFCFCFCFCFC00
andq %rcx, %rax
leaq 0x18bc2(%rip), %r13     # 0x1d7c0
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0x6, %rax
movabsq $0xfcfcfcfcfcfcfc, %rcx # imm = 0xFCFCFCFCFCFCFC
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shlq $0x6, %rax
movabsq $0x3f3f3f3f3f3f3f00, %rcx # imm = 0x3F3F3F3F3F3F3F00
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0xa, %rax
movabsq $0x3f3f3f3f3f3f3f, %rcx # imm = 0x3F3F3F3F3F3F3F
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0x11, %rax
movabsq $0x7f7f7f7f7f7f, %rcx   # imm = 0x7F7F7F7F7F7F
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shrq $0xf, %rax
movabsq $0xfefefefefefe, %rcx   # imm = 0xFEFEFEFEFEFE
andq %rcx, %rax
movq (%rsp), %rcx
orq %rax, (%r13,%rcx,8)
movq (%rsp), %rdi
callq 0x5103
shlq $0xf, %rax
leaq -0x7f00(%r14), %rcx
movq (%rsp), %r14
andq %rax, %rcx
orq %rcx, (%r13,%r14,8)
movl %r14d, %edi
callq 0x5103
shlq $0x11, %rax
leaq -0xfe00(%rbx), %rcx
andq %rax, %rcx
orq %rcx, (%r13,%r14,8)
leaq 0xe318(%rip), %rax      # 0x13010
movl (%rax,%r14,4), %ecx
pushq $0x1
popq %rax
movl %ecx, 0x20(%rsp)
shll %cl, %eax
movslq %eax, %rbp
leaq (,%rbp,8), %rdi
callq 0x4030
leaq 0x198a4(%rip), %rcx     # 0x1e5c0
movq %rax, (%rcx,%r14,8)
testl %ebp, %ebp
movl $0x0, %ecx
cmovlel %ecx, %ebp
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x4d3b
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x4d2c
pushq $0x40
popq %rax
subl 0x20(%rsp), %eax
movq %rax, 0x28(%rsp)
xorl %edi, %edi
movq %rbp, 0x40(%rsp)
cmpl %ebp, %edi
je 0x4e49
leaq 0xe3b3(%rip), %rax      # 0x13110
movq (%rax,%r14,8), %rsi
movl %edi, 0x1c(%rsp)
movl 0x20(%rsp), %edx
callq 0x504a
movq %rax, %r13
leaq 0xe598(%rip), %rax      # 0x13310
movq (%rax,%r14,8), %rax
imulq %r13, %rax
movq 0x28(%rsp), %rcx
shrq %cl, %rax
leaq 0x19831(%rip), %rcx     # 0x1e5c0
movq (%rcx,%r14,8), %rbx
movslq %eax, %r14
cmpq $0x0, (%rbx,%r14,8)
jne 0x500e
shlq $0x3, %r14
movl %r12d, %ebp
testl %ebp, %ebp
jle 0x4dc8
decl %ebp
movl %r15d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14)
testq %r13, %rax
je 0x4da8
movl %r12d, %ebp
cmpl $0x6, %ebp
jg 0x4dec
incl %ebp
movl %r15d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14)
testq %r13, %rax
je 0x4dcb
movl 0x18(%rsp), %ebp
cmpl $0x7, %ebp
jg 0x4e11
movl %ebp, %edi
movl %r12d, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14)
incl %ebp
testq %r13, %rax
je 0x4df0
movl 0x10(%rsp), %ebp
testl %ebp, %ebp
js 0x4e35
movl %ebp, %edi
movl %r12d, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%rbx,%r14)
decl %ebp
testq %r13, %rax
je 0x4e15
movl 0x1c(%rsp), %edi
incl %edi
movq (%rsp), %r14
movq 0x40(%rsp), %rbp
jmp 0x4d4e
leaq 0xe6c0(%rip), %rax      # 0x13510
movl (%rax,%r14,4), %ecx
pushq $0x1
popq %rax
movl %ecx, 0x1c(%rsp)
shll %cl, %eax
movslq %eax, %rbp
leaq (,%rbp,8), %rdi
callq 0x4030
leaq 0x1994c(%rip), %rcx     # 0x1e7c0
movq %rax, (%rcx,%r14,8)
testl %ebp, %ebp
movl $0x0, %ecx
cmovlel %ecx, %ebp
xorl %ecx, %ecx
leaq 0x19335(%rip), %rbx     # 0x1e1c0
cmpq %rcx, %rbp
je 0x4e9a
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x4e8b
pushq $0x40
popq %rax
subl 0x1c(%rsp), %eax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movq %rbp, 0x28(%rsp)
cmpl %ebp, %r13d
je 0x4fed
leaq 0xe752(%rip), %rax      # 0x13610
movq (%rax,%r14,8), %rsi
movl %r13d, %edi
movl 0x1c(%rsp), %edx
callq 0x504a
movq %rax, %r15
leaq 0xe938(%rip), %rax      # 0x13810
movq (%rax,%r14,8), %rax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
shrq %cl, %rax
leaq 0x198d1(%rip), %rcx     # 0x1e7c0
movq (%rcx,%r14,8), %r12
movslq %eax, %rbx
cmpq $0x0, (%r12,%rbx,8)
jne 0x502b
shlq $0x3, %rbx
movl 0x14(%rsp), %ebp
movl 0x18(%rsp), %r14d
testl %ebp, %ebp
js 0x4f39
cmpl $0x7, %r14d
jg 0x4f39
movl %r14d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%r12,%rbx)
testq %r15, %rax
jne 0x4f39
decl %ebp
incl %r14d
jmp 0x4f0e
movl 0xc(%rsp), %ebp
movl 0x18(%rsp), %r14d
cmpl $0x7, %ebp
jg 0x4f6e
cmpl $0x7, %r14d
jg 0x4f6e
movl %r14d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%r12,%rbx)
testq %r15, %rax
jne 0x4f6e
incl %ebp
incl %r14d
jmp 0x4f42
movl 0xc(%rsp), %ebp
movl 0x10(%rsp), %r14d
cmpl $0x7, %ebp
jg 0x4fa2
testl %r14d, %r14d
js 0x4fa2
movl %r14d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%r12,%rbx)
testq %r15, %rax
jne 0x4fa2
incl %ebp
decl %r14d
jmp 0x4f77
movl 0x14(%rsp), %ebp
movl 0x10(%rsp), %r14d
testl %ebp, %ebp
js 0x4fd5
testl %r14d, %r14d
js 0x4fd5
movl %r14d, %edi
movl %ebp, %esi
callq 0x5131
movl %eax, %edi
callq 0x5103
orq %rax, (%r12,%rbx)
testq %r15, %rax
jne 0x4fd5
decl %ebp
decl %r14d
jmp 0x4fab
incl %r13d
leaq 0x191e1(%rip), %rbx     # 0x1e1c0
movq (%rsp), %r14
movq 0x28(%rsp), %rbp
jmp 0x4eae
incq %r14
movabsq $0xfefefefefefefe, %r13 # imm = 0xFEFEFEFEFEFEFE
jmp 0x4956
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe9fb(%rip), %rdi      # 0x13a10
leaq 0xea0e(%rip), %rsi      # 0x13a2a
leaq 0xea17(%rip), %rcx      # 0x13a3a
pushq $0x64
popq %rdx
callq 0x41f0
leaq 0xea28(%rip), %rdi      # 0x13a5a
leaq 0xe9f1(%rip), %rsi      # 0x13a2a
leaq 0xe9fa(%rip), %rcx      # 0x13a3a
movl $0x91, %edx
callq 0x41f0