// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq 0x4e28(%rdi), %r9
movl %esi, %eax
movq %rax, 0x10(%rsp)
movzwl (%r9,%rax,2), %ecx
movl %ecx, %eax
notl %eax
testl %edx, %eax
jne 0x20dc9
cmpw %dx, %cx
je 0x20dc9
movl %esi, %r14d
movl %ecx, %esi
movzwl %dx, %eax
shrl $0x4, %eax
orl %edx, %eax
movzbl %ah, %ecx
orl %eax, %ecx
notl %ecx
testb $0xf, %cl
jne 0x20da1
movq %rdi, %rbx
movl %esi, %eax
xorl %edx, %eax
movw $0x64, %r11w
xorl %ecx, %ecx
movl %eax, 0xc(%rsp)
cmpq $0x4, %rcx
je 0x20d20
movl $0x111, %r15d           # imm = 0x111
shll %cl, %r15d
andl %eax, %r15d
movl %r15d, %eax
shrl $0x2, %eax
leal (,%r15,4), %ebp
cmpq $0x2, %rcx
cmovael %eax, %ebp
testl %r15d, %r15d
je 0x20d14
leaq 0xb16e(%rip), %rax      # 0x2be00
movzwl (%rax,%rcx,2), %r13d
movq (%rbx), %r10
addq $0xc, %r10
movq 0x10(%rsp), %rax
movzwl (%r9,%rax,2), %r12d
leal (%r14,%r13), %esi
movl %r14d, %edi
movl %esi, %eax
xorl %edx, %edx
divw %r11w
movzwl %di, %eax
xorl %r15d, %r12d
movw %r12w, (%r9,%rax,2)
testl %r15d, %r12d
jne 0x20dc9
addl %r13d, %edi
movzwl %di, %eax
movzwl (%r9,%rax,2), %r12d
xorw %bp, %r12w
movw %r12w, (%r9,%rax,2)
movzwl %r12w, %eax
testl %eax, %ebp
jne 0x20dc9
movl %edx, %r8d
movl %edi, %eax
xorl %edx, %edx
divw %r11w
movzwl %ax, %eax
movzwl %r8w, %edx
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
addq %r10, %rax
imulq $0xc, %rdx, %rdx
addl %r13d, %esi
cmpb $0x0, (%rdx,%rax)
js 0x20caf
incq %rcx
movl 0xc(%rsp), %eax
jmp 0x20c57
movw $0x64, %r13w
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x20db2
movq %rcx, 0x10(%rsp)
shrl %cl, %eax
testw $0x111, %ax             # imm = 0x111
je 0x20d93
leaq 0xb0bb(%rip), %rax      # 0x2be00
movq 0x10(%rsp), %rcx
movzwl (%rax,%rcx,2), %r12d
movl %r12d, %ebp
addl %r14d, %ebp
movl %ebp, %eax
xorl %edx, %edx
divw %r13w
movzwl %ax, %eax
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
addq (%rbx), %rax
movzwl %dx, %ecx
imulq $0xc, %rcx, %rcx
movb 0xc(%rcx,%rax), %r15b
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x20dce
testb %r15b, %r15b
jns 0x20d8f
testb %al, %al
je 0x20da1
addl %r12d, %ebp
jmp 0x20d55
testb %al, %al
je 0x20da1
movq 0x10(%rsp), %rcx
incq %rcx
movl 0xc(%rsp), %eax
jmp 0x20d27
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl %r14w, %esi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20dce
callq 0x3180