// File: kobanium[P]Ray/src/feature/SimulationFeature.cpp
// Function: CheckFeatureLib1ForSimulation(game_info_t*, int, int, int*, int&)
static void
CheckFeatureLib1ForSimulation( game_info_t *game, const int color, const int id, int update[], int &update_num )
{
  const int other = GetOppositeColor(color);
  const char *board = game->board;
  const string_t *string = game->string;
  int neighbor = string[id].neighbor[0];
  int lib, liberty;
  bool contact = false;

  // 呼吸点が1つになった連の呼吸点を取り出す
  lib = string[id].lib[0];
  liberty = lib;

  // 呼吸点の上下左右が敵石に接触しているか確認
  if (board[NORTH(lib)] == other) contact = true;
  if (board[ EAST(lib)] == other) contact = true;
  if (board[ WEST(lib)] == other) contact = true;
  if (board[SOUTH(lib)] == other) contact = true;

  // 呼吸点の上下左右が敵連に接しているか
  // また逃げ出す連の大きさで特徴を判定
  if (contact) {
    if (string[id].size == 1) {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_1);
    } else if (string[id].size == 2) {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_2);
    } else {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_3);
    }
  } else {
    if (string[id].size == 1) {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_SAFELY_1);
    } else if (string[id].size == 2) {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_SAFELY_2);
    } else {
      CompareSwapFeature(game->tactical_features, lib, SAVE_EXTENSION, SIM_SAVE_EXTENSION_SAFELY_3);
    }
  }

  // レートの更新対象に入れる
  update[update_num++] = lib;

  // 敵連を取ることによって連を助ける手の特徴の判定
  // 自分の連の大きさと敵の連の大きさで特徴を判定
  if (string[id].size == 1) {
    while (neighbor != NEIGHBOR_END) {
      if (string[neighbor].libs == 1) {
        lib = string[neighbor].lib[0];
        if (string[neighbor].size == 1) {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_1_1);
        } else if (string[neighbor].size == 2) {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_1_2);
        } else {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_1_3);
        }
        update[update_num++] = lib;
      }
      neighbor = string[id].neighbor[neighbor];
    }
  } else if (string[id].size == 2) {
    while (neighbor != NEIGHBOR_END) {
      if (string[neighbor].libs == 1) {
        lib = string[neighbor].lib[0];
        if (string[neighbor].size == 1) {
          if (IsSelfAtariCaptureForSimulation(game, lib, color, liberty)) {
            CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_SELF_ATARI);
          } else {
            CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_2_1);
          }
        } else if (string[neighbor].size == 2) {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_2_2);
        } else {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_2_3);
        }
        update[update_num++] = lib;
      }
      neighbor = string[id].neighbor[neighbor];
    }
  } else if (string[id].size >= 3) {
    while (neighbor != NEIGHBOR_END) {
      if (string[neighbor].libs == 1) {
        lib = string[neighbor].lib[0];
        if (string[neighbor].size == 1) {
          if (IsSelfAtariCaptureForSimulation(game, lib, color, liberty)) {
            CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_SELF_ATARI);
          } else {
            CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_3_1);
          }
        } else if (string[neighbor].size == 2) {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_3_2);
        } else {
          CompareSwapFeature(game->tactical_features, lib, CAPTURE, SIM_SAVE_CAPTURE_3_3);
        }
        update[update_num++] = lib;
      }
      neighbor = string[id].neighbor[neighbor];
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl -0xc(%rbp), %edi
callq 0x25810
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x3c(%rbp)
movb $0x0, -0x45(%rbp)
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x46d4e(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x24(%rbp), %eax
jne 0xa0d10
movb $0x1, -0x45(%rbp)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x24(%rbp), %eax
jne 0xa0d2a
movb $0x1, -0x45(%rbp)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x24(%rbp), %eax
jne 0xa0d44
movb $0x1, -0x45(%rbp)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x46cfa(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x24(%rbp), %eax
jne 0xa0d64
movb $0x1, -0x45(%rbp)
testb $0x1, -0x45(%rbp)
je 0xa0e03
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa0da5
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %ecx
movl %ecx, %edx
callq 0xa35f0
jmp 0xa0dfe
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa0ddf
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %edx
movl $0x2, %ecx
callq 0xa35f0
jmp 0xa0dfc
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %edx
movl $0x3, %ecx
callq 0xa35f0
jmp 0xa0dfe
jmp 0xa0e98
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa0e3d
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %edx
movl $0x4, %ecx
callq 0xa35f0
jmp 0xa0e96
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa0e77
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %edx
movl $0x5, %ecx
callq 0xa35f0
jmp 0xa0e94
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
movl $0x1, %edx
movl $0x6, %ecx
callq 0xa35f0
jmp 0xa0e96
jmp 0xa0e98
movl -0x40(%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 -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa0fe4
jmp 0xa0ed3
cmpl $0x11f, -0x3c(%rbp)     # imm = 0x11F
je 0xa0fdf
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa0fb9
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa0f4c
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xb, %ecx
callq 0xa35f0
jmp 0xa0f9f
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa0f83
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xc, %ecx
callq 0xa35f0
jmp 0xa0f9d
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xd, %ecx
callq 0xa35f0
jmp 0xa0f9f
movl -0x40(%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 -0x38(%rbp), %rax
movslq -0x10(%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 0xa0ed3
jmp 0xa12b1
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa114a
jmp 0xa1005
cmpl $0x11f, -0x3c(%rbp)     # imm = 0x11F
je 0xa1145
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa111f
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa10b2
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0xc(%rbp), %edx
movl -0x44(%rbp), %ecx
callq 0xa8b10
testb $0x1, %al
jne 0xa107a
jmp 0xa1096
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xa, %ecx
callq 0xa35f0
jmp 0xa10b0
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xe, %ecx
callq 0xa35f0
jmp 0xa1105
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa10e9
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xf, %ecx
callq 0xa35f0
jmp 0xa1103
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0x10, %ecx
callq 0xa35f0
jmp 0xa1105
movl -0x40(%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 -0x38(%rbp), %rax
movslq -0x10(%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 0xa1005
jmp 0xa12af
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x3, 0x7c0(%rax)
jl 0xa12ad
jmp 0xa116b
cmpl $0x11f, -0x3c(%rbp)     # imm = 0x11F
je 0xa12ab
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa1285
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x7c0(%rax)
jne 0xa1218
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0xc(%rbp), %edx
movl -0x44(%rbp), %ecx
callq 0xa8b10
testb $0x1, %al
jne 0xa11e0
jmp 0xa11fc
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0xa, %ecx
callq 0xa35f0
jmp 0xa1216
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0x11, %ecx
callq 0xa35f0
jmp 0xa126b
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x7c0(%rax)
jne 0xa124f
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0x12, %ecx
callq 0xa35f0
jmp 0xa1269
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x40(%rbp), %esi
xorl %edx, %edx
movl $0x13, %ecx
callq 0xa35f0
jmp 0xa126b
movl -0x40(%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 -0x38(%rbp), %rax
movslq -0x10(%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 0xa116b
jmp 0xa12ad
jmp 0xa12af
jmp 0xa12b1
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)