// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movw %si, %cx
movq %rdi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movw %ax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x4e28(%rax), %rax
movzwl -0x12(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x16(%rbp)
movzwl -0x14(%rbp), %eax
movzwl -0x16(%rbp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x552fc
callq 0x4180
movzwl -0x14(%rbp), %eax
movzwl -0x16(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5530d
callq 0x4180
movw -0x14(%rbp), %ax
movw %ax, -0x18(%rbp)
movzwl -0x18(%rbp), %ecx
sarl $0x4, %ecx
movzwl -0x18(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x18(%rbp)
movzwl -0x18(%rbp), %ecx
sarl $0x8, %ecx
movzwl -0x18(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x18(%rbp)
movzwl -0x18(%rbp), %eax
andl $0xf, %eax
cmpl $0xf, %eax
je 0x5534c
movb $0x0, -0x1(%rbp)
jmp 0x55565
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x55493
movslq -0x1c(%rbp), %rcx
leaq 0x11af0(%rip), %rax     # 0x66e58
movw (%rax,%rcx,2), %ax
movw %ax, -0x1e(%rbp)
movzwl -0x16(%rbp), %eax
movzwl -0x14(%rbp), %ecx
xorl %ecx, %eax
movl -0x1c(%rbp), %ecx
movl $0x111, %edx            # imm = 0x111
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movw %ax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x553a3
movzwl -0x20(%rbp), %eax
sarl $0x2, %eax
movl %eax, -0x3c(%rbp)
jmp 0x553ad
movzwl -0x20(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movw %ax, -0x22(%rbp)
movzwl -0x16(%rbp), %eax
movzwl -0x14(%rbp), %ecx
xorl %ecx, %eax
movl -0x1c(%rbp), %ecx
movl $0x111, %edx            # imm = 0x111
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x55483
movw -0x12(%rbp), %ax
movw %ax, -0x24(%rbp)
movq -0x38(%rbp), %rax
movzwl -0x20(%rbp), %edi
movq 0x4e28(%rax), %rcx
movzwl -0x24(%rbp), %edx
movzwl (%rcx,%rdx,2), %esi
xorl %edi, %esi
movw %si, (%rcx,%rdx,2)
movq 0x4e28(%rax), %rax
movzwl -0x24(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
movzwl -0x20(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x55419
callq 0x4180
movq -0x38(%rbp), %rax
movswl -0x1e(%rbp), %edx
movzwl -0x24(%rbp), %ecx
addl %edx, %ecx
movw %cx, -0x24(%rbp)
movzwl -0x22(%rbp), %edi
movq 0x4e28(%rax), %rcx
movzwl -0x24(%rbp), %edx
movzwl (%rcx,%rdx,2), %esi
xorl %edi, %esi
movw %si, (%rcx,%rdx,2)
movq 0x4e28(%rax), %rax
movzwl -0x24(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
movzwl -0x22(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x55463
callq 0x4180
jmp 0x55465
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movzwl -0x24(%rbp), %esi
callq 0x4e8e0
movsbl (%rax), %eax
cmpl $0x0, %eax
jl 0x553dd
jmp 0x55483
jmp 0x55485
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x55353
movl $0x0, -0x28(%rbp)
cmpl $0x4, -0x28(%rbp)
jge 0x5554a
movslq -0x28(%rbp), %rcx
leaq 0x119a9(%rip), %rax     # 0x66e58
movw (%rax,%rcx,2), %ax
movw %ax, -0x2a(%rbp)
movzwl -0x16(%rbp), %eax
movzwl -0x14(%rbp), %ecx
xorl %ecx, %eax
movl -0x28(%rbp), %ecx
movl $0x111, %edx            # imm = 0x111
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x5553a
movzwl -0x12(%rbp), %eax
movswl -0x2a(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movzwl -0x2c(%rbp), %esi
callq 0x4e8e0
movsbl (%rax), %eax
cmpl $0x0, %eax
jge 0x55521
movq -0x38(%rbp), %rdi
movzwl -0x2c(%rbp), %esi
callq 0x55570
testb $0x1, %al
jne 0x55511
movb $0x0, -0x1(%rbp)
jmp 0x55565
movswl -0x2a(%rbp), %ecx
movzwl -0x2c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x2c(%rbp)
jmp 0x554e2
movq -0x38(%rbp), %rdi
movzwl -0x2c(%rbp), %esi
callq 0x55570
testb $0x1, %al
jne 0x55538
movb $0x0, -0x1(%rbp)
jmp 0x55565
jmp 0x5553a
jmp 0x5553c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x5549a
movq -0x38(%rbp), %rdi
movzwl -0x12(%rbp), %esi
callq 0x55570
testb $0x1, %al
jne 0x55561
movb $0x0, -0x1(%rbp)
jmp 0x55565
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq