// File: /workspace/github_cpp_makefile_star2_O1/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), %rax
movl %esi, %ecx
imulq $0x28f5c29, %rcx, %rcx  # imm = 0x28F5C29
shrq $0x20, %rcx
imull $0x64, %ecx, %edx
subl %edx, %esi
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rax, %rcx
addq $0xc, %rcx
leaq (%rsi,%rsi,2), %rdx
movzwl 0x2(%rcx,%rdx,4), %r15d
imulq $0x28f5c29, %r15, %rcx  # imm = 0x28F5C29
shrq $0x20, %rcx
imull $0x64, %ecx, %edx
movl %r15d, %esi
subl %edx, %esi
leaq (%rsi,%rsi,2), %r9
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
leaq (%rax,%rcx), %r13
addq $0xc, %r13
movsbl (%r13,%r9,4), %edx
movb $0x1, %bpl
cmpl $0x4f, %edx
jg 0x298ec
movq %rdi, %rbx
movq 0x4e28(%rdi), %r8
movzwl (%r8,%r15,2), %r14d
testb %dl, %dl
js 0x29881
movabsq $0x4332322132212110, %rdi # imm = 0x4332322132212110
cmpl $0xfff, %r14d           # imm = 0xFFF
ja 0x29a57
movl %r14d, %eax
shll $0x4, %eax
movl %r14d, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %r14d, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %rdi, %rsi
shrq %cl, %rsi
shrl $0x6, %eax
andb $0x3c, %al
movq %rdi, %r8
movl %eax, %ecx
shrq %cl, %r8
movl %r14d, %eax
shrl $0x4, %eax
orl %r14d, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %rdi, %r12
shrq %cl, %r12
shrl $0x6, %eax
andb $0x3c, %al
movl %eax, %ecx
shrq %cl, %rdi
addl %r8d, %esi
andb $0xf, %sil
addl %edi, %r12d
andb $0xf, %r12b
movl %r14d, %eax
shrl $0x8, %eax
testl %r14d, %eax
setne %al
cmpb %sil, %dl
jb 0x298ea
cmpb %r12b, %dl
ja 0x298ea
cmpb %r12b, %sil
je 0x298ec
cmpb %sil, %dl
jne 0x298fd
movl %r15d, %r12d
movq 0x4e28(%rbx), %rax
movzwl %r12w, %r14d
movzwl (%rax,%r14,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 0x29867
incl 0xc8334(%rbx)
movzwl %ax, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x29512
testb %al, %al
je 0x29872
movzwl 0x8(%rbx,%r14,2), %r12d
movb $0x1, %bpl
jmp 0x29874
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x298ec
cmpw %r15w, %r12w
jne 0x2982a
jmp 0x298ec
testl $0x550, %r14d           # imm = 0x550
sete %al
testb $0xa, %r14b
setne %cl
orb %al, %cl
jne 0x298b5
incl 0xc8334(%rbx)
movzwl %r15w, %esi
movl %r14d, %edx
andl $0xaa5, %edx            # imm = 0xAA5
movq %rbx, %rdi
callq 0x29512
testb %al, %al
je 0x298ea
testl $0xaa0, %r14d           # imm = 0xAA0
sete %al
testb $0x5, %r14b
setne %cl
orb %al, %cl
jne 0x298ec
incl 0xc8334(%rbx)
movzwl %r15w, %esi
andl $0x55a, %r14d           # imm = 0x55A
movq %rbx, %rdi
movl %r14d, %edx
callq 0x29512
testb %al, %al
jne 0x298ec
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb %r12b, %dl
jne 0x2995c
movl %r15d, %r12d
movq 0x4e28(%rbx), %rax
movzwl %r12w, %r14d
movzwl (%rax,%r14,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 0x29942
incl 0xc8334(%rbx)
movzwl %ax, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x29512
testb %al, %al
je 0x2994d
movzwl 0x8(%rbx,%r14,2), %r12d
movb $0x1, %bpl
jmp 0x2994f
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x298ec
cmpw %r15w, %r12w
jne 0x29905
jmp 0x298ec
testb %al, %al
je 0x298ec
movzbl %sil, %eax
decl %edx
cmpl %eax, %edx
jne 0x299da
movl %r15d, %edx
movq %r9, 0x8(%rsp)
movq 0x4e28(%rbx), %rax
movzwl %dx, %r14d
movzwl (%rax,%r14,2), %ecx
movl %ecx, %eax
shll $0x8, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x299b8
addl $0x2, 0xc8334(%rbx)
movw %dx, 0x10(%rsp)
movzwl %ax, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x29512
movzwl 0x10(%rsp), %edx
movq 0x8(%rsp), %r9
testb %al, %al
je 0x299c2
movzwl 0x8(%rbx,%r14,2), %edx
movb $0x1, %al
jmp 0x299c4
xorl %eax, %eax
testb %al, %al
je 0x298ea
cmpw %r15w, %dx
jne 0x29972
testb %al, %al
je 0x298ea
leaq (,%r9,4), %rax
addq %r13, %rax
movzbl %r12b, %ecx
movsbl (%rax), %eax
incl %eax
cmpl %ecx, %eax
jne 0x298ec
movl %r15d, %r12d
movq 0x4e28(%rbx), %rax
movzwl %r12w, %r14d
movzwl (%rax,%r14,2), %ecx
movl %ecx, %eax
shrl $0x8, %eax
notl %eax
andl %ecx, %eax
cmpw %ax, %cx
je 0x29a30
addl $0x2, 0xc8334(%rbx)
movzwl %ax, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x29512
testb %al, %al
je 0x29a3a
movzwl 0x8(%rbx,%r14,2), %r12d
movb $0x1, %al
jmp 0x29a3c
xorl %eax, %eax
testb %al, %al
je 0x298ea
cmpw %r15w, %r12w
jne 0x299f9
testb %al, %al
je 0x298ea
jmp 0x298ec
xorl %esi, %esi
xorl %r12d, %r12d
xorl %r10d, %r10d
movl %r15d, %ecx
movq %r9, 0x8(%rsp)
movq %r10, 0x20(%rsp)
movzwl %cx, %eax
addl %eax, %eax
movq %rax, 0x10(%rsp)
movzwl (%r8,%rax), %r14d
movl %r14d, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %r9d
movl %eax, 0x1c(%rsp)
movl %r14d, %eax
shll $0x4, %eax
movl %r14d, %ecx
shll $0x8, %ecx
orl %eax, %ecx
notl %ecx
andl %r9d, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %rdi, %r9
shrq %cl, %r9
shrl $0x6, %eax
andb $0x3c, %al
movq %rdi, %r10
movl %eax, %ecx
shrq %cl, %r10
movl %r14d, %r11d
shrl $0x8, %r11d
andl %r14d, %r11d
movl %r14d, %eax
andl $0xff0, %eax            # imm = 0xFF0
shrl $0x4, %eax
orl 0x1c(%rsp), %eax
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3c, %cl
movq %rdi, %r14
shrq %cl, %r14
addl %r10d, %r9d
shrl $0x6, %eax
andb $0x3c, %al
movq %rdi, %r10
movl %eax, %ecx
shrq %cl, %r10
andb $0xf, %r9b
addb %r9b, %sil
movq 0x8(%rsp), %r9
addl %r10d, %r14d
andb $0xf, %r14b
addb %r14b, %r12b
andl $0xf, %r11d
xorl %eax, %eax
orw 0x20(%rsp), %r11w
setne %al
movq 0x10(%rsp), %rcx
movzwl 0x8(%rbx,%rcx), %ecx
movl %eax, %r10d
cmpw %r15w, %cx
jne 0x29a67
jmp 0x29803
nop