// File: /workspace/github_cpp_makefile_star2_O2/iTruth[P]klotski/klotski_board.cpp
// Function: klotski_board::is_valid(std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&, int, int)
bool klotski_board::is_valid(const klotski_board::situation_type& situation, int dx, int dy){
	if(!is_nums_linear(situation)){
		return false;
	}
	std::vector<int> linear_situation;
	for(const auto& i: situation){
		for(int j: i){
			linear_situation.push_back(j);
		}
	}

	int rn = 0;
	int situation_size = linear_situation.size();
	for (int i = 0; i < situation_size - 1; ++i) {
		if(linear_situation[i] == 0){
			continue;
		}
		for (int j = i + 1; j < situation_size; ++j) {
			if(linear_situation[j] != 0
					&&linear_situation[i] > linear_situation[j]){
				rn ^= 1;
			}
		}
	}

	if((dx & 1) == 0){
		int zero_y = -1;
		for (int i = 0; i < dy; ++i) {
			for (int j = 0; j < dx; ++j) {
				if(situation[i][j] == 0){
					zero_y = i;
				}
			}
		}
		if(zero_y == -1){
			throw std::runtime_error("Can not find zero on klotski board");
		}
		rn ^= (dy - 1 - zero_y) & 1;
	}
	return rn == 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
callq 0x6cde
testb %al, %al
je 0x6b9c
movl %ebx, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r12
andq $0x0, 0x10(%r12)
movaps %xmm0, (%r12)
movq (%r15), %rbp
movq %r15, 0x10(%rsp)
movq 0x8(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0xc(%rsp), %r13
cmpq 0x18(%rsp), %rbp
je 0x6ba3
movq (%rbp), %r15
movq 0x8(%rbp), %rbx
cmpq %rbx, %r15
je 0x6b96
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x49ae
addq $0x4, %r15
jmp 0x6b79
addq $0x18, %rbp
jmp 0x6b6a
xorl %ebx, %ebx
jmp 0x6c78
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
decl %edx
xorl %esi, %esi
testl %edx, %edx
movl $0x0, %edi
cmovgl %edx, %edi
leaq 0x4(%rcx), %r8
xorl %eax, %eax
movl 0x8(%rsp), %ebp
movq 0x10(%rsp), %r15
cmpq %rdi, %rsi
je 0x6c13
movl (%rcx,%rsi,4), %r9d
testl %r9d, %r9d
je 0x6c07
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0x6c07
movl (%r8,%r10,4), %r11d
testl %r11d, %r11d
setne %bl
cmpl %r11d, %r9d
setg %r11b
andb %bl, %r11b
movzbl %r11b, %r11d
xorl %r11d, %eax
incq %r10
jmp 0x6be2
incq %rsi
decq %rdx
addq $0x4, %r8
jmp 0x6bd1
testb $0x1, %r14b
jne 0x6c69
movq (%r15), %rdx
xorl %esi, %esi
testl %r14d, %r14d
cmovlel %esi, %r14d
testl %ebp, %ebp
movl $0x0, %edi
cmovgl %ebp, %edi
pushq $-0x1
popq %rcx
cmpq %rdi, %rsi
je 0x6c5b
imulq $0x18, %rsi, %r8
addq %rdx, %r8
xorl %r9d, %r9d
cmpq %r9, %r14
je 0x6c56
movq (%r8), %r10
cmpl $0x0, (%r10,%r9,4)
cmovel %esi, %ecx
incq %r9
jmp 0x6c41
incq %rsi
jmp 0x6c32
cmpl $-0x1, %ecx
je 0x6c89
notl %ecx
addl %ebp, %ecx
andl $0x1, %ecx
xorl %ecx, %eax
testl %eax, %eax
sete %bl
leaq 0x20(%rsp), %rdi
callq 0x509c
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x3100
movq %rax, %r14
leaq 0x3a1b(%rip), %rsi      # 0xa6b6
movq %rax, %rdi
callq 0x30a0
movq 0x9346(%rip), %rsi      # 0xfff0
movq 0x92df(%rip), %rdx      # 0xff90
movq %r14, %rdi
callq 0x33a0
jmp 0x6cc8
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0x6ccb
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x509c
movq %rbx, %rdi
callq 0x33c0
nop