// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %edi
callq 0x25810
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x72b0
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x454e7(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa2609
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x454c7(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa25f5
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x68(%rbp), %esi
xorl %edx, %edx
movl $0x9, %ecx
callq 0xa35f0
movl -0x64(%rbp), %ecx
movl -0x44(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x44(%rbp)
cltq
movl %ecx, -0x60(%rbp,%rax,4)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa26b7
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x6c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa26a3
movl -0x60(%rbp), %eax
cmpl -0x6c(%rbp), %eax
je 0xa26a3
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x70(%rbp), %esi
xorl %edx, %edx
movl $0x9, %ecx
callq 0xa35f0
movl -0x6c(%rbp), %ecx
movl -0x44(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x44(%rbp)
cltq
movl %ecx, -0x60(%rbp,%rax,4)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x45387(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa2779
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x45367(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa2765
movl -0x60(%rbp), %eax
cmpl -0x74(%rbp), %eax
je 0xa2765
movl -0x5c(%rbp), %eax
cmpl -0x74(%rbp), %eax
je 0xa2765
movq -0x28(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x78(%rbp), %esi
xorl %edx, %edx
movl $0x9, %ecx
callq 0xa35f0
movl -0x74(%rbp), %ecx
movl -0x44(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x44(%rbp)
cltq
movl %ecx, -0x60(%rbp,%rax,4)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa2825
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa2823
movl -0x60(%rbp), %eax
cmpl -0x7c(%rbp), %eax
je 0xa2823
movl -0x5c(%rbp), %eax
cmpl -0x7c(%rbp), %eax
je 0xa2823
movl -0x58(%rbp), %eax
cmpl -0x7c(%rbp), %eax
je 0xa2823
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x80(%rbp), %esi
xorl %edx, %edx
movl $0x9, %ecx
callq 0xa35f0
jmp 0xa2825
addq $0x80, %rsp
popq %rbp
retq
nop