// File: kobanium[P]Ray/src/feature/UctFeature.cpp
// Function: CheckCaptureForTree(game_info_t const*, int, int, unsigned int*)
void
CheckCaptureForTree( const game_info_t *game, const int color, const int pos, unsigned int *tactical_features )
{
  const char *board = game->board;
  const int other = GetOppositeColor(color);
  const string_t *string = game->string;
  const int *string_id = game->string_id;
  int neighbor, id;
  int neighbor4[4];
  bool check;

  GetNeighbor4(neighbor4, pos);

  for (int i = 0; i < 4; i++) {
    if (board[neighbor4[i]] == other) {
      if (string[string_id[neighbor4[i]]].libs == 1) {
        check = false;
        id = string_id[neighbor4[i]];
        neighbor = string[id].neighbor[0];
        while (neighbor != NEIGHBOR_END) {
          if (string[neighbor].libs == 1) {
            check = true;
            break;
          }
          neighbor = string[id].neighbor[neighbor];
        }
        if (check) {
          CompareSwapFeature(tactical_features, pos, UCT_CAPTURE_INDEX, UCT_SEMEAI_CAPTURE);
          return;
        } else {
          CompareSwapFeature(tactical_features, pos, UCT_CAPTURE_INDEX, UCT_CAPTURE);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %edi
callq 0x25810
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x9bc90
movl $0x0, -0x58(%rbp)
cmpl $0x4, -0x58(%rbp)
jge 0xa79da
movq -0x20(%rbp), %rax
movslq -0x58(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x24(%rbp), %eax
jne 0xa79ca
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq -0x58(%rbp), %rdx
movslq -0x50(%rbp,%rdx,4), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa79c8
movb $0x0, -0x51(%rbp)
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x11f, -0x3c(%rbp)     # imm = 0x11F
je 0xa7998
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa7975
movb $0x1, -0x51(%rbp)
jmp 0xa7998
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x3c(%rbp)
jmp 0xa794e
testb $0x1, -0x51(%rbp)
je 0xa79b3
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x5, %ecx
callq 0xa7430
jmp 0xa79da
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0xa7430
jmp 0xa79c8
jmp 0xa79ca
jmp 0xa79cc
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xa78ce
addq $0x60, %rsp
popq %rbp
retq