// File: /workspace/github_cpp_makefile_star2_O2/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 0x7e16
xorl %eax, %eax
retq
movl 0x8(%rdi), %r9d
xorl %eax, %eax
cmpl %esi, %r9d
je 0x7e15
cmpl %esi, 0xc(%rdi)
je 0x7e15
leal -0x1(%r9), %r10d
imull %r9d, %r10d
leal 0x1(%r10), %eax
cmpl %esi, %eax
je 0x7e13
pushq %rbx
movl %edx, %ecx
movslq %esi, %r8
cmpl %esi, %r9d
jge 0x80c6
movl %esi, %eax
cltd
idivl %r9d
cmpl %esi, %r10d
jl 0x80c6
cmpl $0x2, %edx
jb 0x80c6
shlq $0x6, %r8
addq %rdi, %r8
movl $0x36725, %edx          # imm = 0x36725
leaq -0x36724(%rdx), %rax
cmpq $0x8, %rax
setb %al
jae 0x82da
movslq -0x18(%r8,%rdx,4), %rsi
movq 0x18(%rdi,%rsi,8), %rsi
testq %rsi, %rsi
je 0x80bd
movb (%rsi), %sil
movslq -0x1c(%r8,%rdx,4), %r9
movq 0x18(%rdi,%r9,8), %r9
testq %r9, %r9
je 0x7f6a
cmpb %sil, (%r9)
je 0x7f6a
movslq -0x10(%r8,%rdx,4), %r10
movq 0x18(%rdi,%r10,8), %r10
movslq (%r8,%rdx,4), %r11
movq 0x18(%rdi,%r11,8), %r11
testq %r10, %r10
je 0x7ef0
testq %r11, %r11
je 0x7f6a
cmpb %sil, (%r11)
jne 0x7f6a
testq %r10, %r10
je 0x7f4e
movslq -0x8(%r8,%rdx,4), %r11
cmpq $0x0, 0x18(%rdi,%r11,8)
je 0x7f61
jmp 0x82da
testq %r11, %r11
je 0x7f04
movslq -0x8(%r8,%rdx,4), %r10
cmpq $0x0, 0x18(%rdi,%r10,8)
jne 0x7f49
jmp 0x7f40
movslq -0x14(%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
testq %rbx, %rbx
je 0x7f1d
cmpb %sil, (%rbx)
je 0x7f2e
jmp 0x82da
movslq -0x8(%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
je 0x82da
movslq -0x8(%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
jne 0x7ec7
testq %r11, %r11
je 0x7f6a
cmpb %sil, (%r11)
jne 0x82da
cmpb %sil, (%r11)
jne 0x7f6a
movslq -0x8(%r8,%rdx,4), %r10
movq 0x18(%rdi,%r10,8), %r10
testq %r10, %r10
je 0x82da
cmpb %sil, (%r10)
je 0x82da
movslq -0x14(%r8,%rdx,4), %r10
movq 0x18(%rdi,%r10,8), %r10
testq %r10, %r10
je 0x7fd3
cmpb %sil, (%r10)
je 0x7fd3
movslq -0x10(%r8,%rdx,4), %r11
movq 0x18(%rdi,%r11,8), %r11
testq %r11, %r11
jne 0x7fac
movslq (%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
orq %r9, %rbx
jne 0x7fac
movslq -0x8(%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
je 0x82da
movslq -0x8(%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
jne 0x7fd3
testq %r11, %r11
je 0x7fd3
movslq (%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
jne 0x7fd3
cmpb %sil, (%r11)
jne 0x82da
movslq -0x10(%r8,%rdx,4), %r11
movq 0x18(%rdi,%r11,8), %r11
testq %r11, %r11
je 0x803e
movslq (%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
testq %rbx, %rbx
je 0x803e
cmpb %sil, (%r11)
je 0x803e
cmpb %sil, (%rbx)
je 0x803e
movslq -0x8(%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
testq %rbx, %rbx
je 0x800e
cmpb %sil, (%rbx)
jne 0x803e
movslq -0xc(%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
testq %rbx, %rbx
je 0x8022
cmpb %sil, (%rbx)
jne 0x803e
movslq -0x4(%r8,%rdx,4), %rbx
movq 0x18(%rdi,%rbx,8), %rbx
testq %rbx, %rbx
je 0x82da
cmpb %sil, (%rbx)
je 0x82da
cmpb %cl, %sil
je 0x80bd
testq %r9, %r9
je 0x806d
testq %r11, %r11
jne 0x806d
movb (%r9), %bl
xorb %cl, %bl
jne 0x806d
movslq -0x8(%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
jne 0x806d
movslq (%r8,%rdx,4), %rbx
cmpq $0x0, 0x18(%rdi,%rbx,8)
je 0x80a7
testq %r10, %r10
je 0x80bd
testq %r11, %r11
jne 0x80bd
movb (%r10), %r10b
xorb %cl, %r10b
jne 0x80bd
movslq -0x8(%r8,%rdx,4), %r10
cmpq $0x0, 0x18(%rdi,%r10,8)
jne 0x80bd
testq %r9, %r9
je 0x80bd
movslq (%r8,%rdx,4), %r10
cmpq $0x0, 0x18(%rdi,%r10,8)
jne 0x80bd
cmpb %sil, (%r9)
jne 0x80bd
jmp 0x82da
testq %r10, %r10
je 0x80bd
movb (%r10), %r10b
cmpb %sil, %r10b
je 0x82da
cmpb %cl, %r10b
je 0x808c
addq $0x2, %rdx
jmp 0x7e69
shlq $0x6, %r8
addq %rdi, %r8
movl $0x3671e, %edx          # imm = 0x3671E
leaq -0x3671d(%rdx), %rax
cmpq $0x8, %rax
setb %al
jae 0x82da
movslq 0x4(%r8,%rdx,4), %rsi
testq %rsi, %rsi
je 0x82d1
movq 0x18(%rdi,%rsi,8), %r10
testq %r10, %r10
je 0x818f
movslq 0xc(%r8,%rdx,4), %rsi
testq %rsi, %rsi
je 0x8143
movq 0x18(%rdi,%rsi,8), %r11
testq %r11, %r11
je 0x8143
movb (%r10), %r9b
cmpb %r9b, (%r11)
je 0x8143
movslq 0x1c(%r8,%rdx,4), %r11
testq %r11, %r11
je 0x82da
movq 0x18(%rdi,%r11,8), %r11
testq %r11, %r11
je 0x82da
cmpb %r9b, (%r11)
jne 0x82da
movslq 0x1c(%r8,%rdx,4), %r9
testq %r9, %r9
je 0x820b
movq 0x18(%rdi,%r9,8), %r11
movb (%r10), %r10b
testq %r11, %r11
je 0x820e
cmpb %r10b, (%r11)
je 0x820e
testl %esi, %esi
je 0x82da
movq 0x18(%rdi,%rsi,8), %r11
testq %r11, %r11
je 0x82da
cmpb %r10b, (%r11)
je 0x820e
jmp 0x82da
movslq 0x1c(%r8,%rdx,4), %rsi
testq %rsi, %rsi
je 0x81c2
movq 0x18(%rdi,%rsi,8), %rsi
testq %rsi, %rsi
je 0x81c2
movslq (%r8,%rdx,4), %r9
testq %r9, %r9
je 0x81c2
movq 0x18(%rdi,%r9,8), %r9
testq %r9, %r9
je 0x81c2
movb (%rsi), %sil
cmpb (%r9), %sil
jne 0x82da
movslq 0xc(%r8,%rdx,4), %rsi
testq %rsi, %rsi
je 0x82d1
movq 0x18(%rdi,%rsi,8), %rsi
testq %rsi, %rsi
je 0x82d1
movslq 0x8(%r8,%rdx,4), %r9
testq %r9, %r9
je 0x82d1
movq 0x18(%rdi,%r9,8), %r9
testq %r9, %r9
je 0x82d1
movb (%rsi), %sil
cmpb (%r9), %sil
je 0x82d1
jmp 0x82da
movb (%r10), %r10b
xorb %cl, %r10b
movslq 0x8(%r8,%rdx,4), %r11
testb $0x1, %r10b
je 0x82a7
testl %r11d, %r11d
je 0x8267
movq 0x18(%rdi,%r11,8), %r10
testq %r10, %r10
je 0x8267
cmpb %cl, (%r10)
jne 0x8267
testl %esi, %esi
je 0x82da
movq 0x18(%rdi,%rsi,8), %r10
testq %r10, %r10
je 0x82da
cmpb %cl, (%r10)
je 0x82da
testl %r9d, %r9d
je 0x8267
movq 0x18(%rdi,%r9,8), %r10
testq %r10, %r10
je 0x8267
cmpb %cl, (%r10)
je 0x82da
movslq (%r8,%rdx,4), %r10
testq %r10, %r10
je 0x82d1
movq 0x18(%rdi,%r10,8), %r10
testq %r10, %r10
je 0x82d1
cmpb %cl, (%r10)
jne 0x82d1
testl %r9d, %r9d
je 0x82da
movq 0x18(%rdi,%r9,8), %r9
testq %r9, %r9
je 0x82da
cmpb %cl, (%r9)
je 0x82da
testl %esi, %esi
je 0x82d1
movq 0x18(%rdi,%rsi,8), %rsi
testq %rsi, %rsi
je 0x82d1
cmpb %cl, (%rsi)
jne 0x82d1
jmp 0x82da
testl %r11d, %r11d
je 0x82ba
movq 0x18(%rdi,%r11,8), %rsi
testq %rsi, %rsi
je 0x82ba
cmpb %cl, (%rsi)
jne 0x82da
movslq (%r8,%rdx,4), %rsi
testq %rsi, %rsi
je 0x82d1
movq 0x18(%rdi,%rsi,8), %rsi
testq %rsi, %rsi
je 0x82d1
cmpb %cl, (%rsi)
jne 0x82da
addq $0x2, %rdx
jmp 0x80d2
popq %rbx
retq