// File: /workspace/github_cpp_makefile_star2_O3/antoniogarro[P]Hara/heuristics.cpp
// Function: Goban::match_mogo_pattern(int, bool) const
bool Goban::match_mogo_pattern(int point, bool side) const
{    
  if (point == 1 || point == size || point == size2 || point == size*(size-1)+1) return false;  //filter corners.
  
  if (point > size && point % size && point <= size*(size-1) && point % size != 1) {
    const int *vic = vicinity[point];
    for (int i = 1; i < 8; i+=2) {
      if (points[vic[i]]) {
        bool adj_color = points[vic[i]]->get_color();
        if (points[vic[i-1]] && points[vic[i-1]]->get_color() != adj_color) {
          if (points[vic[i+2]] == 0 && points[vic[i+6]] == 0) {
            if (points[vic[i+1]] && points[vic[i+1]]->get_color() != adj_color) {
              return true;  //Hane1
            }
            if (points[vic[i+1]] == 0 && points[vic[i+4]] == 0) {
              return true;  //Hane2
            }
          }
          if (points[vic[i+2]] == 0 && points[vic[i+4]] == 0 &&
              points[vic[i+6]] && points[vic[i+6]]->get_color() != adj_color) {
              return true;  //Hane3
          }
          if (points[vic[i+6]] && points[vic[i+6]]->get_color() == adj_color) {
            if ((points[vic[i+2]] || points[vic[i+4]] == 0 || points[vic[i+4]]->get_color() == adj_color) &&
                (points[vic[i+4]] || points[vic[i+2]] == 0 || points[vic[i+2]]->get_color() == adj_color)) {
              return true;  //Cut1
            }
          }
        }
        if (points[vic[i+1]] && points[vic[i+1]]->get_color() != adj_color) {
          if (points[vic[i+2]] == 0 && points[vic[i+6]] == 0) {
            if (points[vic[i-1]] == 0 && points[vic[i+4]] == 0) {
              return true;  //Mirror Hane2
            }
          }
          if (points[vic[i+4]] == 0 && points[vic[i+6]] == 0 &&
              points[vic[i+2]] && points[vic[i+2]]->get_color() != adj_color) {
              return true;  //Mirror Hane3
          }
        }
        if (points[vic[i+2]] && points[vic[i+6]] && points[vic[i+2]]->get_color() != adj_color &&
            points[vic[i+6]]->get_color() != adj_color &&
            (points[vic[i+4]] == 0 || points[vic[i+4]]->get_color() == adj_color) &&
            (points[vic[i+3]] == 0 || points[vic[i+3]]->get_color() == adj_color) &&
            (points[vic[i+5]] == 0 || points[vic[i+5]]->get_color() == adj_color)) {
          return true;  //Cut2
        }
        if (adj_color != side && points[vic[i-1]] && points[vic[i-1]]->get_color() == side &&
            points[vic[i+2]] == 0 && points[vic[i+4]] == 0 && points[vic[i+6]] == 0 &&
            points[vic[i+1]] && points[vic[i+1]]->get_color() == adj_color) {
          return true;  //Hane4
        }
        if (adj_color != side && points[vic[i+1]] && points[vic[i+1]]->get_color() == side &&
            points[vic[i+2]] == 0 && points[vic[i+4]] == 0 && points[vic[i+6]] == 0 &&
            points[vic[i-1]] && points[vic[i-1]]->get_color() == adj_color) {
          return true;  //Mirror Hane4
        }
      }
    }
  } else {
    for (int i = 1; i < 8; i+=2) {
      const int *vic = vicinity[point];
      if (vic[i]) {
        if (points[vic[i]]) {
          if (vic[i+2] && points[vic[i+2]] && points[vic[i+2]]->get_color() != points[vic[i]]->get_color() &&
             (vic[i+6]==0 || points[vic[i+6]] == 0 || points[vic[i+6]]->get_color() != points[vic[i]]->get_color())) {
            return true;  //Side2
          }
          if (vic[i+6] && points[vic[i+6]] && points[vic[i+6]]->get_color() != points[vic[i]]->get_color() &&
             (vic[i+2]== 0 || points[vic[i+2]] == 0 || points[vic[i+2]]->get_color() != points[vic[i]]->get_color())) {
            return true;  //Mirror Side2
          }
          if (points[vic[i]]->get_color() == side) {
            if ((vic[i+1] && points[vic[i+1]] && points[vic[i+1]]->get_color() != side)) {
              return true;  //Side3
            }
            if ((vic[i-1] && points[vic[i-1]] && points[vic[i-1]]->get_color() != side)) {
              return true;  //Mirror Side3
            }
          }
          if (points[vic[i]]->get_color() != side) {
            if (vic[i+1] && points[vic[i+1]] && points[vic[i+1]]->get_color() == side) {
              if (vic[i+2] == 0 || points[vic[i+2]] == 0 || points[vic[i+2]]->get_color() == side) {
                return true;  //Side4
              }
              if (vic[i+2] && points[vic[i+2]] && points[vic[i+2]]->get_color() != side
                && vic[i+6] && points[vic[i+6]] && points[vic[i+6]]->get_color() == side) {
                return true; //Side5
              }
            }
            if (vic[i-1] && points[vic[i-1]] && points[vic[i-1]]->get_color() == side) {
              if (vic[i+6] == 0 || points[vic[i+6]] == 0 || points[vic[i+6]]->get_color() == side) {
                return true;  //Mirror Side4
              }
              if (vic[i+6] && points[vic[i+6]] && points[vic[i+6]]->get_color() != side &&
                  vic[i+2] && points[vic[i+2]] && points[vic[i+2]]->get_color() == side) {
                return true; //Mirror Side5
              }
            }
          }
        } else if ((vic[i+6] && points[vic[i+6]] && vic[i-1] && points[vic[i-1]] &&
                    points[vic[i+6]]->get_color() != points[vic[i-1]]->get_color())
               || (vic[i+2] && points[vic[i+2]] && vic[i+1] && points[vic[i+1]] &&
                    points[vic[i+2]]->get_color() != points[vic[i+1]]->get_color())) {
          return true;  //Side1 and mirror.
        }
      }
    }
  }
  return false;
}

// Assembly:
cmpl $0x1, %esi
jne 0x89ac
xorl %eax, %eax
retq
movl 0x8(%rdi), %r8d
xorl %eax, %eax
cmpl %esi, %r8d
je 0x89ab
cmpl %esi, 0xc(%rdi)
je 0x89ab
leal -0x1(%r8), %r9d
imull %r8d, %r9d
leal 0x1(%r9), %eax
cmpl %esi, %eax
je 0x89a9
pushq %rbx
movl %edx, %ecx
cmpl %esi, %r8d
jge 0x8c67
movl %esi, %eax
cltd
idivl %r8d
cmpl %esi, %r9d
jl 0x8c67
cmpl $0x2, %edx
jb 0x8c67
movslq %esi, %rax
shlq $0x6, %rax
leaq (%rax,%rdi), %rdx
addq $0xd9c94, %rdx          # imm = 0xD9C94
movq $-0x1, %rsi
movslq -0x14(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8c52
movb (%rax), %r8b
movslq -0x18(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %r9
testq %r9, %r9
je 0x8afb
cmpb %r8b, (%r9)
je 0x8afb
movslq -0xc(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %r10
movslq 0x4(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %r10, %r10
je 0x8a7f
testq %rax, %rax
je 0x8afb
cmpb %r8b, (%rax)
jne 0x8afb
testq %r10, %r10
je 0x8add
movslq -0x4(%rdx,%rsi,4), %r11
movb $0x1, %al
cmpq $0x0, 0x18(%rdi,%r11,8)
je 0x8af2
jmp 0x8e8c
testq %rax, %rax
je 0x8a93
movslq -0x4(%rdx,%rsi,4), %r10
cmpq $0x0, 0x18(%rdi,%r10,8)
jne 0x8ad8
jmp 0x8acf
movslq -0x10(%rdx,%rsi,4), %r11
movq 0x18(%rdi,%r11,8), %r11
testq %r11, %r11
je 0x8aac
cmpb %r8b, (%r11)
je 0x8abd
jmp 0x8e8a
movslq -0x4(%rdx,%rsi,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
je 0x8e8a
movslq -0x4(%rdx,%rsi,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
jne 0x8a54
testq %rax, %rax
je 0x8afb
cmpb %r8b, (%rax)
jne 0x8e8a
cmpb %r8b, (%rax)
jne 0x8afb
movslq -0x4(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %r10
movb $0x1, %al
testq %r10, %r10
je 0x8e8c
cmpb %r8b, (%r10)
je 0x8e8c
movslq -0x10(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %r10
testq %r10, %r10
je 0x8b66
cmpb %r8b, (%r10)
je 0x8b66
movslq -0xc(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
jne 0x8b3e
movslq 0x4(%rdx,%rsi,4), %r11
movq 0x18(%rdi,%r11,8), %r11
orq %r9, %r11
jne 0x8b3e
movslq -0x4(%rdx,%rsi,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
je 0x8e8a
movslq -0x4(%rdx,%rsi,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
jne 0x8b66
testq %rax, %rax
je 0x8b66
movslq 0x4(%rdx,%rsi,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
jne 0x8b66
cmpb %r8b, (%rax)
jne 0x8e8a
movslq -0xc(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %r11
testq %r11, %r11
je 0x8bd3
movslq 0x4(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8bd3
cmpb %r8b, (%r11)
je 0x8bd3
cmpb %r8b, (%rax)
je 0x8bd3
movslq -0x4(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8ba2
cmpb %r8b, (%rax)
jne 0x8bd3
movslq -0x8(%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8bb6
cmpb %r8b, (%rax)
jne 0x8bd3
movslq (%rdx,%rsi,4), %rax
movq 0x18(%rdi,%rax,8), %rbx
movb $0x1, %al
testq %rbx, %rbx
je 0x8e8c
cmpb %r8b, (%rbx)
je 0x8e8c
cmpb %cl, %r8b
je 0x8c52
testq %r9, %r9
je 0x8c03
testq %r11, %r11
jne 0x8c03
movb (%r9), %al
xorb %cl, %al
jne 0x8c03
movslq -0x4(%rdx,%rsi,4), %rax
cmpq $0x0, 0x18(%rdi,%rax,8)
jne 0x8c03
movslq 0x4(%rdx,%rsi,4), %rax
cmpq $0x0, 0x18(%rdi,%rax,8)
je 0x8c3d
testq %r10, %r10
je 0x8c52
testq %r11, %r11
jne 0x8c52
movb (%r10), %al
xorb %cl, %al
jne 0x8c52
movslq -0x4(%rdx,%rsi,4), %rax
cmpq $0x0, 0x18(%rdi,%rax,8)
jne 0x8c52
testq %r9, %r9
je 0x8c52
movslq 0x4(%rdx,%rsi,4), %rax
cmpq $0x0, 0x18(%rdi,%rax,8)
jne 0x8c52
cmpb %r8b, (%r9)
jne 0x8c52
jmp 0x8e8a
testq %r10, %r10
je 0x8c52
movb (%r10), %al
cmpb %r8b, %al
je 0x8e8a
cmpb %cl, %al
je 0x8c21
addq $0x2, %rsi
xorl %eax, %eax
cmpq $0x6, %rsi
jb 0x8a09
jmp 0x8e8c
movslq %esi, %rax
shlq $0x6, %rax
leaq (%rax,%rdi), %rdx
addq $0xd9c94, %rdx          # imm = 0xD9C94
movq $-0x1, %rsi
movslq -0x14(%rdx,%rsi,4), %rax
testq %rax, %rax
je 0x8e78
movq 0x18(%rdi,%rax,8), %r10
testq %r10, %r10
je 0x8d2e
movslq -0xc(%rdx,%rsi,4), %r8
testq %r8, %r8
je 0x8cdf
movq 0x18(%rdi,%r8,8), %rax
testq %rax, %rax
je 0x8cdf
movb (%r10), %r9b
cmpb %r9b, (%rax)
je 0x8cdf
movslq 0x4(%rdx,%rsi,4), %r11
movb $0x1, %al
testq %r11, %r11
je 0x8e8c
movq 0x18(%rdi,%r11,8), %r11
testq %r11, %r11
je 0x8e8c
cmpb %r9b, (%r11)
jne 0x8e8c
movslq 0x4(%rdx,%rsi,4), %r9
testq %r9, %r9
je 0x8da9
movq 0x18(%rdi,%r9,8), %rax
movb (%r10), %r10b
testq %rax, %rax
je 0x8dac
cmpb %r10b, (%rax)
je 0x8dac
movb $0x1, %al
testl %r8d, %r8d
je 0x8e8c
movq 0x18(%rdi,%r8,8), %r11
testq %r11, %r11
je 0x8e8c
cmpb %r10b, (%r11)
je 0x8dac
jmp 0x8e8c
movslq 0x4(%rdx,%rsi,4), %rax
testq %rax, %rax
je 0x8d61
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8d61
movslq -0x18(%rdx,%rsi,4), %r8
testq %r8, %r8
je 0x8d61
movq 0x18(%rdi,%r8,8), %r8
testq %r8, %r8
je 0x8d61
movb (%rax), %al
cmpb (%r8), %al
jne 0x8e8a
movslq -0xc(%rdx,%rsi,4), %rax
testq %rax, %rax
je 0x8e78
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8e78
movslq -0x10(%rdx,%rsi,4), %r8
testq %r8, %r8
je 0x8e78
movq 0x18(%rdi,%r8,8), %r8
testq %r8, %r8
je 0x8e78
movb (%rax), %al
cmpb (%r8), %al
je 0x8e78
jmp 0x8e8a
movb (%r10), %r10b
xorb %cl, %r10b
movslq -0x10(%rdx,%rsi,4), %rax
testb $0x1, %r10b
je 0x8e4e
testl %eax, %eax
je 0x8e0a
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8e0a
cmpb %cl, (%rax)
jne 0x8e0a
movb $0x1, %al
testl %r8d, %r8d
je 0x8e8c
movq 0x18(%rdi,%r8,8), %r10
testq %r10, %r10
je 0x8e8c
cmpb %cl, (%r10)
je 0x8e8c
testl %r9d, %r9d
je 0x8e0a
movq 0x18(%rdi,%r9,8), %r10
testq %r10, %r10
je 0x8e0a
cmpb %cl, (%r10)
je 0x8e8c
movslq -0x18(%rdx,%rsi,4), %rax
testq %rax, %rax
je 0x8e78
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8e78
cmpb %cl, (%rax)
jne 0x8e78
movb $0x1, %al
testl %r9d, %r9d
je 0x8e8c
movq 0x18(%rdi,%r9,8), %r9
testq %r9, %r9
je 0x8e8c
cmpb %cl, (%r9)
je 0x8e8c
testl %r8d, %r8d
je 0x8e78
movq 0x18(%rdi,%r8,8), %r8
testq %r8, %r8
je 0x8e78
cmpb %cl, (%r8)
jne 0x8e78
jmp 0x8e8c
testl %eax, %eax
je 0x8e60
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8e60
cmpb %cl, (%rax)
jne 0x8e8a
movslq -0x18(%rdx,%rsi,4), %rax
testq %rax, %rax
je 0x8e78
movq 0x18(%rdi,%rax,8), %rax
testq %rax, %rax
je 0x8e78
cmpb %cl, (%rax)
jne 0x8e8a
addq $0x2, %rsi
cmpq $0x6, %rsi
jb 0x8c80
xorl %eax, %eax
jmp 0x8e8c
movb $0x1, %al
popq %rbx
retq