// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %r14
movq (%rdi), %rax
movl %esi, %ecx
shrl $0x2, %ecx
imull $0x147b, %ecx, %ecx     # imm = 0x147B
shrl $0x11, %ecx
imull $0x64, %ecx, %edx
subl %edx, %esi
movl $0xffff, %edx           # imm = 0xFFFF
andl %edx, %esi
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rax, %rcx
addq $0xc, %rcx
leaq (%rsi,%rsi,2), %rsi
movzwl 0x2(%rcx,%rsi,4), %r12d
movl %r12d, %ecx
shrl $0x2, %ecx
imull $0x147b, %ecx, %ecx     # imm = 0x147B
shrl $0x11, %ecx
imull $0x64, %ecx, %esi
movl %r12d, %edi
subl %esi, %edi
andl %edx, %edi
leaq (%rdi,%rdi,2), %rsi
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
leaq (%rax,%rcx), %rdi
addq $0xc, %rdi
movsbl (%rdi,%rsi,4), %edx
movb $0x1, %bl
cmpl $0x4f, %edx
jg 0x29d97
movq 0x4e28(%r14), %r10
movzwl (%r10,%r12,2), %ebp
testb %dl, %dl
js 0x29d2f
movabsq $0x4332322132212110, %r9 # imm = 0x4332322132212110
cmpl $0xfff, %ebp            # imm = 0xFFF
ja 0x29ebf
movl %ebp, %eax
shll $0x4, %eax
movl %ebp, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %ebp, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r9, %r8
shrq %cl, %r8
shrl $0x6, %eax
andb $0x3c, %al
movq %r9, %r10
movl %eax, %ecx
shrq %cl, %r10
movl %ebp, %eax
shrl $0x4, %eax
orl %ebp, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r9, %r13
shrq %cl, %r13
shrl $0x6, %eax
andb $0x3c, %al
movl %eax, %ecx
shrq %cl, %r9
addl %r10d, %r8d
andb $0xf, %r8b
addl %r9d, %r13d
andb $0xf, %r13b
movl %ebp, %eax
shrl $0x8, %eax
testl %ebp, %eax
setne %al
cmpb %r8b, %dl
jb 0x29d95
cmpb %r13b, %dl
ja 0x29d95
cmpb %r13b, %r8b
je 0x29d97
cmpb %r8b, %dl
jne 0x29da8
movl %r12d, %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 0x29d21
incl 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x2996a
testb %al, %al
je 0x29d95
movzwl 0x8(%r14,%r15,2), %eax
cmpw %r12w, %ax
jne 0x29ce3
jmp 0x29d97
testl $0x550, %ebp            # imm = 0x550
sete %al
testb $0xa, %bpl
setne %cl
orb %al, %cl
jne 0x29d62
incl 0xc8334(%r14)
movzwl %r12w, %esi
movl %ebp, %edx
andl $0xaa5, %edx            # imm = 0xAA5
movq %r14, %rdi
callq 0x2996a
testb %al, %al
je 0x29d95
testl $0xaa0, %ebp            # imm = 0xAA0
sete %al
testb $0x5, %bpl
setne %cl
orb %al, %cl
jne 0x29d97
incl 0xc8334(%r14)
movzwl %r12w, %esi
andl $0x55a, %ebp            # imm = 0x55A
movq %r14, %rdi
movl %ebp, %edx
callq 0x2996a
testb %al, %al
jne 0x29d97
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb %r13b, %dl
jne 0x29dfc
movl %r12d, %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 0x29dee
incl 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x2996a
testb %al, %al
je 0x29d95
movzwl 0x8(%r14,%r15,2), %eax
cmpw %r12w, %ax
jne 0x29db0
jmp 0x29d97
testb %al, %al
je 0x29d97
movzbl %r8b, %eax
movl %edx, %ecx
decl %ecx
cmpl %eax, %ecx
jne 0x29e5e
leaq (%rdi,%rsi,4), %rbp
movl %r12d, %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 0x29e4f
addl $0x2, 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x2996a
testb %al, %al
je 0x29d95
movzwl 0x8(%r14,%r15,2), %eax
cmpw %r12w, %ax
jne 0x29e13
movb (%rbp), %dl
movzbl %r13b, %eax
movsbl %dl, %ecx
incl %ecx
cmpl %eax, %ecx
jne 0x29d97
movl %r12d, %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 0x29eae
addl $0x2, 0xc8334(%r14)
movzwl %ax, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x2996a
testb %al, %al
je 0x29d95
movzwl 0x8(%r14,%r15,2), %eax
cmpw %r12w, %ax
jne 0x29e72
jmp 0x29d97
xorl %r8d, %r8d
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movl %r12d, %ecx
movzwl %cx, %eax
addl %eax, %eax
movq %rax, 0x20(%rsp)
movzwl (%r10,%rax), %r15d
movl %r15d, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %ebp
movl %eax, 0x8(%rsp)
movl %r15d, %eax
shll $0x4, %eax
movl %r15d, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %ebp, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r9, %r11
shrq %cl, %r11
shrl $0x6, %eax
andb $0x3c, %al
movq %r9, %rbp
movl %eax, %ecx
shrq %cl, %rbp
movq %rbp, 0x18(%rsp)
movl %r15d, %ebp
shrl $0x8, %ebp
andl %r15d, %ebp
movl %r15d, %eax
andl $0xff0, %eax            # imm = 0xFF0
shrl $0x4, %eax
orl 0x8(%rsp), %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %r9, %r15
shrq %cl, %r15
addl 0x18(%rsp), %r11d
movq %r11, 0x8(%rsp)
shrl $0x6, %eax
andb $0x3c, %al
movq %r9, %r11
movl %eax, %ecx
shrq %cl, %r11
movq 0x8(%rsp), %rax
andb $0xf, %al
addb %al, %r8b
addl %r11d, %r15d
andb $0xf, %r15b
addb %r15b, %r13b
andl $0xf, %ebp
xorl %eax, %eax
orw 0x10(%rsp), %bp
setne %al
movq 0x20(%rsp), %rcx
movzwl 0x8(%r14,%rcx), %ecx
movl %eax, %r11d
movq %r11, 0x10(%rsp)
cmpw %r12w, %cx
jne 0x29ed1
jmp 0x29cbc
nop