// File: /workspace/github_cpp_makefile_star2_O3/Alcaro[P]bridges/solver.cpp
// Function: (anonymous namespace)::linker::init(gamemap&, unsigned short*)
void init(gamemap& map, uint16_t* possibilities)
	{
		for (int y=0;y<map.height;y++)
		for (int x=0;x<map.width;x++)
		{
			uint16_t index = y*100+x;
			gamemap::island& here = map.map[y][x];
			link_t& lhere = links[index];
			
			if (here.population >= 0)
			{
				uint16_t flags = possibilities[index];
				lhere.links[0] = (flags&0x1110 ? index + here.bridgelen[0]     : -1);
				lhere.links[1] = (flags&0x2220 ? index - here.bridgelen[1]*100 : -1);
				lhere.links[2] = (flags&0x4440 ? index - here.bridgelen[2]     : -1);
				lhere.links[3] = (flags&0x8880 ? index + here.bridgelen[3]*100 : -1);
				
				lhere.join_root = index;
				lhere.join_next = index;
				lhere.join_last = index;
				
				lhere.castlecolor = here.population;
			}
			//else the island will never be touched by these functions
		}
		
		//drop pop-1 nodes
		n_linkable_islands = 0;
		for (int y=0;y<map.height;y++)
		for (int x=0;x<map.width;x++)
		{
			uint16_t index = y*100+x;
			gamemap::island& here = map.map[y][x];
			link_t& lhere = links[index];
			
			if (here.population == 1)
			{
				for (int i=0;i<4;i++)
				{
					if (lhere.links[i] != (uint16_t)-1)
					{
						links[lhere.links[i]].links[i^2] = -1;
						lhere.links[i] = -1;
					}
				}
			}
			if (here.population > 1)
			{
				a_linkable_island = index;
				n_linkable_islands++;
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movslq 0x4(%rsi), %rcx
movq %rcx, -0x10(%rsp)
testq %rcx, %rcx
jle 0x2867d
movl (%rsi), %ecx
movq %rsi, -0x8(%rsp)
leaq 0x13(%rsi), %r8
movq %rcx, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testl %ecx, %ecx
jle 0x285a4
xorl %ebx, %ebx
movq %r10, %r14
movsbl -0x7(%r8,%rbx), %ebp
testw %bp, %bp
js 0x28594
movzwl %r14w, %r15d
movzwl (%rdx,%r15,2), %r12d
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %ax            # imm = 0xFFFF
testl $0x1110, %r12d          # imm = 0x1110
je 0x2851e
movsbl -0x3(%r8,%rbx), %eax
addl %r14d, %eax
shll $0x4, %r15d
addq %rdi, %r15
movw %ax, (%r15)
testl $0x2220, %r12d          # imm = 0x2220
je 0x2853f
movsbl -0x2(%r8,%rbx), %eax
imull $-0x64, %eax, %r13d
addl %r14d, %r13d
movw %r13w, 0x2(%r15)
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %ax            # imm = 0xFFFF
testl $0x4440, %r12d          # imm = 0x4440
je 0x28561
movsbl -0x1(%r8,%rbx), %esi
movl %r14d, %eax
subl %esi, %eax
movw %ax, 0x4(%r15)
testl $0x8880, %r12d          # imm = 0x8880
je 0x2857b
movsbl (%r8,%rbx), %eax
imull $0x64, %eax, %r13d
addl %r14d, %r13d
movw %r13w, 0x6(%r15)
movw %r14w, 0x8(%r15)
movw %r14w, 0xa(%r15)
movw %r14w, 0xc(%r15)
movw %bp, 0xe(%r15)
incq %r14
addq $0xc, %rbx
cmpq %rbx, %r9
jne 0x284eb
incq %r11
addq $0x64, %r10
addq $0x4b0, %r8             # imm = 0x4B0
cmpq -0x10(%rsp), %r11
jne 0x284de
movw $0x0, 0x27102(%rdi)
cmpl $0x0, -0x10(%rsp)
jle 0x28686
movq -0x8(%rsp), %r13
movl (%r13), %ecx
addq $0xc, %r13
xorl %edx, %edx
movw $0xffff, %r8w           # imm = 0xFFFF
xorl %r9d, %r9d
testl %ecx, %ecx
jle 0x2866a
imulq $0x64, %r9, %r10
imulq $0x4b0, %r9, %r11       # imm = 0x4B0
addq %r13, %r11
movl %edx, %ebx
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
movb (%r11,%rax,4), %bpl
cmpb $0x1, %bpl
jne 0x28648
movzwl %bx, %r15d
shll $0x4, %r15d
addq %rdi, %r15
xorl %r12d, %r12d
movzwl (%r15,%r12,2), %eax
cmpq $0xffff, %rax           # imm = 0xFFFF
je 0x2863f
shll $0x4, %eax
addq %rdi, %rax
movq %r12, %rsi
xorq $0x2, %rsi
movw %r8w, (%rax,%rsi,2)
movw %r8w, (%r15,%r12,2)
incq %r12
cmpq $0x4, %r12
jne 0x2861b
cmpb $0x2, %bpl
jl 0x28660
leal (%r14,%r10), %eax
movw %ax, 0x27100(%rdi)
incw 0x27102(%rdi)
incq %r14
incl %ebx
cmpq %rcx, %r14
jne 0x285ff
incq %r9
addl $0x64, %edx
cmpq -0x10(%rsp), %r9
jne 0x285e8
jmp 0x28686
movw $0x0, 0x27102(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop