// File: Alcaro[P]bridges/solver.cpp
// Function: (anonymous namespace)::solver<((anonymous namespace)::op_t)3>::fill_simple(unsigned short)
bool fill_simple(uint16_t index)
	{
		index = map.get(index).rootnode;
		gamemap::island& here = map.get(index);
		
		if (here.population >= 80) return true; // these ones don't care about how many bridges they have
		
		if (here.population < 0)
		{
			uint16_t flags = possibilities[index];
			
			//ocean tile with mandatory vertical bridge and allowed horizontal -> require zero horizontal
			if ((flags & 0x0550) != 0 && (flags & 0x000A) == 0)
			{
				add_difficulty(1);
				if (!set_state(index, flags & 0x0AAF)) return false;
			}
			//mandatory horizontal -> ban vertical
			if ((flags & 0x0AA0) != 0 && (flags & 0x0005) == 0)
			{
				add_difficulty(1);
				if (!set_state(index, flags & 0x055F)) return false;
			}
			
			//if (!(flags&0x1111) || !(flags&0x2222) || !(flags&0x4444) || !(flags&0x8888)) return false;
			return true;
		}
		
		
		uint8_t min;
		uint8_t max;
		bool has_doubles;
		count_bridges(index, min, max, has_doubles);
		
		if (here.population < min || here.population > max) return false;
		if (min == max) return true;
		
		//if no further bridges can be built, ban the options
		if (here.population == min)
		{
			uint16_t ni = index;
			do {
				uint16_t flags = possibilities[ni];
				uint16_t flags_min = (flags & ~(flags<<4 | flags<<8));
				if (flags != flags_min)
				{
					add_difficulty(1);
					if (!set_state(ni, flags_min)) return false;
				}
				
				ni = nextjoined[ni];
			} while (ni != index);
			
			return true;
		}
		
		//if all possible bridges must be built, do that
		if (here.population == max)
		{
			uint16_t ni = index;
			do {
				uint16_t flags = possibilities[ni];
				uint16_t flags_max = (flags & ~(flags>>4 | flags>>8));
				if (flags != flags_max)
				{
					add_difficulty(1);
					if (!set_state(ni, flags_max)) return false;
				}
				
				ni = nextjoined[ni];
			} while (ni != index);
			
			return true;
		}
		
		//if only one more bridge is free, or all but one must be taken, lock all two-bridge possibilities
		if (!has_doubles) return true; // no two-bridge possibilities open -> skip checks
		
		if (here.population-1 == min)
		{
			uint16_t ni = index;
			do {
				uint16_t flags = possibilities[ni];
				uint16_t flags_min_minus1 = (flags & ~(flags<<8));
				if (flags != flags_min_minus1)
				{
					add_difficulty(2);
					if (!set_state(ni, flags_min_minus1)) return false;
				}
				
				ni = nextjoined[ni];
			} while (ni != index);
		}
		if (here.population+1 == max)
		{
			uint16_t ni = index;
			do {
				uint16_t flags = possibilities[ni];
				uint16_t flags_max_minus1 = (flags & ~(flags>>8));
				if (flags != flags_max_minus1)
				{
					add_difficulty(2);
					if (!set_state(ni, flags_max_minus1)) return false;
				}
				
				ni = nextjoined[ni];
			} while (ni != index);
		}
		
		return true;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movw %si, %ax
movq %rdi, -0x68(%rbp)
movw %ax, -0x6a(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq (%rax), %rdi
movzwl -0x6a(%rbp), %esi
callq 0x4e8e0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movw 0x2(%rcx), %cx
movw %cx, -0x6a(%rbp)
movq (%rax), %rdi
movzwl -0x6a(%rbp), %esi
callq 0x4e8e0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x50, %eax
jl 0x591a4
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jge 0x592a3
movq -0xa0(%rbp), %rax
movq 0x4e28(%rax), %rax
movzwl -0x6a(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x7a(%rbp)
movzwl -0x7a(%rbp), %eax
andl $0x550, %eax            # imm = 0x550
cmpl $0x0, %eax
je 0x59234
movzwl -0x7a(%rbp), %eax
andl $0xa, %eax
cmpl $0x0, %eax
jne 0x59234
movq -0xa0(%rbp), %rdi
movq %rdi, -0x8(%rbp)
movl $0x1, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x6a(%rbp), %cx
movzwl -0x7a(%rbp), %eax
andl $0xaaf, %eax            # imm = 0xAAF
movzwl %cx, %esi
movzwl %ax, %edx
callq 0x58e80
testb $0x1, %al
jne 0x59232
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x59234
movzwl -0x7a(%rbp), %eax
andl $0xaa0, %eax            # imm = 0xAA0
cmpl $0x0, %eax
je 0x5929a
movzwl -0x7a(%rbp), %eax
andl $0x5, %eax
cmpl $0x0, %eax
jne 0x5929a
movq -0xa0(%rbp), %rdi
movq %rdi, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x6a(%rbp), %cx
movzwl -0x7a(%rbp), %eax
andl $0x55f, %eax            # imm = 0x55F
movzwl %cx, %esi
movzwl %ax, %edx
callq 0x58e80
testb $0x1, %al
jne 0x59298
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x5929a
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
movq -0xa0(%rbp), %rdi
leaq -0x7b(%rbp), %rdx
leaq -0x7c(%rbp), %rcx
leaq -0x7d(%rbp), %r8
movzwl -0x6a(%rbp), %esi
callq 0x59b30
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
movzbl -0x7b(%rbp), %ecx
cmpl %ecx, %eax
jl 0x592dd
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
movzbl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x592e6
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
movzbl -0x7b(%rbp), %eax
movzbl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x592fb
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
movzbl -0x7b(%rbp), %ecx
cmpl %ecx, %eax
jne 0x593e2
movw -0x6a(%rbp), %ax
movw %ax, -0x80(%rbp)
movq -0xa0(%rbp), %rax
movq 0x4e28(%rax), %rax
movzwl -0x80(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x82(%rbp)
movzwl -0x82(%rbp), %eax
movzwl -0x82(%rbp), %ecx
shll $0x4, %ecx
movzwl -0x82(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movw %ax, -0x84(%rbp)
movzwl -0x82(%rbp), %eax
movzwl -0x84(%rbp), %ecx
cmpl %ecx, %eax
je 0x593b5
movq -0xa0(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x80(%rbp), %ax
movzwl %ax, %esi
movzwl -0x84(%rbp), %edx
callq 0x58e80
testb $0x1, %al
jne 0x593b3
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x593b5
movq -0xa0(%rbp), %rax
movzwl -0x80(%rbp), %ecx
movw 0x8(%rax,%rcx,2), %ax
movw %ax, -0x80(%rbp)
movzwl -0x80(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x59316
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
movzbl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x594db
movw -0x6a(%rbp), %ax
movw %ax, -0x86(%rbp)
movq -0xa0(%rbp), %rax
movq 0x4e28(%rax), %rax
movzwl -0x86(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x88(%rbp)
movzwl -0x88(%rbp), %eax
movzwl -0x88(%rbp), %ecx
sarl $0x4, %ecx
movzwl -0x88(%rbp), %edx
sarl $0x8, %edx
orl %edx, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movw %ax, -0x8a(%rbp)
movzwl -0x88(%rbp), %eax
movzwl -0x8a(%rbp), %ecx
cmpl %ecx, %eax
je 0x594a5
movq -0xa0(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x86(%rbp), %ax
movzwl %ax, %esi
movzwl -0x8a(%rbp), %edx
callq 0x58e80
testb $0x1, %al
jne 0x594a3
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x594a5
movq -0xa0(%rbp), %rax
movzwl -0x86(%rbp), %ecx
movw 0x8(%rax,%rcx,2), %ax
movw %ax, -0x86(%rbp)
movzwl -0x86(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x59400
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
testb $0x1, -0x7d(%rbp)
jne 0x594ea
movb $0x1, -0x5d(%rbp)
jmp 0x596bd
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
subl $0x1, %eax
movzbl -0x7b(%rbp), %ecx
cmpl %ecx, %eax
jne 0x595d3
movw -0x6a(%rbp), %ax
movw %ax, -0x8c(%rbp)
movq -0xa0(%rbp), %rax
movq 0x4e28(%rax), %rax
movzwl -0x8c(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x8e(%rbp)
movzwl -0x8e(%rbp), %eax
movzwl -0x8e(%rbp), %ecx
shll $0x8, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movw %ax, -0x90(%rbp)
movzwl -0x8e(%rbp), %eax
movzwl -0x90(%rbp), %ecx
cmpl %ecx, %eax
je 0x595a4
movq -0xa0(%rbp), %rdi
movq %rdi, -0x48(%rbp)
movl $0x2, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x8c(%rbp), %ax
movzwl %ax, %esi
movzwl -0x90(%rbp), %edx
callq 0x58e80
testb $0x1, %al
jne 0x595a2
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x595a4
movq -0xa0(%rbp), %rax
movzwl -0x8c(%rbp), %ecx
movw 0x8(%rax,%rcx,2), %ax
movw %ax, -0x8c(%rbp)
movzwl -0x8c(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5950b
jmp 0x595d3
movq -0x78(%rbp), %rax
movsbl (%rax), %eax
addl $0x1, %eax
movzbl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x596b9
movw -0x6a(%rbp), %ax
movw %ax, -0x92(%rbp)
movq -0xa0(%rbp), %rax
movq 0x4e28(%rax), %rax
movzwl -0x92(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x94(%rbp)
movzwl -0x94(%rbp), %eax
movzwl -0x94(%rbp), %ecx
sarl $0x8, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movw %ax, -0x96(%rbp)
movzwl -0x94(%rbp), %eax
movzwl -0x96(%rbp), %ecx
cmpl %ecx, %eax
je 0x5968a
movq -0xa0(%rbp), %rdi
movq %rdi, -0x58(%rbp)
movl $0x2, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl 0xc8334(%rax), %ecx
movl %ecx, 0xc8334(%rax)
movw -0x92(%rbp), %ax
movzwl %ax, %esi
movzwl -0x96(%rbp), %edx
callq 0x58e80
testb $0x1, %al
jne 0x59688
movb $0x0, -0x5d(%rbp)
jmp 0x596bd
jmp 0x5968a
movq -0xa0(%rbp), %rax
movzwl -0x92(%rbp), %ecx
movw 0x8(%rax,%rcx,2), %ax
movw %ax, -0x92(%rbp)
movzwl -0x92(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x595f4
jmp 0x596b9
movb $0x1, -0x5d(%rbp)
movb -0x5d(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)