// File: /workspace/github_cpp_makefile_star2_O1/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 0x1dc54(%rip), %r10     # 0x758bc
movslq (%r10), %r9
movq %r8, %r11
subq %r9, %r11
movsbl 0x43f8(%rdi,%r11), %ebx
xorl %r9d, %r9d
cmpl %ebx, %esi
jne 0x57cd5
movslq 0x95720(%rdi,%r11,4), %r9
imulq $0x7c8, %r9, %r11       # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%r11)
jne 0x57cca
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)
addq %r11, %r11
leaq (%r11,%r11,2), %r11
cmpb $0x8, 0x97372(%rdi,%r11)
ja 0x57cca
movb $0x9, 0x97372(%rdi,%r11)
movl %r9d, -0x10(%rsp)
movl $0x1, %r9d
movsbl 0x43f9(%rdi,%r8), %r11d
cmpl %r11d, %esi
jne 0x57d3b
movslq 0x95724(%rdi,%r8,4), %r11
imulq $0x7c8, %r11, %rbx      # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%rbx)
jne 0x57d30
cmpl %r11d, -0x10(%rsp)
je 0x57d30
addq %rax, %rbx
movswl 0x8(%rbx), %ebx
movslq %ebx, %rbx
movslq (%rcx), %r14
leal 0x1(%r14), %ebp
movl %ebp, (%rcx)
movl %ebx, (%rdx,%r14,4)
addq %rbx, %rbx
leaq (%rbx,%rbx,2), %rbx
cmpb $0x8, 0x97372(%rdi,%rbx)
ja 0x57d30
movb $0x9, 0x97372(%rdi,%rbx)
movl %r9d, %ebx
incl %r9d
movl %r11d, -0x10(%rsp,%rbx,4)
movslq (%r10), %r10
addq %r8, %r10
movsbl 0x43f8(%rdi,%r10), %r11d
cmpl %r11d, %esi
jne 0x57dae
movslq 0x95720(%rdi,%r10,4), %r10
imulq $0x7c8, %r10, %r11      # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%r11)
jne 0x57da6
cmpl %r10d, -0x10(%rsp)
je 0x57da6
cmpl %r10d, -0xc(%rsp)
je 0x57da6
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)
addq %r11, %r11
leaq (%r11,%r11,2), %r11
cmpb $0x8, 0x97372(%rdi,%r11)
ja 0x57da6
movb $0x9, 0x97372(%rdi,%r11)
movl %r9d, %r9d
movl %r10d, -0x10(%rsp,%r9,4)
movsbl 0x43f7(%rdi,%r8), %r9d
cmpl %r9d, %esi
jne 0x57e16
movslq 0x9571c(%rdi,%r8,4), %r8
imulq $0x7c8, %r8, %rsi       # imm = 0x7C8
cmpl $0x1, 0x4(%rax,%rsi)
jne 0x57e16
cmpl %r8d, -0x10(%rsp)
je 0x57e16
cmpl %r8d, -0xc(%rsp)
je 0x57e16
cmpl %r8d, -0x8(%rsp)
je 0x57e16
addq %rsi, %rax
movswl 0x8(%rax), %eax
cltq
movslq (%rcx), %rsi
leal 0x1(%rsi), %r8d
movl %r8d, (%rcx)
movl %eax, (%rdx,%rsi,4)
addq %rax, %rax
leaq (%rax,%rax,2), %rax
cmpb $0x8, 0x97372(%rdi,%rax)
ja 0x57e16
movb $0x9, 0x97372(%rdi,%rax)
popq %rbx
popq %r14
popq %rbp
retq