// File: /workspace/github_cpp_makefile_star2_O2/nesro[P]NCursesGomoku/src/game.cpp
// Function: CGame::checkForWin()
void CGame::checkForWin(void) {
	int x;
	int y;
	int direction;
	char message[CBoard::MESSAGE_LENGTH];

	int playerToCheck = (m_PlayerOnTurn + 1) % 2;

	/* sequences of "xxxxx" and "ooooo" */
	char playerWinningSequence[2][6] = { { PLAYER_0_CHAR, PLAYER_0_CHAR,
			PLAYER_0_CHAR, PLAYER_0_CHAR, PLAYER_0_CHAR, '\0' }, {
			PLAYER_1_CHAR, PLAYER_1_CHAR, PLAYER_1_CHAR, PLAYER_1_CHAR,
			PLAYER_1_CHAR, '\0' } };

	if (m_Players[playerToCheck]->m_Surrender) {

		lastMove();

		memset(message, '\0', CBoard::MESSAGE_LENGTH);
		sprintf(message, " (%c) surrender! Press \"q\".",
				m_Players[playerToCheck]->m_Mark);

		m_Board->printMessage(message);
		usleep(1000000);

		playerCleanup();

		waitForChar('q', 'Q');

		m_Status = STATUS_MENU;
		return;
	}

	if (m_Board->m_StonesOnBoard
			>= m_Board->BOARD_HEIGHT * m_Board->BOARD_HEIGHT) {

		lastMove();

		m_Board->printMessage(" Draw! Press \"q\".");

		playerCleanup();

		waitForChar('q', 'Q');

		m_Status = STATUS_MENU;
		return;
	}

	/* find for winning sequence */
	if (m_Board->searchFor(x, y, direction,
			playerWinningSequence[playerToCheck])) {

		lastMove();

		memset(message, '\0', CBoard::MESSAGE_LENGTH);
		sprintf(message, " Player \"%c\" WINS! Press \"q\".",
				m_Players[playerToCheck]->m_Mark);

		m_Board->printMessage(message);

		waitForChar('q', 'Q');

		playerCleanup();

		m_Status = STATUS_MENU;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movslq 0x58(%rdi), %rcx
leal 0x1(%rcx), %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
movabsq $0x6f6f007878787878, %rax # imm = 0x6F6F007878787878
movq %rax, 0x8(%rsp)
movl $0x6f6f6f, 0x10(%rsp)   # imm = 0x6F6F6F
movslq %edx, %r15
movq 0x40(%rdi,%r15,8), %rax
cmpb $0x1, 0x8(%rax)
jne 0x3c82
movq 0x40(%rbx,%rcx,8), %rdi
movb $0x1, 0xa(%rdi)
movq (%rdi), %rax
callq *0x10(%rax)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq 0x40(%rbx,%r15,8), %rax
movsbl 0x9(%rax), %edx
leaq 0x2038(%rip), %rsi      # 0x5c98
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x30f4
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x22b0
jmp 0x3cae
movq 0x50(%rbx), %rdi
cmpl $0xe1, 0x24(%rdi)
jl 0x3cd1
movq 0x40(%rbx,%rcx,8), %rdi
movb $0x1, 0xa(%rdi)
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x50(%rbx), %rdi
leaq 0x200b(%rip), %rsi      # 0x5cb4
callq 0x30f4
movq %rbx, %rdi
callq 0x367a
pushq $0x71
popq %rsi
pushq $0x51
popq %rdx
callq 0x3d6c
movl $0x1, (%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
imulq $0x6, %r15, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x1c(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x2eae
testb %al, %al
je 0x3cc7
movslq 0x58(%rbx), %rax
movq 0x40(%rbx,%rax,8), %rdi
movb $0x1, 0xa(%rdi)
movq (%rdi), %rax
callq *0x10(%rax)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq 0x40(%rbx,%r15,8), %rax
movsbl 0x9(%rax), %edx
leaq 0x1f9d(%rip), %rsi      # 0x5cc6
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x30f4
pushq $0x71
popq %rsi
pushq $0x51
popq %rdx
callq 0x3d6c
movq %rbx, %rdi
callq 0x367a
jmp 0x3cc1
nop