// File: /workspace/github_cpp_makefile_star2_O3/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), %rax
leal 0x1(%rax), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %eax, %edx
incl %edx
andl $-0x2, %edx
subl %edx, %ecx
movabsq $0x6f6f007878787878, %rdx # imm = 0x6F6F007878787878
movq %rdx, 0x8(%rsp)
movl $0x6f6f6f, 0x10(%rsp)   # imm = 0x6F6F6F
movslq %ecx, %r15
movq 0x40(%rdi,%r15,8), %rcx
cmpb $0x1, 0x8(%rcx)
jne 0x3fb0
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 0x1d52(%rip), %rsi      # 0x5c98
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x31f6
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x22c0
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x3f75
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x3f8c
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movq 0x5035(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x3f9b
jmp 0x40dd
movq 0x50(%rbx), %rdi
cmpl $0xe1, 0x24(%rdi)
jl 0x4026
movq 0x40(%rbx,%rax,8), %rdi
movb $0x1, 0xa(%rdi)
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x50(%rbx), %rdi
leaq 0x1cdd(%rip), %rsi      # 0x5cb4
callq 0x31f6
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x3feb
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4002
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movq 0x4fbf(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x4011
jmp 0x40dd
leaq (%r15,%r15,2), %rax
leaq (%rsp,%rax,2), %r8
addq $0x8, %r8
leaq 0x1c(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x2f52
testb %al, %al
je 0x40e3
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 0x1c44(%rip), %rsi      # 0x5cc6
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x31f6
movq 0x4f31(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x409f
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x40be
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x40d5
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movl $0x1, (%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop