// File: /workspace/github_cpp_makefile_star2_O2/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
movl (%rsi), %ecx
xorl %r8d, %r8d
testl %ecx, %ecx
cmovlel %r8d, %ecx
movl 0x4(%rsi), %eax
testl %eax, %eax
cmovlel %r8d, %eax
movq %rax, -0x10(%rsp)
leaq 0xc(%rsi), %rax
movq %rax, -0x8(%rsp)
imulq $0xc, %rcx, %r9
leaq 0x13(%rsi), %r10
xorl %r11d, %r11d
cmpq -0x10(%rsp), %r11
je 0x21adb
movq %r8, %rbx
xorl %r14d, %r14d
cmpq %r14, %r9
je 0x21ac8
movsbl -0x7(%r10,%r14), %ebp
testw %bp, %bp
js 0x21abc
movzwl %bx, %r15d
movzwl (%rdx,%r15,2), %r12d
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %cx            # imm = 0xFFFF
testw $0x1110, %r12w          # imm = 0x1110
je 0x21a4a
movsbl -0x3(%r10,%r14), %ecx
addl %ebx, %ecx
shll $0x4, %r15d
addq %rdi, %r15
movw %cx, (%r15)
testw $0x2220, %r12w          # imm = 0x2220
je 0x21a6a
movsbl -0x2(%r10,%r14), %ecx
imull $-0x64, %ecx, %r13d
addl %ebx, %r13d
movw %r13w, 0x2(%r15)
movw $0xffff, %r13w          # imm = 0xFFFF
movw $0xffff, %cx            # imm = 0xFFFF
testw $0x4440, %r12w          # imm = 0x4440
je 0x21a8a
movsbl -0x1(%r10,%r14), %eax
movl %ebx, %ecx
subl %eax, %ecx
movw %cx, 0x4(%r15)
testw $0x8880, %r12w          # imm = 0x8880
je 0x21aa3
movsbl (%r10,%r14), %eax
imull $0x64, %eax, %r13d
addl %ebx, %r13d
movw %r13w, 0x6(%r15)
movw %bx, 0x8(%r15)
movw %bx, 0xa(%r15)
movw %bx, 0xc(%r15)
movw %bp, 0xe(%r15)
addq $0xc, %r14
incq %rbx
jmp 0x21a10
incq %r11
addq $0x4b0, %r10            # imm = 0x4B0
addq $0x64, %r8
jmp 0x219ff
andw $0x0, 0x27102(%rdi)
movl (%rsi), %edx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
xorl %r8d, %r8d
cmpq -0x10(%rsp), %r8
je 0x21b8c
imulq $0x64, %r8, %r9
imulq $0x4b0, %r8, %r10       # imm = 0x4B0
addq -0x8(%rsp), %r10
movl %esi, %r11d
xorl %ebx, %ebx
cmpq %rdx, %rbx
je 0x21b81
imulq $0xc, %rbx, %rax
movb (%rax,%r10), %bpl
cmpb $0x1, %bpl
jne 0x21b61
movzwl %r11w, %r14d
shll $0x4, %r14d
addq %rdi, %r14
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x21b61
movzwl (%r14,%r15,2), %ecx
cmpq $0xffff, %rcx           # imm = 0xFFFF
je 0x21b5c
shll $0x4, %ecx
addq %rdi, %rcx
movq %r15, %rax
xorq $0x2, %rax
orw $-0x1, (%rcx,%rax,2)
orw $-0x1, (%r14,%r15,2)
incq %r15
jmp 0x21b30
cmpb $0x2, %bpl
jl 0x21b79
leal (%rbx,%r9), %eax
movw %ax, 0x27100(%rdi)
incw 0x27102(%rdi)
incq %rbx
incl %r11d
jmp 0x21b0f
incq %r8
addl $0x64, %esi
jmp 0x21aef
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop