// File: /workspace/github_cpp_makefile_star2_O3/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), %ebx
movslq %ebx, %r9
leaq 0x1f411(%rip), %rcx     # 0x768bc
movl (%rcx), %r11d
leal (%r11,%rbx), %ecx
movslq %ecx, %rcx
movsbl 0x43f8(%rdi,%rcx), %r10d
leaq (%r9,%r9), %rcx
leaq (%rcx,%rcx,2), %rdx
movb 0x97373(%rdi,%rdx), %dl
movl 0x7c0(%rbp), %edi
cmpl %r10d, %esi
je 0x57528
movsbl 0x43f7(%r15,%r9), %r10d
cmpl %r10d, %esi
je 0x57528
movsbl 0x43f9(%r15,%r9), %r9d
cmpl %r9d, %esi
je 0x57528
movl %ebx, %r9d
subl %r11d, %r9d
movslq %r9d, %r9
movsbl 0x43f8(%r15,%r9), %r9d
cmpl %r9d, %esi
je 0x57528
cmpl $0x2, %edi
je 0x5754c
cmpl $0x1, %edi
movq 0x8(%rsp), %r9
jne 0x5785c
movb $0x4, %sil
cmpb $0x4, %dl
jb 0x57559
jmp 0x57568
cmpl $0x2, %edi
je 0x57544
cmpl $0x1, %edi
movq 0x8(%rsp), %r9
jne 0x5784b
testb %dl, %dl
jne 0x57568
movb $0x1, %sil
jmp 0x57559
movb $0x2, %sil
cmpb $0x2, %dl
jmp 0x57552
movb $0x5, %sil
cmpb $0x5, %dl
movq 0x8(%rsp), %r9
jae 0x57568
leaq (%rcx,%rcx,2), %rcx
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)
movl %ebx, (%r9,%rcx,4)
movl 0x7c0(%rbp), %ecx
cmpl $0x1, %ecx
je 0x5771d
movq %rbx, 0x20(%rsp)
cmpl $0x2, %ecx
movq %r8, 0x18(%rsp)
jne 0x57729
cmpl $0x11f, %eax            # imm = 0x11F
je 0x5783c
movslq %eax, %r14
imulq $0x7c8, %r14, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x57697
addq %r12, %rax
movswl 0x8(%rax), %ebx
movslq %ebx, %r13
movl 0x7c0(%rax), %eax
cmpl $0x2, %eax
je 0x5762a
cmpl $0x1, %eax
jne 0x5764e
movq %r15, %rdi
movl %r13d, %esi
movl 0x14(%rsp), %edx
movq 0x20(%rsp), %rcx
callq 0x5bd50
addq %r13, %r13
leaq (,%r13,2), %rcx
addq %r13, %rcx
movb 0x97372(%r15,%rcx), %dl
testb %al, %al
je 0x57672
cmpb $0x9, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x5768a
movb $0xa, 0x97372(%r15,%rcx)
jmp 0x5768a
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0xe, 0x97372(%r15,%rax)
ja 0x5768a
movb $0xf, 0x97372(%r15,%rax)
jmp 0x5768a
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0xf, 0x97372(%r15,%rax)
ja 0x5768a
movb $0x10, 0x97372(%r15,%rax)
jmp 0x5768a
cmpb $0xd, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x5768a
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
jmp 0x575a7
cltq
imulq $0x7c8, %rax, %rdx      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rdx)
jne 0x576fd
addq %r12, %rdx
movswl 0x8(%rdx), %ecx
movslq %ecx, %rdi
movl 0x7c0(%rdx), %esi
addq %rdi, %rdi
leaq (%rdi,%rdi,2), %rdx
movb 0x97372(%r15,%rdx), %dil
cmpl $0x2, %esi
je 0x57707
cmpl $0x1, %esi
jne 0x57712
movb $0xb, %sil
cmpb $0xb, %dil
jae 0x576f0
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 0x5771d
movb $0xc, %sil
cmpb $0xc, %dil
jb 0x576e8
jmp 0x576f0
movb $0xd, %sil
cmpb $0xc, %dil
jbe 0x576e8
jmp 0x576f0
cmpl $0x11f, %eax            # imm = 0x11F
jne 0x576a5
jmp 0x5783c
setg %cl
movzwl %ax, %edx
cmpl $0x11f, %edx            # imm = 0x11F
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5783c
movslq %eax, %r14
imulq $0x7c8, %r14, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x57828
addq %r12, %rax
movswl 0x8(%rax), %ebx
movslq %ebx, %r13
movl 0x7c0(%rax), %eax
cmpl $0x2, %eax
je 0x577bb
cmpl $0x1, %eax
jne 0x577df
movq %r15, %rdi
movl %r13d, %esi
movl 0x14(%rsp), %edx
movq 0x20(%rsp), %rcx
callq 0x5bd50
addq %r13, %r13
leaq (,%r13,2), %rcx
addq %r13, %rcx
movb 0x97372(%r15,%rcx), %dl
testb %al, %al
je 0x57803
cmpb $0x9, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x5781b
movb $0xa, 0x97372(%r15,%rcx)
jmp 0x5781b
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x11, 0x97372(%r15,%rax)
ja 0x5781b
movb $0x12, 0x97372(%r15,%rax)
jmp 0x5781b
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x12, 0x97372(%r15,%rax)
ja 0x5781b
movb $0x13, 0x97372(%r15,%rax)
jmp 0x5781b
cmpb $0x10, %dl
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
ja 0x5781b
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 0x57743
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x3, %sil
cmpb $0x3, %dl
jb 0x57559
jmp 0x57568
movb $0x6, %sil
cmpb $0x5, %dl
jbe 0x57559
jmp 0x57568