// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/feature/SimulationFeature.cpp
// Function: CheckCaptureAfterKoForSimulation(game_info_t*, int, int*, int&)
void
CheckCaptureAfterKoForSimulation( game_info_t *game, const int color, int update[], int &update_num )
{
  const string_t *string = game->string;
  const char *board = game->board;
  const int *string_id = game->string_id;
  const int other = GetOppositeColor(color);
  const int previous_move_2 = game->record[game->moves - 2].pos;
  int checked = 0;
  int check[4] = { 0 };

  //  上
  if (board[NORTH(previous_move_2)] == other) {
    const int id = string_id[NORTH(previous_move_2)];
    if (string[id].libs == 1) {
      const int lib = string[id].lib[0];
      update[update_num++] = lib;
      CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_CAPTURE_AFTER_KO);
    }
    check[checked++] = id;
  }

  //  右
  if (board[EAST(previous_move_2)] == other) {
    const int id = string_id[EAST(previous_move_2)];
    if (string[id].libs == 1 && check[0] != id) {
      const int lib = string[id].lib[0];
      update[update_num++] = lib;
      CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_CAPTURE_AFTER_KO);
    }
    check[checked++] = id;
  }

  //  下
  if (board[SOUTH(previous_move_2)] == other) {
    const int id = string_id[SOUTH(previous_move_2)];
    if (string[id].libs == 1 && check[0] != id && check[1] != id) {
      const int lib = string[id].lib[0];
      update[update_num++] = lib;
      CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_CAPTURE_AFTER_KO);
    }
    check[checked++] = id;
  }

  //  左
  if (board[WEST(previous_move_2)] == other) {
    const int id = string_id[WEST(previous_move_2)];
    if (string[id].libs == 1 && check[0] != id && check[1] != id && check[2] != id) {
      const int lib = string[id].lib[0];
      update[update_num++] = lib;
      CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_CAPTURE_AFTER_KO);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
leaq 0x9620(%rdi), %rax
xorl $0x3, %esi
movslq 0x43b0(%rdi), %r8
shlq $0x4, %r8
movslq -0x1c(%r8,%rdi), %r8
xorps %xmm0, %xmm0
movaps %xmm0, -0x10(%rsp)
leaq 0x22e07(%rip), %r10     # 0x618bc
movslq (%r10), %r9
movq %r8, %rbx
subq %r9, %rbx
movsbl 0x43f8(%rdi,%rbx), %ebp
xorl %r11d, %r11d
movl $0x0, %r9d
cmpl %ebp, %esi
jne 0x3eb24
movslq 0x95720(%rdi,%rbx,4), %r11
imulq $0x7c8, %r11, %r9       # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%r9)
jne 0x3eb19
addq %rax, %r9
movswl 0x8(%r9), %r9d
movslq %r9d, %r9
movslq (%rcx), %rbx
leal 0x1(%rbx), %ebp
movl %ebp, (%rcx)
movl %r9d, (%rdx,%rbx,4)
imulq $0x6, %r9, %r9
cmpb $0x8, 0x97372(%rdi,%r9)
ja 0x3eb19
movb $0x9, 0x97372(%rdi,%r9)
movl %r11d, -0x10(%rsp)
movl $0x1, %r9d
movsbl 0x43f9(%rdi,%r8), %ebx
cmpl %ebx, %esi
jne 0x3eb88
movslq 0x95724(%rdi,%r8,4), %rbx
imulq $0x7c8, %rbx, %r14      # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%r14)
jne 0x3eb7d
cmpl %ebx, %r11d
je 0x3eb7d
addq %rax, %r14
movswl 0x8(%r14), %r11d
movslq %r11d, %r11
movslq (%rcx), %r14
leal 0x1(%r14), %ebp
movl %ebp, (%rcx)
movl %r11d, (%rdx,%r14,4)
imulq $0x6, %r11, %r11
cmpb $0x8, 0x97372(%rdi,%r11)
ja 0x3eb7d
movb $0x9, 0x97372(%rdi,%r11)
movl %r9d, %r11d
incl %r9d
movl %ebx, -0x10(%rsp,%r11,4)
movslq (%r10), %r10
addq %r8, %r10
movsbl 0x43f8(%rdi,%r10), %r11d
cmpl %r11d, %esi
jne 0x3ebf8
movslq 0x95720(%rdi,%r10,4), %r10
imulq $0x7c8, %r10, %r11      # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%r11)
jne 0x3ebf0
cmpl %r10d, -0x10(%rsp)
je 0x3ebf0
cmpl %r10d, -0xc(%rsp)
je 0x3ebf0
addq %rax, %r11
movswl 0x8(%r11), %r11d
movslq %r11d, %r11
movslq (%rcx), %rbx
leal 0x1(%rbx), %ebp
movl %ebp, (%rcx)
movl %r11d, (%rdx,%rbx,4)
imulq $0x6, %r11, %r11
cmpb $0x8, 0x97372(%rdi,%r11)
ja 0x3ebf0
movb $0x9, 0x97372(%rdi,%r11)
movl %r9d, %r9d
movl %r10d, -0x10(%rsp,%r9,4)
movsbl 0x43f7(%rdi,%r8), %r9d
cmpl %r9d, %esi
jne 0x3ec5d
movslq 0x9571c(%rdi,%r8,4), %r8
imulq $0x7c8, %r8, %rsi       # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%rsi)
jne 0x3ec5d
cmpl %r8d, -0x10(%rsp)
je 0x3ec5d
cmpl %r8d, -0xc(%rsp)
je 0x3ec5d
cmpl %r8d, -0x8(%rsp)
je 0x3ec5d
addq %rsi, %rax
movswl 0x8(%rax), %eax
cltq
movslq (%rcx), %rsi
leal 0x1(%rsi), %r8d
movl %r8d, (%rcx)
movl %eax, (%rdx,%rsi,4)
imulq $0x6, %rax, %rax
cmpb $0x8, 0x97372(%rdi,%rax)
ja 0x3ec5d
movb $0x9, 0x97372(%rdi,%rax)
popq %rbx
popq %r14
popq %rbp
retq