// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, %rbx
movq 0x4e28(%rdi), %rax
movl %esi, %ecx
movq %rcx, 0x10(%rsp)
movzwl (%rax,%rcx,2), %edi
movl %edi, %ecx
notl %ecx
testl %edx, %ecx
jne 0x27828
movq %rsi, 0x8(%rsp)
cmpw %dx, %di
je 0x27828
movl %edi, %r8d
movzwl %dx, %ecx
shrl $0x4, %ecx
orl %edx, %ecx
movzbl %ch, %edi
orl %ecx, %edi
notl %edi
testb $0xf, %dil
jne 0x27817
movl %r8d, %edi
xorl %edx, %edi
xorl %ecx, %ecx
movl $0x111, %edx            # imm = 0x111
shll %cl, %edx
movl %edi, %r14d
andl %edi, %edx
movl %edx, %r8d
shrl $0x2, %r8d
leal (,%rdx,4), %edi
cmpq $0x2, %rcx
cmovael %r8d, %edi
testl %edx, %edx
je 0x27728
leaq 0xb82f(%rip), %rsi      # 0x32eb0
movzwl (%rsi,%rcx,2), %r8d
movq (%rbx), %r9
addq $0xc, %r9
movq 0x10(%rsp), %rsi
movzwl (%rax,%rsi,2), %r10d
movq 0x8(%rsp), %rsi
leal (%rsi,%r8), %r15d
movl %esi, %r11d
movzwl %r11w, %r12d
xorl %edx, %r10d
movw %r10w, (%rax,%r12,2)
testl %edx, %r10d
jne 0x27828
addl %r8d, %r11d
movzwl %r11w, %r12d
movzwl (%rax,%r12,2), %r10d
xorw %di, %r10w
movw %r10w, (%rax,%r12,2)
movzwl %r10w, %ebp
testl %ebp, %edi
jne 0x27828
movzwl %r15w, %ebp
movl %ebp, %r13d
shrl $0x2, %r13d
imull $0x147b, %r13d, %r13d   # imm = 0x147B
shrl $0x11, %r13d
imull $0x64, %r13d, %r13d
subl %r13d, %r15d
shrl $0x2, %r12d
imull $0x147b, %r12d, %r12d   # imm = 0x147B
shrl $0x11, %r12d
movzwl %r15w, %r15d
imulq $0x4b0, %r12, %r12      # imm = 0x4B0
addq %r9, %r12
leaq (%r15,%r15,2), %r15
addl %r8d, %ebp
cmpb $0x0, (%r12,%r15,4)
movl %ebp, %r15d
js 0x276a3
incq %rcx
cmpq $0x4, %rcx
movl %r14d, %edi
jne 0x27650
xorl %r15d, %r15d
movl %edi, %eax
movl %r15d, %ecx
shrl %cl, %eax
testl $0x111, %eax            # imm = 0x111
je 0x277ef
leaq 0xb75c(%rip), %rax      # 0x32eb0
movzwl (%rax,%r15,2), %r12d
movq 0x8(%rsp), %rsi
leal (%r12,%rsi), %r13d
movl %r13d, %eax
movl $0xffff, %edi           # imm = 0xFFFF
andl %edi, %eax
shrl $0x2, %eax
imull $0x147b, %eax, %eax     # imm = 0x147B
shrl $0x11, %eax
imulq $0x4b0, %rax, %rcx      # imm = 0x4B0
addq (%rbx), %rcx
imull $0x64, %eax, %eax
movl %r13d, %edx
subl %eax, %edx
andl %edi, %edx
leaq (%rdx,%rdx,2), %rax
cmpb $0x0, 0xc(%rcx,%rax,4)
jns 0x277df
leal (%rsi,%r12,2), %ebp
movzwl %r13w, %esi
movq %rbx, %rdi
callq 0x2782e
testb %al, %al
je 0x27817
movzwl %bp, %ebp
movl %ebp, %eax
shrl $0x2, %eax
imull $0x147b, %eax, %eax     # imm = 0x147B
shrl $0x11, %eax
imull $-0x64, %eax, %ecx
addl %r12d, %r13d
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
addq (%rbx), %rax
addl %ebp, %ecx
movzwl %cx, %ecx
leaq (%rcx,%rcx,2), %rcx
addl %r12d, %ebp
cmpb $0x0, 0xc(%rax,%rcx,4)
js 0x2779b
movzwl %r13w, %esi
movq %rbx, %rdi
callq 0x2782e
testb %al, %al
je 0x27817
incq %r15
cmpq $0x4, %r15
movl %r14d, %edi
jne 0x2773b
movzwl 0x8(%rsp), %esi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2782e
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3180
nop