// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, -0x10(%rsp)
movslq 0x4(%rsi), %rax
testq %rax, %rax
jle 0x27fcd
movq -0x10(%rsp), %rcx
movl (%rcx), %esi
leaq 0x13(%rcx), %r8
movq %rsi, -0x8(%rsp)
movq %rsi, %rcx
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpl $0x0, -0x8(%rsp)
jle 0x27fb6
xorl %ebx, %ebx
movq %r10, %r14
movsbl -0x7(%r8,%rbx), %ebp
testw %bp, %bp
js 0x27fa6
movzwl %r14w, %r15d
movzwl (%rdx,%r15,2), %r12d
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %cx            # imm = 0xFFFF
testl $0x1110, %r12d          # imm = 0x1110
je 0x27f30
movsbl -0x3(%r8,%rbx), %ecx
addl %r14d, %ecx
shll $0x4, %r15d
addq %rdi, %r15
movw %cx, (%r15)
testl $0x2220, %r12d          # imm = 0x2220
je 0x27f51
movsbl -0x2(%r8,%rbx), %ecx
imull $-0x64, %ecx, %r13d
addl %r14d, %r13d
movw %r13w, 0x2(%r15)
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %cx            # imm = 0xFFFF
testl $0x4440, %r12d          # imm = 0x4440
je 0x27f73
movsbl -0x1(%r8,%rbx), %esi
movl %r14d, %ecx
subl %esi, %ecx
movw %cx, 0x4(%r15)
testl $0x8880, %r12d          # imm = 0x8880
je 0x27f8d
movsbl (%r8,%rbx), %ecx
imull $0x64, %ecx, %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 0x27efd
incq %r11
addq $0x64, %r10
addq $0x4b0, %r8             # imm = 0x4B0
cmpq %rax, %r11
jne 0x27eed
movw $0x0, 0x27102(%rdi)
testl %eax, %eax
jle 0x28090
movq -0x10(%rsp), %rdx
movl (%rdx), %ecx
addq $0xc, %rdx
movq %rdx, -0x10(%rsp)
xorl %edx, %edx
movw $0xffff, %r8w           # imm = 0xFFFF
xorl %r9d, %r9d
testl %ecx, %ecx
jle 0x28081
imulq $0x64, %r9, %r10
imulq $0x4b0, %r9, %r11       # imm = 0x4B0
addq -0x10(%rsp), %r11
movl %edx, %ebx
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rsi
movb (%r11,%rsi,4), %bpl
cmpb $0x1, %bpl
jne 0x2805f
movzwl %bx, %r15d
shll $0x4, %r15d
addq %rdi, %r15
xorl %r12d, %r12d
movzwl (%r15,%r12,2), %esi
cmpq $0xffff, %rsi           # imm = 0xFFFF
je 0x28056
shll $0x4, %esi
addq %rdi, %rsi
movq %r12, %r13
xorq $0x2, %r13
movw %r8w, (%rsi,%r13,2)
movw %r8w, (%r15,%r12,2)
incq %r12
cmpq $0x4, %r12
jne 0x28031
cmpb $0x2, %bpl
jl 0x28077
leal (%r14,%r10), %esi
movw %si, 0x27100(%rdi)
incw 0x27102(%rdi)
incq %r14
incl %ebx
cmpq %rcx, %r14
jne 0x28015
incq %r9
addl $0x64, %edx
cmpq %rax, %r9
jne 0x27ff8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop