// File: /workspace/github_cpp_makefile_star2_O1/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 $0x638, %rsp            # imm = 0x638
movq %r9, 0x38(%rsp)
movl %r8d, (%rsp)
movq %rcx, %r14
movl %edx, %r13d
movl %esi, %ebp
movq %rdi, %r15
xorl %eax, %eax
movl %eax, 0x634(%rsp)
movl %eax, 0x90(%rsp)
leaq 0x6c3c(%rip), %rax      # 0xfd20
movq %rax, 0x88(%rsp)
testq %rcx, %rcx
je 0x90fe
movq %r15, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x525c
leaq 0x88(%rsp), %rbx
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x525c
movl (%rsp), %ecx
testl %ecx, %ecx
setne %al
movl 0x5ac(%rbx), %edx
cmpl %ecx, %edx
setg %cl
testb %cl, %al
movl %edx, %eax
jne 0x93f3
leaq 0x50(%rsp), %rdx
movl $0x0, 0x30(%rdx)
movq $0x0, (%rdx)
movq %r15, %rdi
movl %ebp, %esi
callq 0x5210
testl %eax, %eax
jle 0x93e6
movl %ebp, %ecx
movq %r15, 0x30(%rsp)
leaq 0xd63e8(%r15), %rdx
movl %eax, %eax
movq %rax, 0x18(%rsp)
negq %rax
movq %rax, 0x48(%rsp)
xorl %esi, %esi
movl %ebp, 0x8(%rsp)
movq %rdx, 0x20(%rsp)
movq %r14, 0x40(%rsp)
movl %r13d, 0x2c(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x50(%rsp,%rsi,8), %r12
cmpq 0x38(%rsp), %r12
je 0x930b
cmpb %r13b, (%r12)
je 0x9315
cmpl $0x1, 0x96c(%r12)
jne 0x930b
movq 0x30(%rsp), %r14
cmpl $0x0, 0x4(%r12)
je 0x9393
addq $0x4, %r12
movslq (%r12), %rsi
leaq (%rsi,%rsi,4), %rax
movl (%rdx,%rax,4), %eax
testl %eax, %eax
je 0x92ed
xorl %ebp, %ebp
cmpl %ecx, %eax
jne 0x921d
movl (%rsp), %r15d
testl %r15d, %r15d
setne %bl
leaq 0x88(%rsp), %rdi
callq 0x9676
movq 0x20(%rsp), %rdx
movl 0x634(%rsp), %eax
cmpl %r15d, %eax
setg %cl
testb %cl, %bl
movl 0x8(%rsp), %ecx
je 0x92d2
jmp 0x92f4
cltq
movq 0x18(%r14,%rax,8), %rax
testq %rax, %rax
je 0x92d2
cmpb %r13b, (%rax)
jne 0x92d2
movb $0x1, %r13b
movl $0x1, %ebx
movq 0x18(%rsp), %rcx
movslq (%r12), %rsi
leaq (%rsi,%rsi,4), %rax
leaq (%rdx,%rax,4), %rax
movslq (%rax,%rbp,4), %rax
movq 0x18(%r14,%rax,8), %rax
cmpq 0x48(%rsp,%rbx,8), %rax
jne 0x9298
movl (%rsp), %r14d
testl %r14d, %r14d
setne %r15b
leaq 0x88(%rsp), %rdi
callq 0x9676
movq 0x20(%rsp), %rdx
movl 0x634(%rsp), %eax
cmpl %r14d, %eax
movq 0x30(%rsp), %r14
setg %cl
testb %cl, %r15b
movq 0x18(%rsp), %rcx
jne 0x92ba
cmpq %rcx, %rbx
setb %r13b
movq 0x48(%rsp), %rax
addq %rbx, %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
jne 0x9243
movl $0xe, %esi
jmp 0x92c3
movl $0x1, %esi
movl %eax, 0x4(%rsp)
testb $0x1, %r13b
movl 0x2c(%rsp), %r13d
movl 0x8(%rsp), %ecx
jne 0x92fd
movslq (%r12), %rsi
leaq (%rsi,%rsi,4), %rax
leaq (%rdx,%rax,4), %rax
movl 0x4(%rax,%rbp,4), %eax
incq %rbp
testl %eax, %eax
jne 0x91df
movl $0xb, %esi
jmp 0x92fd
movl $0x1, %esi
movl %eax, 0x4(%rsp)
cmpl $0xb, %esi
je 0x91ba
jmp 0x9398
movq 0x10(%rsp), %rsi
jmp 0x93c1
movl 0x5ac(%r12), %esi
movl $0x5, 0xc(%rsp)
testl %esi, %esi
sete %bpl
je 0x93b2
addq $0x5b0, %r12            # imm = 0x5B0
cmpl %ecx, %esi
je 0x9381
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x934b
movq (%rdi), %rax
callq *(%rax)
movl (%rsp), %r15d
testl %r15d, %r15d
setne %bl
movl -0x4(%r12), %esi
leaq 0x88(%rsp), %rdi
callq 0x9676
movl 0x634(%rsp), %eax
cmpl %r15d, %eax
setg %cl
testb %cl, %bl
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rdx
jne 0x93a6
movl (%r12), %esi
addq $0x4, %r12
testl %esi, %esi
sete %bpl
jne 0x9338
jmp 0x93b2
movl $0x8, %esi
cmpl $0x8, %esi
movl %esi, %eax
movq 0x10(%rsp), %rsi
je 0x93c1
jmp 0x93c3
movl $0x1, 0xc(%rsp)
movl %eax, 0x4(%rsp)
testb $0x1, %bpl
movq 0x10(%rsp), %rsi
movl 0xc(%rsp), %eax
je 0x93c3
xorl %eax, %eax
testl %eax, %eax
jne 0x93da
incq %rsi
cmpq 0x18(%rsp), %rsi
jne 0x9187
movl $0x2, %eax
cmpl $0x2, %eax
sete %cl
movl 0x4(%rsp), %eax
jmp 0x93e8
movb $0x1, %cl
testb %cl, %cl
je 0x93f3
movl 0x634(%rsp), %eax
addq $0x638, %rsp            # imm = 0x638
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop