// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x8(%rsp)
movq %rdi, %r15
movl %esi, 0x14(%rsp)
xorl $0x3, %esi
movslq %edx, %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
leaq (%rdi,%rax), %rbp
addq $0x9620, %rbp           # imm = 0x9620
movswl 0x8(%rbp), %edx
movslq %edx, %r9
leaq 0x23e1b(%rip), %rcx     # 0x618bc
movl (%rcx), %r11d
movq %rdx, 0x20(%rsp)
leal (%r11,%rdx), %ecx
movslq %ecx, %rcx
movsbl 0x43f8(%rdi,%rcx), %r10d
imulq $0x6, %r9, %rcx
movl 0x7c0(%rbp), %edi
movb 0x97373(%r15,%rcx), %dl
cmpl %r10d, %esi
je 0x3db22
movsbl 0x43f7(%r15,%r9), %r10d
cmpl %r10d, %esi
je 0x3db22
movsbl 0x43f9(%r15,%r9), %r9d
cmpl %r9d, %esi
je 0x3db22
movq 0x20(%rsp), %r9
subl %r11d, %r9d
movslq %r9d, %r9
movsbl 0x43f8(%r15,%r9), %r9d
cmpl %r9d, %esi
je 0x3db22
cmpl $0x2, %edi
je 0x3db46
cmpl $0x1, %edi
movq 0x8(%rsp), %r9
jne 0x3de0b
movb $0x4, %sil
cmpb $0x4, %dl
jb 0x3db53
jmp 0x3db5e
cmpl $0x2, %edi
je 0x3db3e
cmpl $0x1, %edi
movq 0x8(%rsp), %r9
jne 0x3ddfa
testb %dl, %dl
jne 0x3db5e
movb $0x1, %sil
jmp 0x3db53
movb $0x2, %sil
cmpb $0x2, %dl
jmp 0x3db4c
movb $0x5, %sil
cmpb $0x5, %dl
movq 0x8(%rsp), %r9
jae 0x3db5e
incq %rcx
movb %sil, 0x97372(%r15,%rcx)
leaq 0x9620(%r15), %r12
movswl 0x9b9c(%r15,%rax), %eax
movslq (%r8), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%r8)
movq 0x20(%rsp), %rdx
movl %edx, (%r9,%rcx,4)
movl 0x7c0(%rbp), %ecx
cmpl $0x1, %ecx
je 0x3dde4
cmpl $0x2, %ecx
movq %r8, 0x18(%rsp)
je 0x3dd62
setg %cl
cmpw $0x11f, %ax             # imm = 0x11F
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3ddeb
movslq %eax, %r14
imulq $0x7c8, %r14, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x3dc79
addq %r12, %rax
movswl 0x8(%rax), %ebx
movslq %ebx, %r13
movl 0x7c0(%rax), %eax
cmpl $0x2, %eax
je 0x3dc20
cmpl $0x1, %eax
jne 0x3dc3a
movq %r15, %rdi
movl %r13d, %esi
movl 0x14(%rsp), %edx
movq 0x20(%rsp), %rcx
callq 0x42088
imulq $0x6, %r13, %rcx
movb 0x97372(%r15,%rcx), %dl
testb %al, %al
je 0x3dc54
cmpb $0x9, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x3dc6c
movb $0xa, 0x97372(%r15,%rcx)
jmp 0x3dc6c
imulq $0x6, %r13, %rax
cmpb $0x11, 0x97372(%r15,%rax)
ja 0x3dc6c
movb $0x12, 0x97372(%r15,%rax)
jmp 0x3dc6c
imulq $0x6, %r13, %rax
cmpb $0x12, 0x97372(%r15,%rax)
ja 0x3dc6c
movb $0x13, 0x97372(%r15,%rax)
jmp 0x3dc6c
cmpb $0x10, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x3dc6c
movb $0x11, 0x97372(%r15,%rcx)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl %ebx, (%r9,%rax,4)
movswl 0x57c(%rbp,%r14,2), %eax
cmpl $0x11f, %eax            # imm = 0x11F
jne 0x3dbb2
jmp 0x3ddeb
movslq %eax, %r14
imulq $0x7c8, %r14, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x3dd59
addq %r12, %rax
movswl 0x8(%rax), %ebx
movslq %ebx, %r13
movl 0x7c0(%rax), %eax
cmpl $0x2, %eax
je 0x3dd00
cmpl $0x1, %eax
jne 0x3dd1a
movq %r15, %rdi
movl %r13d, %esi
movl 0x14(%rsp), %edx
movq 0x20(%rsp), %rcx
callq 0x42088
imulq $0x6, %r13, %rcx
movb 0x97372(%r15,%rcx), %dl
testb %al, %al
je 0x3dd34
cmpb $0x9, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x3dd4c
movb $0xa, 0x97372(%r15,%rcx)
jmp 0x3dd4c
imulq $0x6, %r13, %rax
cmpb $0xe, 0x97372(%r15,%rax)
ja 0x3dd4c
movb $0xf, 0x97372(%r15,%rax)
jmp 0x3dd4c
imulq $0x6, %r13, %rax
cmpb $0xf, 0x97372(%r15,%rax)
ja 0x3dd4c
movb $0x10, 0x97372(%r15,%rax)
jmp 0x3dd4c
cmpb $0xd, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x3dd4c
movb $0xe, 0x97372(%r15,%rcx)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl %ebx, (%r9,%rax,4)
movswl 0x57c(%rbp,%r14,2), %eax
cmpl $0x11f, %eax            # imm = 0x11F
jne 0x3dc92
jmp 0x3ddeb
cltq
imulq $0x7c8, %rax, %rdx      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rdx)
jne 0x3ddc4
addq %r12, %rdx
movswl 0x8(%rdx), %ecx
movslq %ecx, %rdi
movl 0x7c0(%rdx), %esi
imulq $0x6, %rdi, %rdx
movb 0x97372(%r15,%rdx), %dil
cmpl $0x2, %esi
je 0x3ddce
cmpl $0x1, %esi
jne 0x3ddd9
movb $0xb, %sil
cmpb $0xb, %dil
jae 0x3ddb7
movb %sil, 0x97372(%r15,%rdx)
movslq (%r8), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%r8)
movl %ecx, (%r9,%rdx,4)
movswl 0x57c(%rbp,%rax,2), %eax
jmp 0x3dde4
movb $0xc, %sil
cmpb $0xc, %dil
jb 0x3ddaf
jmp 0x3ddb7
movb $0xd, %sil
cmpb $0xc, %dil
jbe 0x3ddaf
jmp 0x3ddb7
cmpl $0x11f, %eax            # imm = 0x11F
jne 0x3dd6f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x3, %sil
cmpb $0x3, %dl
jb 0x3db53
jmp 0x3db5e
movb $0x6, %sil
cmpb $0x5, %dl
jbe 0x3db53
jmp 0x3db5e