// File: /workspace/github_cpp_makefile_star2_O1/nesro[P]NCursesGomoku/src/board.cpp
// Function: CBoard::searchFor(int&, int&, int&, char const*) const
bool CBoard::searchFor(int & x, int & y, int & direction,
		const char * pattern) const {

	int randomSearch = rand() % 4;

	/* choose one from four directions of searching */
	switch (randomSearch) {
	case 0:
		for (int i = 0; i < BOARD_WIDTH; i++) {
			for (int j = 0; j < BOARD_HEIGHT; j++) {
				for (int searchDirection = 0; searchDirection < 8;
						searchDirection++) {
					for (int l = 0, tmpX = i, tmpY = j;; l++) {
						if (pattern[l] == '\0') {
							x = i;
							y = j;
							direction = searchDirection;

							return true;
						} else if (!outOfBoard(tmpX, tmpY)
								&& m_Stones[tmpY][tmpX] == pattern[l]) {
							tmpX += DIRECTIONS[searchDirection][0];
							tmpY += DIRECTIONS[searchDirection][1];

							continue;
						} else {
							break;
						}
					}
				}
			}
		}
		break;
	case 1:
		for (int i = BOARD_WIDTH - 1; i >= 0; i--) {
			for (int j = 0; j < BOARD_HEIGHT; j++) {
				for (int searchDirection = 0; searchDirection < 8;
						searchDirection++) {
					for (int l = 0, tmpX = i, tmpY = j;; l++) {
						if (pattern[l] == '\0') {
							x = i;
							y = j;
							direction = searchDirection;

							return true;
						} else if (!outOfBoard(tmpX, tmpY)
								&& m_Stones[tmpY][tmpX] == pattern[l]) {
							tmpX += DIRECTIONS[searchDirection][0];
							tmpY += DIRECTIONS[searchDirection][1];

							continue;
						} else {
							break;
						}
					}
				}
			}
		}
		break;
	case 2:
		for (int i = 0; i < BOARD_WIDTH; i++) {
			for (int j = BOARD_HEIGHT - 1; j >= 0; j--) {
				for (int searchDirection = 0; searchDirection < 8;
						searchDirection++) {
					for (int l = 0, tmpX = i, tmpY = j;; l++) {
						if (pattern[l] == '\0') {
							x = i;
							y = j;
							direction = searchDirection;

							return true;
						} else if (!outOfBoard(tmpX, tmpY)
								&& m_Stones[tmpY][tmpX] == pattern[l]) {
							tmpX += DIRECTIONS[searchDirection][0];
							tmpY += DIRECTIONS[searchDirection][1];

							continue;
						} else {
							break;
						}
					}
				}
			}
		}
		break;
	case 3:
		for (int i = BOARD_WIDTH - 1; i >= 0; i--) {
			for (int j = BOARD_HEIGHT - 1; j >= 0; j--) {
				for (int searchDirection = 0; searchDirection < 8;
						searchDirection++) {
					for (int l = 0, tmpX = i, tmpY = j;; l++) {
						if (pattern[l] == '\0') {
							x = i;
							y = j;
							direction = searchDirection;

							return true;
						} else if (!outOfBoard(tmpX, tmpY)
								&& m_Stones[tmpY][tmpX] == pattern[l]) {
							tmpX += DIRECTIONS[searchDirection][0];
							tmpY += DIRECTIONS[searchDirection][1];

							continue;
						} else {
							break;
						}
					}
				}
			}
		}
		break;
	default:
		break;
	}

	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
callq 0x2090
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cmpl $0x3, %eax
ja 0x33e8
leaq 0x2449(%rip), %rcx      # 0x53e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq $0x38, %r13
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
leaq 0x243a(%rip), %rcx      # 0x53f0
xorl %esi, %esi
movl %edx, (%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
movl %edx, 0x4(%rsp)
cmpl $0xf, %esi
setae %al
cmpl $0xf, %r8d
setae %r9b
orb %al, %r9b
xorl %r10d, %r10d
xorl %r11d, %r11d
movb (%rbx), %dl
testb %dl, %dl
sete %bpl
je 0x303b
movq 0x8(%rsp), %rax
movl %esi, %r14d
movl %r8d, %r12d
testb %r9b, %r9b
jne 0x3052
movslq %r12d, %r15
movslq %r14d, %rdi
leaq (%r15,%r15,4), %r15
leaq (%r15,%r15,2), %r15
addq %r13, %r15
cmpb %dl, (%rdi,%r15)
jne 0x3052
movb (%rax), %dl
testb %dl, %dl
sete %bpl
je 0x303b
addl 0x4(%rcx,%r10,8), %r12d
cmpl $0xe, %r12d
jg 0x3052
addl (%rcx,%r10,8), %r14d
cmpl $0xe, %r14d
jg 0x3052
movl %r12d, %r15d
orl %r14d, %r15d
incq %rax
testl %r15d, %r15d
jns 0x2ff5
jmp 0x3052
movq 0x10(%rsp), %rax
movl %esi, (%rax)
movq 0x18(%rsp), %rax
movl %r8d, (%rax)
movq 0x20(%rsp), %rax
movl %r10d, (%rax)
testb $0x1, %bpl
jne 0x3073
cmpq $0x7, %r10
leaq 0x1(%r10), %rax
setae %r11b
movq %rax, %r10
cmpq $0x8, %rax
jne 0x2fdb
jmp 0x3079
testb $0x1, %r11b
je 0x3092
cmpl $0xe, %r8d
leal 0x1(%r8), %eax
setae %dl
movl %eax, %r8d
cmpl $0xf, %eax
jne 0x2fc0
jmp 0x309d
testb $0x1, 0x4(%rsp)
je 0x33e0
cmpl $0xe, %esi
leal 0x1(%rsi), %eax
setae %dl
movl %eax, %esi
cmpl $0xf, %eax
jne 0x2fb8
jmp 0x33e8
addq $0x38, %r13
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
leaq 0x2324(%rip), %rcx      # 0x53f0
xorl %esi, %esi
movl %edx, (%rsp)
movl $0xe, %edi
xorl %eax, %eax
movl %eax, 0x4(%rsp)
cmpl $0xf, %esi
setae %al
cmpl $0xf, %edi
setae %r9b
orb %al, %r9b
xorl %r10d, %r10d
xorl %r11d, %r11d
movb (%rbx), %dl
testb %dl, %dl
sete %bpl
je 0x3152
movq 0x8(%rsp), %rax
movl %esi, %r14d
movl %edi, %r15d
testb %r9b, %r9b
jne 0x3168
movslq %r15d, %r12
movslq %r14d, %r8
leaq (%r12,%r12,4), %r12
leaq (%r12,%r12,2), %r12
addq %r13, %r12
cmpb %dl, (%r8,%r12)
jne 0x3168
movb (%rax), %dl
testb %dl, %dl
sete %bpl
je 0x3152
addl 0x4(%rcx,%r10,8), %r15d
cmpl $0xe, %r15d
jg 0x3168
addl (%rcx,%r10,8), %r14d
cmpl $0xe, %r14d
jg 0x3168
movl %r15d, %r12d
orl %r14d, %r12d
incq %rax
testl %r12d, %r12d
jns 0x310c
jmp 0x3168
movq 0x10(%rsp), %rax
movl %esi, (%rax)
movq 0x18(%rsp), %rax
movl %edi, (%rax)
movq 0x20(%rsp), %rax
movl %r10d, (%rax)
testb $0x1, %bpl
jne 0x3189
cmpq $0x7, %r10
leaq 0x1(%r10), %rax
setae %r11b
movq %rax, %r10
cmpq $0x8, %rax
jne 0x30f2
jmp 0x318f
testb $0x1, %r11b
je 0x319d
subl $0x1, %edi
setb %al
jae 0x30d8
jmp 0x31a8
testb $0x1, 0x4(%rsp)
je 0x33e0
cmpl $0xe, %esi
leal 0x1(%rsi), %eax
setae %dl
movl %eax, %esi
cmpl $0xf, %eax
jne 0x30ce
jmp 0x33e8
addq $0x38, %r13
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
movl $0xe, %ecx
xorl %eax, %eax
leaq 0x2214(%rip), %rsi      # 0x53f0
movl %eax, (%rsp)
xorl %eax, %eax
movl $0xe, %r8d
movl %eax, 0x4(%rsp)
cmpl $0xf, %ecx
setge %al
movl %r8d, %edx
orl %ecx, %edx
sets %dl
cmpl $0xf, %r8d
setge %r9b
orb %al, %r9b
orb %dl, %r9b
xorl %r10d, %r10d
xorl %r11d, %r11d
movb (%rbx), %dl
testb %dl, %dl
sete %bpl
je 0x326d
movq 0x8(%rsp), %rax
movl %ecx, %r14d
movl %r8d, %r15d
testb %r9b, %r9b
jne 0x3284
movslq %r15d, %r12
movslq %r14d, %rdi
leaq (%r12,%r12,4), %r12
leaq (%r12,%r12,2), %r12
addq %r13, %r12
cmpb %dl, (%rdi,%r12)
jne 0x3284
movb (%rax), %dl
testb %dl, %dl
sete %bpl
je 0x326d
addl 0x4(%rsi,%r10,8), %r15d
cmpl $0xe, %r15d
jg 0x3284
addl (%rsi,%r10,8), %r14d
cmpl $0xe, %r14d
jg 0x3284
movl %r15d, %r12d
orl %r14d, %r12d
incq %rax
testl %r12d, %r12d
jns 0x3227
jmp 0x3284
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movl %r8d, (%rax)
movq 0x20(%rsp), %rax
movl %r10d, (%rax)
testb $0x1, %bpl
jne 0x32a5
cmpq $0x7, %r10
leaq 0x1(%r10), %rax
setae %r11b
movq %rax, %r10
cmpq $0x8, %rax
jne 0x320d
jmp 0x32ab
testb $0x1, %r11b
je 0x32ba
subl $0x1, %r8d
setb %al
jae 0x31e7
jmp 0x32c5
testb $0x1, 0x4(%rsp)
je 0x33e0
subl $0x1, %ecx
setb %al
jae 0x31dc
jmp 0x33e8
addq $0x38, %r13
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
movl $0xe, %ecx
xorl %eax, %eax
leaq 0x20ff(%rip), %rsi      # 0x53f0
movl %eax, (%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
movl %edx, 0x4(%rsp)
cmpl $0xf, %ecx
setae %al
cmpl $0xf, %r8d
setae %r9b
orb %al, %r9b
xorl %r10d, %r10d
xorl %r11d, %r11d
movb (%rbx), %dl
testb %dl, %dl
sete %bpl
je 0x3374
movq 0x8(%rsp), %rax
movl %ecx, %r14d
movl %r8d, %r15d
testb %r9b, %r9b
jne 0x338b
movslq %r15d, %r12
movslq %r14d, %rdi
leaq (%r12,%r12,4), %r12
leaq (%r12,%r12,2), %r12
addq %r13, %r12
cmpb %dl, (%rdi,%r12)
jne 0x338b
movb (%rax), %dl
testb %dl, %dl
sete %bpl
je 0x3374
addl 0x4(%rsi,%r10,8), %r15d
cmpl $0xe, %r15d
jg 0x338b
addl (%rsi,%r10,8), %r14d
cmpl $0xe, %r14d
jg 0x338b
movl %r15d, %r12d
orl %r14d, %r12d
incq %rax
testl %r12d, %r12d
jns 0x332e
jmp 0x338b
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movl %r8d, (%rax)
movq 0x20(%rsp), %rax
movl %r10d, (%rax)
testb $0x1, %bpl
jne 0x33ac
cmpq $0x7, %r10
leaq 0x1(%r10), %rax
setae %r11b
movq %rax, %r10
cmpq $0x8, %rax
jne 0x3314
jmp 0x33b2
testb $0x1, %r11b
je 0x33cb
cmpl $0xe, %r8d
leal 0x1(%r8), %eax
setae %dl
movl %eax, %r8d
cmpl $0xf, %eax
jne 0x32f9
jmp 0x33d2
testb $0x1, 0x4(%rsp)
je 0x33e0
subl $0x1, %ecx
setb %al
jae 0x32f1
jmp 0x33e8
movb $0x1, %al
testb $0x1, (%rsp)
je 0x33ea
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop