// File: /workspace/github_cpp_makefile_star2_O3/antoniogarro[P]Hara/heuristics.cpp
// Function: Goban::total_liberties(int, bool, PList*, int, Group const*) const
int Goban::total_liberties(int point, bool color, PList *liberties, int enough=0, const Group *exclude=0) const
{
  PointSet<MAXSIZE2> libs;
  if (liberties) point_liberties(point, *liberties);
  point_liberties(point, libs);
  if (enough && libs.length() > enough) return libs.length();
  
  GroupSet<4> neighbours;
  int nneigh = neighbour_groups(point, neighbours);
  for (int i = 0; i < nneigh; i++) {
    const Group *curr_neigh = neighbours[i];
    if (curr_neigh != exclude) {
      if (curr_neigh->get_color() == color) {
        for (Group::LibertyIterator lib(curr_neigh); lib; ++lib) {
          if (*lib != point) {
            if (liberties) liberties->add(*lib);
            libs.add(*lib);
            if (enough && libs.length() > enough) return libs.length();
          }
        }
      } else if (curr_neigh->get_nliberties() == 1) {
        for (Group::StoneIterator st(curr_neigh); st; ++st) {
          for (int j = 0; adjacent[*st][j]; j++) {
            if (adjacent[*st][j] == point) {
              libs.add(*st);
              if (enough && libs.length() > enough) return libs.length();
            } else if (points[adjacent[*st][j]] &&
                       points[adjacent[*st][j]]->get_color() == color) {
              for (int k = 0; k < nneigh; k++) {
                if (points[adjacent[*st][j]] == neighbours[k]) {
                  libs.add(*st);
                  if (enough && libs.length() > enough) return libs.length();
                }
              }
            }
          }
        }
      }
    }
  }
  return libs.length();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x608, %rsp            # imm = 0x608
movq %r9, 0x18(%rsp)
movl %r8d, %ebp
movq %rcx, %rbx
movl %edx, 0x8(%rsp)
movq %rdi, %r13
xorl %eax, %eax
movl %eax, 0x604(%rsp)
movl %eax, 0x60(%rsp)
leaq 0x6dd5(%rip), %rax      # 0xfcf0
movq %rax, 0x58(%rsp)
testq %rcx, %rcx
movl %esi, 0xc(%rsp)
je 0x8f38
movq %r13, %rdi
movq %rbx, %rdx
callq 0x5388
movl 0xc(%rsp), %esi
movq %rbx, 0x10(%rsp)
leaq 0x58(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rdx
movl %esi, %r14d
callq 0x5388
testl %ebp, %ebp
setne %cl
movl 0x5ac(%rbx), %eax
cmpl %ebp, %eax
setg %dl
testb %dl, %cl
jne 0x920e
leaq 0x20(%rsp), %rdx
movl $0x0, 0x30(%rdx)
movq $0x0, (%rdx)
movq %r13, %rdi
movl %r14d, %esi
callq 0x533c
testl %eax, %eax
movq 0x10(%rsp), %rdi
jle 0x9207
movl %r14d, %r9d
leaq 0xd63e8(%r13), %rbx
movl %eax, %r15d
xorl %r14d, %r14d
movq 0x20(%rsp,%r14,8), %r12
cmpq 0x18(%rsp), %r12
je 0x91fb
movl 0x8(%rsp), %eax
cmpb %al, (%r12)
je 0x9154
cmpl $0x1, 0x96c(%r12)
jne 0x91fb
movl 0x4(%r12), %edx
testl %edx, %edx
je 0x91fb
addq $0x4, %r12
movslq %edx, %rax
leaq (%rax,%rax,4), %rax
movl (%rbx,%rax,4), %eax
testl %eax, %eax
je 0x913e
xorl %ecx, %ecx
cmpl %r9d, %eax
jne 0x9057
movl 0x604(%rsp), %esi
movl $0x169, %eax            # imm = 0x169
cmpq $0x169, %rsi            # imm = 0x169
je 0x910f
testl %esi, %esi
jle 0x902b
xorl %eax, %eax
cmpl %edx, 0x60(%rsp,%rax,4)
je 0x910d
incq %rax
cmpq %rax, %rsi
jne 0x9019
movslq %esi, %rax
incl %esi
movl %esi, 0x604(%rsp)
movl %edx, 0x60(%rsp,%rax,4)
movslq 0x604(%rsp), %rax
movl $0x0, 0x60(%rsp,%rax,4)
movl 0x604(%rsp), %eax
jmp 0x910f
cltq
movq 0x18(%r13,%rax,8), %rax
testq %rax, %rax
je 0x9123
movl 0x8(%rsp), %edx
cmpb %dl, (%rax)
jne 0x9123
xorl %edx, %edx
movslq (%r12), %rsi
leaq (%rsi,%rsi,4), %rax
leaq (%rbx,%rax,4), %rax
movslq (%rax,%rcx,4), %rax
movq 0x18(%r13,%rax,8), %rax
cmpq 0x20(%rsp,%rdx,8), %rax
jne 0x90ff
movl 0x604(%rsp), %r8d
movl $0x169, %eax            # imm = 0x169
cmpq $0x169, %r8             # imm = 0x169
je 0x90ea
testl %r8d, %r8d
jle 0x90bc
xorl %eax, %eax
cmpl %esi, 0x60(%rsp,%rax,4)
je 0x90e7
incq %rax
cmpq %rax, %r8
jne 0x90ae
movslq %r8d, %rax
incl %r8d
movl %r8d, 0x604(%rsp)
movl %esi, 0x60(%rsp,%rax,4)
movslq 0x604(%rsp), %rax
movl $0x0, 0x60(%rsp,%rax,4)
movl 0x604(%rsp), %eax
jmp 0x90ea
movl %r8d, %eax
testl %ebp, %ebp
setne %sil
cmpl %ebp, %eax
setg %r8b
testb %r8b, %sil
jne 0x920e
incq %rdx
cmpq %r15, %rdx
jne 0x9075
jmp 0x9123
movl %esi, %eax
testl %ebp, %ebp
setne %dl
cmpl %ebp, %eax
setg %sil
testb %sil, %dl
jne 0x920e
movslq (%r12), %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rbx,%rax,4), %rax
movl 0x4(%rax,%rcx,4), %eax
incq %rcx
testl %eax, %eax
jne 0x8ff5
movl 0x4(%r12), %edx
addq $0x4, %r12
testl %edx, %edx
jne 0x8fe1
jmp 0x91fb
movl 0x5ac(%r12), %esi
testl %esi, %esi
je 0x91fb
addq $0x5ac, %r12            # imm = 0x5AC
cmpl %r9d, %esi
je 0x91ea
testq %rdi, %rdi
je 0x9188
movq (%rdi), %rax
callq *(%rax)
movl 0xc(%rsp), %r9d
movq 0x10(%rsp), %rdi
movl (%r12), %esi
movl 0x604(%rsp), %ecx
movl $0x169, %eax            # imm = 0x169
cmpq $0x169, %rcx            # imm = 0x169
je 0x91dc
testl %ecx, %ecx
jle 0x91b1
xorl %eax, %eax
cmpl %esi, 0x60(%rsp,%rax,4)
je 0x91da
incq %rax
cmpq %rax, %rcx
jne 0x91a3
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x604(%rsp)
movl %esi, 0x60(%rsp,%rax,4)
movslq 0x604(%rsp), %rax
movl $0x0, 0x60(%rsp,%rax,4)
movl 0x604(%rsp), %eax
jmp 0x91dc
movl %ecx, %eax
testl %ebp, %ebp
setne %cl
cmpl %ebp, %eax
setg %dl
testb %dl, %cl
jne 0x920e
movl 0x4(%r12), %esi
addq $0x4, %r12
testl %esi, %esi
jne 0x916b
incq %r14
cmpq %r15, %r14
jne 0x8fa3
movl 0x604(%rsp), %eax
addq $0x608, %rsp            # imm = 0x608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq