// File: 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
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x56de7
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x56dd7
movq -0x68(%rbp), %rax
imull $0x64, -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movw %cx, -0x22(%rbp)
movq -0x10(%rbp), %rcx
addq $0xc, %rcx
movslq -0x1c(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rcx
movslq -0x20(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, -0x30(%rbp)
movzwl -0x22(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jl 0x56dc7
movq -0x18(%rbp), %rax
movzwl -0x22(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x3a(%rbp)
movzwl -0x3a(%rbp), %eax
andl $0x1110, %eax           # imm = 0x1110
cmpl $0x0, %eax
je 0x56cc9
movzwl -0x22(%rbp), %eax
movq -0x30(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x6c(%rbp)
jmp 0x56cd3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x6c(%rbp)
jmp 0x56cd3
movl -0x6c(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, (%rax)
movzwl -0x3a(%rbp), %eax
andl $0x2220, %eax           # imm = 0x2220
cmpl $0x0, %eax
je 0x56d04
movzwl -0x22(%rbp), %eax
movq -0x30(%rbp), %rcx
movsbl 0x5(%rcx), %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0x70(%rbp)
jmp 0x56d0e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x70(%rbp)
jmp 0x56d0e
movl -0x70(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x2(%rax)
movzwl -0x3a(%rbp), %eax
andl $0x4440, %eax           # imm = 0x4440
cmpl $0x0, %eax
je 0x56d3d
movzwl -0x22(%rbp), %eax
movq -0x30(%rbp), %rcx
movsbl 0x6(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x74(%rbp)
jmp 0x56d47
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x74(%rbp)
jmp 0x56d47
movl -0x74(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x4(%rax)
movzwl -0x3a(%rbp), %eax
andl $0x8880, %eax           # imm = 0x8880
cmpl $0x0, %eax
je 0x56d79
movzwl -0x22(%rbp), %eax
movq -0x30(%rbp), %rcx
movsbl 0x7(%rcx), %ecx
imull $0x64, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x78(%rbp)
jmp 0x56d83
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x78(%rbp)
jmp 0x56d83
movl -0x78(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x6(%rax)
movw -0x22(%rbp), %cx
movq -0x38(%rbp), %rax
movw %cx, 0x8(%rax)
movw -0x22(%rbp), %cx
movq -0x38(%rbp), %rax
movw %cx, 0xa(%rax)
movw -0x22(%rbp), %cx
movq -0x38(%rbp), %rax
movw %cx, 0xc(%rax)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0xe(%rax)
jmp 0x56dc9
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x56c36
jmp 0x56dd9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x56c1f
movq -0x68(%rbp), %rax
movw $0x0, 0x27102(%rax)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x56f20
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x56f10
movq -0x68(%rbp), %rax
imull $0x64, -0x40(%rbp), %ecx
addl -0x44(%rbp), %ecx
movw %cx, -0x46(%rbp)
movq -0x10(%rbp), %rcx
addq $0xc, %rcx
movslq -0x40(%rbp), %rdx
imulq $0x4b0, %rdx, %rdx      # imm = 0x4B0
addq %rdx, %rcx
movslq -0x44(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movzwl -0x46(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x1, %eax
jne 0x56ed3
movl $0x0, -0x5c(%rbp)
cmpl $0x4, -0x5c(%rbp)
jge 0x56ed1
movq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x56ec4
movq -0x68(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x5c(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
xorl $0x2, %ecx
movslq %ecx, %rcx
movw $0xffff, (%rax,%rcx,2)  # imm = 0xFFFF
movq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movw $0xffff, (%rax,%rcx,2)  # imm = 0xFFFF
jmp 0x56ec6
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x56e77
jmp 0x56ed3
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x1, %eax
jle 0x56f00
movq -0x68(%rbp), %rax
movw -0x46(%rbp), %cx
movw %cx, 0x27100(%rax)
movw 0x27102(%rax), %cx
addw $0x1, %cx
movw %cx, 0x27102(%rax)
jmp 0x56f02
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x56e12
jmp 0x56f12
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x56dfb
popq %rbp
retq
nopw %cs:(%rax,%rax)