// File: iTruth[P]klotski/klotski_board.cpp
// Function: klotski_board::is_valid() const
bool klotski_board::is_valid() const{
	if(!is_nums_linear()){
		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){
		update_zero_pos();
		rn ^= (dy - 1 - zero_y) & 1;
	}
	return rn == 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0xdcbd
movb $0x0, -0x1(%rbp)
jmp 0xdeb2
leaq -0x28(%rbp), %rdi
callq 0x5cf0
movq -0x90(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7640
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7670
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7a30
testb $0x1, %al
jne 0xdd05
jmp 0xdd9b
leaq -0x38(%rbp), %rdi
callq 0x7aa0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x7d30
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0x7d60
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xb920
testb $0x1, %al
jne 0xdd47
jmp 0xdd8b
leaq -0x58(%rbp), %rdi
callq 0xb9d0
movl (%rax), %eax
movl %eax, -0x64(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x5d10
jmp 0xdd64
jmp 0xdd66
leaq -0x58(%rbp), %rdi
callq 0xe690
jmp 0xdd34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5e00
jmp 0xdec0
jmp 0xdd8d
leaq -0x38(%rbp), %rdi
callq 0x7ac0
jmp 0xdcef
movl $0x0, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x7c10
movl %eax, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xde64
movslq -0x80(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xe740
cmpl $0x0, (%rax)
jne 0xddda
jmp 0xde56
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0xde54
movslq -0x84(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xe740
cmpl $0x0, (%rax)
je 0xde41
movslq -0x80(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xe740
movl (%rax), %eax
movl %eax, -0x94(%rbp)
movslq -0x84(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xe740
movq %rax, %rcx
movl -0x94(%rbp), %eax
cmpl (%rcx), %eax
jle 0xde41
movl -0x78(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xde43
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xdde6
jmp 0xde56
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0xddb5
movq -0x90(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xde9d
movq -0x90(%rbp), %rdi
callq 0xded0
jmp 0xde84
movq -0x90(%rbp), %rcx
movl 0xc(%rcx), %eax
subl $0x1, %eax
subl 0x14(%rcx), %eax
andl $0x1, %eax
xorl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x1(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5e00
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x34e0
nopl (%rax)