// File: tyhsu[P]Ewn/game.cpp
// Function: Game::count_movable_chs(int const&)
int Game::count_movable_chs(const int& dice)
{
	for(int i = 0; i < 2; i++)
		this->movable_chs_list[i].assign(0, false, 0, 0);

	if (this->cur_chs_list_ptr[dice].exist == true) {
		// this piece is alive!
		for(int i = 0; i < 2; i++)
			this->movable_chs_list[i] = this->cur_chs_list_ptr[dice];
		return 1;
	}
	else {
		int movable_chs_cnt = 2;

		// search for maybe other two.
		for (int i = dice-1; i >= 0; i--) {
			if (this->cur_chs_list_ptr[i].exist){
				this->movable_chs_list[0] = this->cur_chs_list_ptr[i];
				break;
			}
		}
		for (int i = dice+1; i < 6; i++) {
			if (this->cur_chs_list_ptr[i].exist){
				this->movable_chs_list[1] = this->cur_chs_list_ptr[i];
				break;
			}
		}

		// if one of movable_chs_list doesn't value, let this Chs = the other one (with value).
		for (int i = 0; i < 2; i++) {
			if (this->movable_chs_list[i].symbol == 0) {
				this->movable_chs_list[i] = this->movable_chs_list[1-i];
				movable_chs_cnt--;
			}
		}
		return movable_chs_cnt;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0xae0e
movq -0x48(%rbp), %rdi
addq $0x1c, %rdi
movslq -0x1c(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x1e(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x1d(%rbp), %rsi
leaq -0x1e(%rbp), %rdx
leaq -0x24(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0xa110
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xadbf
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb 0x1(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xae8c
movl $0x0, -0x2c(%rbp)
cmpl $0x2, -0x2c(%rbp)
jge 0xae80
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rcx
movq -0x18(%rbp), %rdx
movslq (%rdx), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
addq $0x1c, %rax
movslq -0x2c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xae3b
movl $0x1, -0x4(%rbp)
jmp 0xafcf
movl $0x2, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jl 0xaef3
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
testb $0x1, 0x1(%rax)
je 0xaee6
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rcx
movslq -0x34(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, 0x1c(%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x24(%rax)
jmp 0xaef3
jmp 0xaee8
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xae9f
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x6, -0x38(%rbp)
jge 0xaf53
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
testb $0x1, 0x1(%rax)
je 0xaf46
movq -0x48(%rbp), %rax
movq 0xd0(%rax), %rcx
movslq -0x38(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, 0x28(%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x30(%rax)
jmp 0xaf53
jmp 0xaf48
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xaeff
movl $0x0, -0x3c(%rbp)
cmpl $0x2, -0x3c(%rbp)
jge 0xafc9
movq -0x48(%rbp), %rax
addq $0x1c, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xafbc
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1c, %rcx
movl $0x1, %edx
subl -0x3c(%rbp), %edx
movslq %edx, %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
addq $0x1c, %rax
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xafbe
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xaf5a
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)