// File: /workspace/github_cpp_makefile_star2_O1/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 0x41b6
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 0x1b3c(%rip), %rsi      # 0x5c88
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x33fa
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x22c0
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x417b
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4192
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movq 0x4e2f(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x41a1
jmp 0x42e3
movq 0x50(%rbx), %rdi
cmpl $0xe1, 0x24(%rdi)
jl 0x422c
movq 0x40(%rbx,%rax,8), %rdi
movb $0x1, 0xa(%rdi)
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x50(%rbx), %rdi
leaq 0x1ac7(%rip), %rsi      # 0x5ca4
callq 0x33fa
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x41f1
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4208
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movq 0x4db9(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x4217
jmp 0x42e3
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 0x42e9
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 0x1a2e(%rip), %rsi      # 0x5cb6
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x50(%rbx), %rdi
movq %r14, %rsi
callq 0x33fa
movq 0x4d2b(%rip), %r14      # 0x8fd0
movq (%r14), %rdi
callq 0x20e0
orl $0x20, %eax
cmpl $0x71, %eax
jne 0x42a5
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x42c4
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x40(%rbx)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x42db
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x48(%rbx)
movl $0x1, (%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop