// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %eax
movq (%rdi), %rcx
movw $0x64, %si
xorl %edx, %edx
divw %si
movzwl %ax, %eax
movzwl %dx, %edx
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
addq %rcx, %rax
addq $0xc, %rax
imulq $0xc, %rdx, %rdx
movzwl 0x2(%rdx,%rax), %ebp
movl %ebp, %eax
xorl %edx, %edx
divw %si
movzwl %ax, %eax
movzwl %dx, %edx
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
leaq (%rcx,%rax), %r13
addq $0xc, %r13
imulq $0xc, %rdx, %rsi
movsbl (%rsi,%r13), %edx
movb $0x1, %bl
cmpl $0x4f, %edx
jg 0x23050
movq %rdi, %r14
movzwl %bp, %r12d
movq 0x4e28(%rdi), %r9
movzwl (%r9,%r12,2), %r15d
testb %dl, %dl
js 0x22fe7
movabsq $0x4332322132212110, %r8 # imm = 0x4332322132212110
cmpw $0xfff, %r15w           # imm = 0xFFF
ja 0x23172
movl %r15d, %eax
shll $0x4, %eax
movl %r15d, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %r15d, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r8, %rdi
shrq %cl, %rdi
shrl $0x6, %eax
andb $0x3c, %al
movq %r8, %r9
movl %eax, %ecx
shrq %cl, %r9
movl %r15d, %eax
shrl $0x4, %eax
orl %r15d, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r8, %r12
shrq %cl, %r12
shrl $0x6, %eax
andb $0x3c, %al
movl %eax, %ecx
shrq %cl, %r8
addl %r9d, %edi
andb $0xf, %dil
addl %r8d, %r12d
andb $0xf, %r12b
movl %r15d, %eax
shrl $0x8, %eax
testl %r15d, %eax
setne %al
cmpb %dil, %dl
jb 0x2304e
cmpb %r12b, %dl
ja 0x2304e
cmpb %r12b, %dil
je 0x23050
cmpb %dil, %dl
jne 0x23061
movl %ebp, %eax
movq 0x4e28(%r14), %rcx
movzwl %ax, %r15d
movzwl (%rcx,%r15,2), %ecx
movl %ecx, %edx
shll $0x4, %edx
movl %ecx, %eax
shll $0x8, %eax
orl %edx, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x22fda
incl 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x22c90
testb %al, %al
je 0x2304e
movzwl 0x8(%r14,%r15,2), %eax
cmpw %bp, %ax
jne 0x22f9c
jmp 0x23050
testw $0x550, %r15w           # imm = 0x550
sete %al
testb $0xa, %r15b
setne %cl
orb %al, %cl
jne 0x2301a
incl 0xc8334(%r14)
movl %r15d, %edx
andl $0xaa5, %edx            # imm = 0xAA5
movq %r14, %rdi
movl %r12d, %esi
callq 0x22c90
testb %al, %al
je 0x2304e
testw $0xaa0, %r15w           # imm = 0xAA0
sete %al
testb $0x5, %r15b
setne %cl
orb %al, %cl
jne 0x23050
incl 0xc8334(%r14)
andl $0x55a, %r15d           # imm = 0x55A
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x22c90
testb %al, %al
jne 0x23050
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb %r12b, %dl
jne 0x230b3
movl %ebp, %eax
movq 0x4e28(%r14), %rcx
movzwl %ax, %r15d
movzwl (%rcx,%r15,2), %ecx
movl %ecx, %edx
shrl $0x4, %edx
movl %ecx, %eax
shrl $0x8, %eax
orl %edx, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x230a6
incl 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x22c90
testb %al, %al
je 0x2304e
movzwl 0x8(%r14,%r15,2), %eax
cmpw %bp, %ax
jne 0x23068
jmp 0x23050
testb %al, %al
je 0x23050
movzbl %dil, %eax
movl %edx, %ecx
decl %ecx
cmpl %eax, %ecx
jne 0x23113
addq %rsi, %r13
movl %ebp, %eax
movq 0x4e28(%r14), %rcx
movzwl %ax, %r15d
movzwl (%rcx,%r15,2), %ecx
movl %ecx, %eax
shll $0x8, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x23104
addl $0x2, 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x22c90
testb %al, %al
je 0x2304e
movzwl 0x8(%r14,%r15,2), %eax
cmpw %bp, %ax
jne 0x230c8
movb (%r13), %dl
movzbl %r12b, %eax
movsbl %dl, %ecx
incl %ecx
cmpl %eax, %ecx
jne 0x23050
movl %ebp, %eax
movq 0x4e28(%r14), %rcx
movzwl %ax, %r15d
movzwl (%rcx,%r15,2), %ecx
movl %ecx, %eax
shrl $0x8, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x23162
addl $0x2, 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x22c90
testb %al, %al
je 0x2304e
movzwl 0x8(%r14,%r15,2), %eax
cmpw %bp, %ax
jne 0x23126
jmp 0x23050
xorl %edi, %edi
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movl %ebp, %ecx
movzwl %cx, %eax
addl %eax, %eax
movq %rax, 0x20(%rsp)
movzwl (%r9,%rax), %r11d
movl %r11d, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %r15d
movl %eax, 0x8(%rsp)
movl %r11d, %eax
shll $0x4, %eax
movl %r11d, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %r15d, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r8, %r10
shrq %cl, %r10
shrl $0x6, %eax
andb $0x3c, %al
movq %r8, %r15
movl %eax, %ecx
shrq %cl, %r15
movq %r15, 0x18(%rsp)
movl %r11d, %r15d
shrl $0x8, %r15d
andl %r11d, %r15d
movl %r11d, %eax
andl $0xff0, %eax            # imm = 0xFF0
shrl $0x4, %eax
orl 0x8(%rsp), %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r8, %r11
shrq %cl, %r11
addl 0x18(%rsp), %r10d
movq %r10, 0x8(%rsp)
shrl $0x6, %eax
andb $0x3c, %al
movq %r8, %r10
movl %eax, %ecx
shrq %cl, %r10
movq 0x8(%rsp), %rax
andb $0xf, %al
addb %al, %dil
addl %r10d, %r11d
andb $0xf, %r11b
addb %r11b, %r12b
andl $0xf, %r15d
xorl %eax, %eax
orw 0x10(%rsp), %r15w
setne %al
movq 0x20(%rsp), %rcx
movzwl 0x8(%r14,%rcx), %ecx
movl %eax, %r10d
movq %r10, 0x10(%rsp)
cmpw %bp, %cx
jne 0x23182
jmp 0x22f76