// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rdi, %r14
callq 0x79b6
testb %al, %al
je 0x7913
movl %ebp, 0x8(%rsp)
movl %ebx, 0x4(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r14), %r13
movq %r14, 0x30(%rsp)
movq 0x8(%r14), %rbx
cmpq %rbx, %r13
je 0x7859
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
movq (%r13), %r14
movq 0x8(%r13), %rbp
cmpq %rbp, %r14
je 0x7850
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x783f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x784a
movq %r15, %rdi
movq %r12, %rdx
callq 0x60e0
addq $0x4, %r14
jmp 0x781a
addq $0x18, %r13
cmpq %rbx, %r13
jne 0x7812
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
subq %rdi, %rcx
shrq $0x2, %rcx
xorl %eax, %eax
cmpl $0x2, %ecx
movl 0x8(%rsp), %ebp
jl 0x78c6
leal -0x1(%rcx), %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movq %rdi, %r8
xorl %eax, %eax
movl (%rdi,%rsi,4), %r9d
testl %r9d, %r9d
je 0x78b7
movl $0x1, %r10d
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
cmpq %r10, %rcx
jne 0x7894
incq %rsi
addq $0x4, %r8
decq %rcx
cmpq %rdx, %rsi
jne 0x7885
testb $0x1, %bpl
jne 0x792a
movl 0x4(%rsp), %ebx
testl %ebx, %ebx
jle 0x7917
movq 0x30(%rsp), %rcx
movq (%rcx), %rdx
movl %ebx, %esi
movl %ebp, %r8d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
testl %ebp, %ebp
jle 0x7909
leaq (%r9,%r9,2), %r10
movq (%rdx,%r10,8), %r10
xorl %r11d, %r11d
cmpl $0x0, (%r10,%r11,4)
cmovel %r9d, %ecx
incq %r11
cmpq %r11, %r8
jne 0x78f8
incq %r9
cmpq %rsi, %r9
jne 0x78e9
jmp 0x791c
xorl %ebx, %ebx
jmp 0x7941
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0x7952
notl %ecx
addl %ebx, %ecx
andl $0x1, %ecx
xorl %ecx, %eax
testl %eax, %eax
sete %bl
testq %rdi, %rdi
je 0x7941
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 0x2d50(%rip), %rsi      # 0xa6b6
movq %rax, %rdi
callq 0x30b0
movq 0x767b(%rip), %rsi      # 0xeff0
movq 0x761c(%rip), %rdx      # 0xef98
movq %r14, %rdi
callq 0x33b0
jmp 0x7993
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0x7996
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x79ad
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x33d0
nop