// File: /workspace/github_cpp_makefile_star2_O2/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 $0x628, %rsp            # imm = 0x628
movq %r9, %r12
movl %r8d, (%rsp)
movq %rcx, %r13
movl %edx, 0x4(%rsp)
andl $0x0, 0x624(%rsp)
movl %esi, %r15d
andl $0x0, 0x80(%rsp)
movq %rdi, %r14
leaq 0x6980(%rip), %rax      # 0xecf8
movq %rax, 0x78(%rsp)
testq %rcx, %rcx
je 0x8390
movq %r14, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x500a
leaq 0x78(%rsp), %rbx
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x500a
movl (%rsp), %edx
testl %edx, %edx
setne %cl
movl 0x5ac(%rbx), %eax
cmpl %edx, %eax
setg %dl
testb %dl, %cl
je 0x83cc
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rdx
andl $0x0, 0x30(%rdx)
andq $0x0, (%rdx)
movq %r14, %rdi
movl %r15d, %esi
callq 0x4fc8
movq %r14, 0x8(%rsp)
leaq 0xd63e8(%r14), %rcx
movq %rcx, 0x18(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movq %rdx, 0x28(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
cmpq 0x28(%rsp), %rcx
je 0x859d
movq %rcx, 0x30(%rsp)
movq 0x40(%rsp,%rcx,8), %r14
cmpq %r12, %r14
je 0x8590
movl 0x4(%rsp), %eax
cmpb %al, (%r14)
je 0x8540
cmpl $0x1, 0x96c(%r14)
jne 0x8590
movq %r12, 0x20(%rsp)
movl 0x4(%r14), %esi
testl %esi, %esi
je 0x8590
addq $0x4, %r14
xorl %edx, %edx
movq 0x8(%rsp), %r12
movslq %esi, %rax
imulq $0x14, %rax, %rax
addq 0x18(%rsp), %rax
movslq (%rax,%rdx,4), %rax
testq %rax, %rax
je 0x8536
cmpl %r15d, %eax
movq %rdx, 0x10(%rsp)
jne 0x84b1
movl (%rsp), %ebp
testl %ebp, %ebp
setne %bl
leaq 0x78(%rsp), %rdi
callq 0x87ac
movq 0x10(%rsp), %rdx
movl 0x624(%rsp), %eax
cmpl %ebp, %eax
setg %cl
testb %cl, %bl
je 0x84c3
jmp 0x83ba
movq 0x18(%r12,%rax,8), %rax
testq %rax, %rax
je 0x84c3
movl 0x4(%rsp), %ecx
cmpb %cl, (%rax)
je 0x84cb
incq %rdx
movl (%r14), %esi
jmp 0x8462
xorl %ebx, %ebx
cmpq %rbx, 0x38(%rsp)
je 0x84c3
movslq (%r14), %rsi
imulq $0x14, %rsi, %rax
addq 0x18(%rsp), %rax
movslq (%rax,%rdx,4), %rax
movq 0x18(%r12,%rax,8), %rax
cmpq 0x40(%rsp,%rbx,8), %rax
jne 0x8531
movl (%rsp), %r12d
testl %r12d, %r12d
movl %r15d, %ebp
movq %r13, %r15
setne %r13b
leaq 0x78(%rsp), %rdi
callq 0x87ac
movq 0x10(%rsp), %rdx
movl 0x624(%rsp), %eax
cmpl %r12d, %eax
movq 0x8(%rsp), %r12
setg %cl
testb %cl, %r13b
movq %r15, %r13
movl %ebp, %r15d
jne 0x83ba
incq %rbx
jmp 0x84cd
movq 0x20(%rsp), %r12
jmp 0x844b
addq $0x5ac, %r14            # imm = 0x5AC
movl (%r14), %esi
testl %esi, %esi
je 0x8590
cmpl %r15d, %esi
je 0x858a
testq %r13, %r13
je 0x8564
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
movl (%r14), %esi
movl (%rsp), %ebp
testl %ebp, %ebp
setne %bl
leaq 0x78(%rsp), %rdi
callq 0x87ac
movl 0x624(%rsp), %eax
cmpl %ebp, %eax
setg %cl
testb %cl, %bl
jne 0x83ba
addq $0x4, %r14
jmp 0x8547
movq 0x30(%rsp), %rcx
incq %rcx
jmp 0x840d
movl 0x624(%rsp), %eax
jmp 0x83ba
nop