// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movl %esi, %r14d
movq %rdi, %r15
callq 0x7834
testb %al, %al
je 0x76e5
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r15), %rbx
movq %r15, 0x28(%rsp)
movq 0x8(%r15), %rax
xorl %r13d, %r13d
movq %rax, 0x30(%rsp)
cmpq %rax, %rbx
je 0x76ec
movl %r14d, 0x4(%rsp)
movl %ebp, 0x8(%rsp)
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
movq (%rbx), %rbp
movq 0x8(%rbx), %r14
cmpq %r14, %rbp
je 0x76c5
movl (%rbp), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x76b4
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x76bf
movq %r15, %rdi
movq %r12, %rdx
callq 0x60a4
addq $0x4, %rbp
jmp 0x768f
addq $0x18, %rbx
cmpq 0x30(%rsp), %rbx
jne 0x7688
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
movl 0x8(%rsp), %ebp
movl 0x4(%rsp), %r14d
jmp 0x76f0
xorl %ebx, %ebx
jmp 0x77c0
xorl %edi, %edi
xorl %eax, %eax
subq %rdi, %rax
shrq $0x2, %rax
cmpl $0x2, %eax
jl 0x774e
leal -0x1(%rax), %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %edx, %edx
movq %rdi, %rsi
xorl %r13d, %r13d
movl (%rdi,%rdx,4), %r8d
testl %r8d, %r8d
je 0x773f
movl $0x1, %r9d
movl (%rsi,%r9,4), %r10d
testl %r10d, %r10d
setne %r11b
cmpl %r10d, %r8d
setg %r10b
andb %r11b, %r10b
movzbl %r10b, %r10d
xorl %r10d, %r13d
incq %r9
cmpq %r9, %rax
jne 0x771b
incq %rdx
addq $0x4, %rsi
decq %rax
cmpq %rcx, %rdx
jne 0x770c
testb $0x1, %r14b
jne 0x77a8
testl %ebp, %ebp
jle 0x77d1
movq 0x28(%rsp), %rax
movq (%rax), %rcx
movl %ebp, %edx
movl %r14d, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
testl %r14d, %r14d
jle 0x778e
leaq (%r8,%r8,2), %r9
movq (%rcx,%r9,8), %r9
xorl %r10d, %r10d
cmpl $0x0, (%r9,%r10,4)
cmovel %r8d, %eax
incq %r10
cmpq %r10, %rsi
jne 0x777d
incq %r8
cmpq %rdx, %r8
jne 0x776d
cmpl $-0x1, %eax
je 0x77d1
notl %eax
addl %ebp, %eax
andl $0x1, %eax
xorl %r13d, %eax
movl %eax, %r13d
testl %r13d, %r13d
sete %bl
testq %rdi, %rdi
je 0x77c0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x30f0
movq %rax, %r14
leaq 0x2f01(%rip), %rsi      # 0xa6e6
movq %rax, %rdi
callq 0x30b0
movq 0x77fc(%rip), %rsi      # 0xeff0
movq 0x779d(%rip), %rdx      # 0xef98
movq %r14, %rdi
callq 0x33b0
jmp 0x7812
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0x7815
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x782c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x33d0