// File: /workspace/github_cpp_makefile_star2_O1/Alcaro[P]bridges/solver.cpp
// Function: (anonymous namespace)::solver<((anonymous namespace)::op_t)0>::set_state(unsigned short, unsigned short)
bool set_state(uint16_t index, uint16_t newstate)
	{
//verify();
		uint16_t prevstate = possibilities[index];
//printf("SET(%.3i):%.4X->%.4X\n",index,prevstate,newstate);
		
		if (newstate & ~prevstate) abort();
		if (newstate == prevstate) abort();
		
		uint16_t tmp = newstate;
		tmp |= tmp>>4;
		tmp |= tmp>>8;
		if ((tmp&0x000F) != 0x000F) return false;
		
		static const int16_t offsets[4] = { 1, -100, -1, 100 };
		
		for (int dir=0;dir<4;dir++)
		{
			int16_t offset = offsets[dir];
			uint16_t src_bits = ((prevstate^newstate) & (0x0111<<dir));
			uint16_t dst_bits = (dir&2) ? (src_bits>>2) : (src_bits<<2);
			if ((prevstate^newstate) & (0x0111<<dir))
			{
				uint16_t ix2 = index;
				do
				{
//verify(false);
					possibilities[ix2] ^= src_bits;
					if (possibilities[ix2] & src_bits) abort();
					ix2 += offset;
					possibilities[ix2] ^= dst_bits;
					if (possibilities[ix2] & dst_bits) abort();
//verify(false);
				} while (map.get(ix2).population < 0);
			}
		}
//verify();
		
		for (int dir=0;dir<4;dir++)
		{
			int16_t offset = offsets[dir];
			if ((prevstate^newstate) & (0x0111<<dir))
			{
				//don't merge those calls, it's a tiny slowdown for whatever reason
				uint16_t ix2 = index + offset;
				while (map.get(ix2).population < 0)
				{
					if (!fill_simple(ix2)) return false;
					ix2 += offset;
				}
				if (!fill_simple(ix2)) return false;
			}
		}
		
		if (!fill_simple(index)) return false;
		return true;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x4e28(%rdi), %rax
movl %esi, %ecx
movzwl (%rax,%rcx,2), %ebp
movl %ebp, %ecx
notl %ecx
testl %edx, %ecx
jne 0x270ad
movq %rsi, (%rsp)
cmpw %dx, %bp
je 0x270ad
movzwl %dx, %ecx
shrl $0x4, %ecx
orl %edx, %ecx
movzbl %ch, %esi
orl %ecx, %esi
notl %esi
testb $0xf, %sil
jne 0x2709c
movq %rdi, %rbx
xorl %edx, %ebp
xorl %ecx, %ecx
leaq 0xbea6(%rip), %r12      # 0x32dd0
movq (%rsp), %r15
movl $0x111, %edx            # imm = 0x111
shll %cl, %edx
andl %ebp, %edx
movl %edx, %edi
shrl $0x2, %edi
leal (,%rdx,4), %esi
cmpq $0x2, %rcx
cmovael %edi, %esi
testl %edx, %edx
je 0x26fc5
movzwl (%r12,%rcx,2), %edi
movq (%rbx), %r8
addq $0xc, %r8
movl %r15d, %r9d
movzwl %r9w, %r10d
movzwl (%rax,%r10,2), %r11d
xorw %dx, %r11w
movw %r11w, (%rax,%r10,2)
movzwl %r11w, %r10d
testl %r10d, %edx
jne 0x270ad
addl %edi, %r9d
movzwl %r9w, %r10d
movzwl (%rax,%r10,2), %r11d
xorw %si, %r11w
movw %r11w, (%rax,%r10,2)
movzwl %r11w, %r11d
testl %r11d, %esi
jne 0x270ad
imulq $0x28f5c29, %r10, %r11  # imm = 0x28F5C29
shrq $0x20, %r11
imull $0x64, %r11d, %r14d
subl %r14d, %r10d
imulq $0x4b0, %r11, %r11      # imm = 0x4B0
addq %r8, %r11
leaq (%r10,%r10,2), %r10
cmpb $0x0, (%r11,%r10,4)
js 0x26f5d
incq %rcx
cmpq $0x4, %rcx
jne 0x26f2e
xorl %r15d, %r15d
movl %ebp, %eax
movl %r15d, %ecx
shrl %cl, %eax
testl $0x111, %eax            # imm = 0x111
je 0x27078
leaq 0xbde2(%rip), %rax      # 0x32dd0
movzwl (%rax,%r15,2), %r12d
movq (%rsp), %rsi
leal (%r12,%rsi), %r13d
movzwl %r13w, %eax
imulq $0x28f5c29, %rax, %rcx  # imm = 0x28F5C29
shrq $0x20, %rcx
imulq $0x4b0, %rcx, %rdx      # imm = 0x4B0
addq (%rbx), %rdx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
leaq (%rax,%rax,2), %rax
cmpb $0x0, 0xc(%rdx,%rax,4)
jns 0x27068
leal (%rsi,%r12,2), %r14d
movzwl %r13w, %esi
movq %rbx, %rdi
callq 0x270b2
testb %al, %al
je 0x2709c
movzwl %r14w, %eax
imulq $0x28f5c29, %rax, %rcx  # imm = 0x28F5C29
shrq $0x20, %rcx
imulq $0x4b0, %rcx, %rdx      # imm = 0x4B0
addq (%rbx), %rdx
addl %r12d, %r13d
imull $0x64, %ecx, %ecx
leal (%rax,%r12), %r14d
subl %ecx, %eax
leaq (%rax,%rax,2), %rax
cmpb $0x0, 0xc(%rdx,%rax,4)
js 0x27028
movzwl %r13w, %esi
movq %rbx, %rdi
callq 0x270b2
testb %al, %al
je 0x2709c
incq %r15
cmpq $0x4, %r15
jne 0x26fd5
movzwl (%rsp), %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x270b2
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3180