// File: /workspace/github_cpp_makefile_star2_O1/kobanium[P]Ray/src/feature/SimulationFeature.cpp
// Function: CheckFeatureLib3ForSimulation(game_info_t*, int, int, int*, int&)
static void
CheckFeatureLib3ForSimulation( game_info_t *game, const int color, const int id, int update[], int &update_num )
{
  const int *string_id = game->string_id;
  const string_t *string = game->string;
  const char *board = game->board;
  int neighbor = string[id].neighbor[0];
  int lib1, lib2, lib3;
  bool capturable1, capturable2;

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

  // 呼吸点の周囲が空点3つ, または呼吸点が3つ以上の自分の連に接続できるかで特徴を判定
  if (nb4_empty[Pat3(game->pat, lib1)] == 3 ||
      (board[NORTH(lib1)] == color && string_id[NORTH(lib1)] != id &&
       string[string_id[NORTH(lib1)]].libs >= 3) ||
      (board[ WEST(lib1)] == color && string_id[ WEST(lib1)] != id &&
       string[string_id[WEST(lib1)]].libs >= 3) ||
      (board[ EAST(lib1)] == color && string_id[ EAST(lib1)] != id &&
       string[string_id[EAST(lib1)]].libs >= 3) ||
      (board[SOUTH(lib1)] == color && string_id[SOUTH(lib1)] != id &&
       string[string_id[SOUTH(lib1)]].libs >= 3)) {
    CompareSwapFeature(game->tactical_features, lib1, EXTENSION, SIM_3POINT_EXTENSION_SAFELY);
  } else {
    CompareSwapFeature(game->tactical_features, lib1, EXTENSION, SIM_3POINT_EXTENSION);
  }

  // 呼吸点の周囲が空点3つ, または呼吸点が3つ以上の自分の連に接続できるかで特徴を判定
  if (nb4_empty[Pat3(game->pat, lib2)] == 3 ||
      (board[NORTH(lib2)] == color && string_id[NORTH(lib2)] != id &&
       string[string_id[NORTH(lib2)]].libs >= 3) ||
      (board[ WEST(lib2)] == color && string_id[ WEST(lib2)] != id &&
       string[string_id[WEST(lib2)]].libs >= 3) ||
      (board[ EAST(lib2)] == color && string_id[ EAST(lib2)] != id &&
       string[string_id[EAST(lib2)]].libs >= 3) ||
      (board[SOUTH(lib2)] == color && string_id[SOUTH(lib2)] != id &&
       string[string_id[SOUTH(lib2)]].libs >= 3)) {
    CompareSwapFeature(game->tactical_features, lib2, EXTENSION, SIM_3POINT_EXTENSION_SAFELY);
  } else {
    CompareSwapFeature(game->tactical_features, lib2, EXTENSION, SIM_3POINT_EXTENSION);
  }

  // 呼吸点の周囲が空点3つ, または呼吸点が3つ以上の自分の連に接続できるかで特徴を判定
  if (nb4_empty[Pat3(game->pat, lib3)] == 3 ||
      (board[NORTH(lib3)] == color && string_id[NORTH(lib3)] != id &&
       string[string_id[NORTH(lib3)]].libs >= 3) ||
      (board[ WEST(lib3)] == color && string_id[ WEST(lib3)] != id &&
       string[string_id[ WEST(lib3)]].libs >= 3) ||
      (board[ EAST(lib3)] == color && string_id[ EAST(lib3)] != id &&
       string[string_id[ EAST(lib3)]].libs >= 3) ||
      (board[SOUTH(lib3)] == color && string_id[SOUTH(lib3)] != id &&
       string[string_id[SOUTH(lib3)]].libs >= 3)) {
    CompareSwapFeature(game->tactical_features, lib3, EXTENSION, SIM_3POINT_EXTENSION_SAFELY);
  } else {
    CompareSwapFeature(game->tactical_features, lib3, EXTENSION, SIM_3POINT_EXTENSION);
  }

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

  // 呼吸点が3つになった連の周囲の敵連を調べる
  // 1. 呼吸点が1つの敵連
  // 2. 呼吸点が2つの敵連
  // 3. 呼吸点が3つの敵連
  // それぞれに対して, 特徴を判定する
  while (neighbor != NEIGHBOR_END) {
    if (string[neighbor].libs == 1) {
      lib1 = string[neighbor].lib[0];
      update[update_num++] = lib1;
      if (string[neighbor].size <= 2) {
        CompareSwapFeature(game->tactical_features, lib1, CAPTURE, SIM_3POINT_CAPTURE_SMALL);
      } else {
        CompareSwapFeature(game->tactical_features, lib1, CAPTURE, SIM_3POINT_CAPTURE_LARGE);
      }
    } else if (string[neighbor].libs == 2) {
      lib1 = string[neighbor].lib[0];
      lib2 = string[neighbor].lib[lib1];
      update[update_num++] = lib1;
      update[update_num++] = lib2;
      capturable1 = IsCapturableAtariForSimulation(game, lib1, color, neighbor);
      capturable2 = IsCapturableAtariForSimulation(game, lib2, color, neighbor);
      if (string[neighbor].size <= 2) {
        if (capturable1) {
          CompareSwapFeature(game->tactical_features, lib1, ATARI, SIM_3POINT_C_ATARI_SMALL);
        } else {
          CompareSwapFeature(game->tactical_features, lib1, ATARI, SIM_3POINT_ATARI_SMALL);
        }
        if (capturable2) {
          CompareSwapFeature(game->tactical_features, lib2, ATARI, SIM_3POINT_C_ATARI_SMALL);
        } else {
          CompareSwapFeature(game->tactical_features, lib2, ATARI, SIM_3POINT_ATARI_SMALL);
        }
      } else {
        if (capturable1) {
          CompareSwapFeature(game->tactical_features, lib1, ATARI, SIM_3POINT_C_ATARI_LARGE);
        } else {
          CompareSwapFeature(game->tactical_features, lib1, ATARI, SIM_3POINT_ATARI_LARGE);
        }
        if (capturable2) {
          CompareSwapFeature(game->tactical_features, lib2, ATARI, SIM_3POINT_C_ATARI_LARGE);
        } else {
          CompareSwapFeature(game->tactical_features, lib2, ATARI, SIM_3POINT_ATARI_LARGE);
        }
      }
    } else if (string[neighbor].libs == 3) {
      lib1 = string[neighbor].lib[0];
      lib2 = string[neighbor].lib[lib1];
      lib3 = string[neighbor].lib[lib2];
      update[update_num++] = lib1;
      update[update_num++] = lib2;
      update[update_num++] = lib3;
      if (string[neighbor].size <= 2) {
        CompareSwapFeature(game->tactical_features, lib1, DAME, SIM_3POINT_DAME_SMALL);
        CompareSwapFeature(game->tactical_features, lib2, DAME, SIM_3POINT_DAME_SMALL);
        CompareSwapFeature(game->tactical_features, lib3, DAME, SIM_3POINT_DAME_SMALL);
      } else {
        CompareSwapFeature(game->tactical_features, lib1, DAME, SIM_3POINT_DAME_LARGE);
        CompareSwapFeature(game->tactical_features, lib2, DAME, SIM_3POINT_DAME_LARGE);
        CompareSwapFeature(game->tactical_features, lib3, DAME, SIM_3POINT_DAME_LARGE);
      }
    }
    neighbor = string[id].neighbor[neighbor];
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movl %esi, %ebx
movq %rdi, %r15
leaq 0x9620(%rdi), %rax
movq %rax, 0x10(%rsp)
movl %edx, 0x8(%rsp)
movslq %edx, %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rdi, %rax
addq $0x9620, %rax           # imm = 0x9620
movzwl 0x57c(%rax), %ebp
movswl 0x8(%rax), %ecx
movl %ecx, 0x1c(%rsp)
movslq %ecx, %r13
movswl 0x8(%rax,%r13,2), %ecx
movl %ecx, 0xc(%rsp)
movslq %ecx, %r14
movq %rax, 0x20(%rsp)
movswl 0x8(%rax,%r14,2), %eax
movl %eax, 0x40(%rsp)
leaq 0x4748(%rdi), %r12
movq %r12, %rdi
movl %r13d, %esi
callq 0x4f84b
movl %eax, %eax
leaq 0x1aae7215(%rip), %rcx  # 0x1ab3e6e0
cmpb $0x3, (%rcx,%rax)
jne 0x574fc
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x2, 0x97375(%r15,%rax)
ja 0x575fa
movb $0x3, 0x97375(%r15,%rax)
jmp 0x575fa
leaq 0x1e3b9(%rip), %rax     # 0x758bc
movl (%rax), %eax
movl 0x1c(%rsp), %ecx
subl %eax, %ecx
movslq %ecx, %rcx
movsbl 0x43f8(%r15,%rcx), %edx
cmpl %ebx, %edx
jne 0x5753c
movslq 0x95720(%r15,%rcx,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x5753c
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x574d1
movsbl 0x43f7(%r15,%r13), %ecx
cmpl %ebx, %ecx
jne 0x5756e
movslq 0x9571c(%r15,%r13,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x5756e
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x574d1
movsbl 0x43f9(%r15,%r13), %ecx
cmpl %ebx, %ecx
jne 0x575a0
movslq 0x95724(%r15,%r13,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x575a0
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x574d1
addl 0x1c(%rsp), %eax
cltq
movsbl 0x43f8(%r15,%rax), %ecx
cmpl %ebx, %ecx
jne 0x575d8
movslq 0x95720(%r15,%rax,4), %rax
cmpl 0x8(%rsp), %eax
je 0x575d8
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x10(%rsp), %rcx
cmpl $0x3, 0x4(%rcx,%rax)
jge 0x574d1
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x0, 0x97375(%r15,%rax)
jne 0x575fa
movb $0x1, 0x97375(%r15,%rax)
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x4f84b
movl %eax, %eax
leaq 0x1aae70d1(%rip), %rcx  # 0x1ab3e6e0
cmpb $0x3, (%rcx,%rax)
jne 0x57639
addq %r14, %r14
leaq (%r14,%r14,2), %rax
cmpb $0x2, 0x97375(%r15,%rax)
ja 0x57730
movb $0x3, 0x97375(%r15,%rax)
jmp 0x57730
leaq 0x1e27c(%rip), %rax     # 0x758bc
movl (%rax), %eax
movl 0xc(%rsp), %ecx
subl %eax, %ecx
movslq %ecx, %rcx
movsbl 0x43f8(%r15,%rcx), %edx
cmpl %ebx, %edx
jne 0x57679
movslq 0x95720(%r15,%rcx,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x57679
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x57615
movsbl 0x43f7(%r15,%r14), %ecx
cmpl %ebx, %ecx
jne 0x576ab
movslq 0x9571c(%r15,%r14,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x576ab
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x57615
movsbl 0x43f9(%r15,%r14), %ecx
cmpl %ebx, %ecx
jne 0x576dd
movslq 0x95724(%r15,%r14,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x576dd
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movq 0x10(%rsp), %rdx
cmpl $0x2, 0x4(%rdx,%rcx)
jg 0x57615
addl 0xc(%rsp), %eax
cltq
movsbl 0x43f8(%r15,%rax), %ecx
cmpl %ebx, %ecx
jne 0x57715
movslq 0x95720(%r15,%rax,4), %rax
cmpl 0x8(%rsp), %eax
je 0x57715
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x10(%rsp), %rcx
cmpl $0x3, 0x4(%rcx,%rax)
jge 0x57615
addq %r14, %r14
leaq (%r14,%r14,2), %rax
cmpb $0x0, 0x97375(%r15,%rax)
jne 0x57730
movb $0x1, 0x97375(%r15,%rax)
movl 0x40(%rsp), %r14d
movslq %r14d, %r13
movq %r12, %rdi
movl %r13d, %esi
callq 0x4f84b
movl %eax, %eax
leaq 0x1aae6f94(%rip), %rcx  # 0x1ab3e6e0
cmpb $0x3, (%rcx,%rax)
movl %ebx, 0x44(%rsp)
movq 0x10(%rsp), %r10
jne 0x57795
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x2, 0x97375(%r15,%rax)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %r11
ja 0x57890
movb $0x3, 0x97375(%r15,%rax)
jmp 0x57890
leaq 0x1e120(%rip), %rax     # 0x758bc
movl (%rax), %eax
movl %r14d, %ecx
subl %eax, %ecx
movslq %ecx, %rcx
movsbl 0x43f8(%r15,%rcx), %edx
cmpl %ebx, %edx
jne 0x577d0
movslq 0x95720(%r15,%rcx,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x577d0
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
cmpl $0x2, 0x4(%r10,%rcx)
jg 0x5775b
movsbl 0x43f7(%r15,%r13), %ecx
cmpl %ebx, %ecx
jne 0x577fe
movslq 0x9571c(%r15,%r13,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x577fe
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
cmpl $0x2, 0x4(%r10,%rcx)
jg 0x5775b
movsbl 0x43f9(%r15,%r13), %ecx
cmpl %ebx, %ecx
jne 0x5782c
movslq 0x95724(%r15,%r13,4), %rcx
cmpl 0x8(%rsp), %ecx
je 0x5782c
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
cmpl $0x2, 0x4(%r10,%rcx)
jg 0x5775b
addl %r14d, %eax
cltq
movsbl 0x43f8(%r15,%rax), %ecx
cmpl %ebx, %ecx
jne 0x5785f
movslq 0x95720(%r15,%rax,4), %rax
cmpl 0x8(%rsp), %eax
je 0x5785f
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpl $0x3, 0x4(%r10,%rax)
jge 0x5775b
addq %r13, %r13
leaq (,%r13,2), %rax
addq %r13, %rax
cmpb $0x0, 0x97375(%r15,%rax)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %r11
jne 0x57890
movb $0x1, 0x97375(%r15,%rax)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl 0x1c(%rsp), %ecx
movl %ecx, (%r9,%rax,4)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl 0xc(%rsp), %ecx
movl %ecx, (%r9,%rax,4)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl %r14d, (%r9,%rax,4)
movzwl %bp, %eax
cmpl $0x11f, %eax            # imm = 0x11F
je 0x57c2c
movq %r15, 0x38(%rsp)
movl 0x44(%rsp), %r14d
movswq %bp, %r12
imulq $0x7c8, %r12, %rax      # imm = 0x7C8
leaq (%r10,%rax), %rbx
movl 0x4(%r10,%rax), %eax
cmpl $0x3, %eax
je 0x579ea
cmpl $0x2, %eax
je 0x57946
cmpl $0x1, %eax
jne 0x57c17
movswl 0x8(%rbx), %eax
cltq
movslq (%r8), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%r8)
movl %eax, (%r9,%rcx,4)
addq %rax, %rax
cmpl $0x2, 0x7c0(%rbx)
leaq (%rax,%rax,2), %rax
jg 0x57b22
cmpb $0x4, 0x97372(%r15,%rax)
ja 0x57c17
movb $0x5, 0x97372(%r15,%rax)
jmp 0x57c17
movswl 0x8(%rbx), %eax
movslq %eax, %rbp
movswl 0x8(%rbx,%rbp,2), %eax
movslq %eax, %r13
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl %ebp, (%r9,%rax,4)
movslq (%r8), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r8)
movl %r13d, (%r9,%rax,4)
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x5b318
movb %al, 0xc(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x5b318
addq %rbp, %rbp
cmpl $0x2, 0x7c0(%rbx)
leaq (%rbp,%rbp,2), %rcx
jg 0x57a8e
cmpb $0x0, 0xc(%rsp)
je 0x57b3f
movq 0x38(%rsp), %r15
cmpb $0x5, 0x97374(%r15,%rcx)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %r11
ja 0x57b6c
movb $0x6, 0x97374(%r15,%rcx)
jmp 0x57b6c
movswl 0x8(%rbx), %eax
movslq %eax, %rdx
movswl 0x8(%rbx,%rdx,2), %eax
movslq %eax, %rcx
movswl 0x8(%rbx,%rcx,2), %eax
cltq
movslq (%r8), %rsi
leal 0x1(%rsi), %edi
movl %edi, (%r8)
movl %edx, (%r9,%rsi,4)
movslq (%r8), %rsi
leal 0x1(%rsi), %edi
movl %edi, (%r8)
movl %ecx, (%r9,%rsi,4)
movslq (%r8), %rsi
leal 0x1(%rsi), %edi
movl %edi, (%r8)
movl %eax, (%r9,%rsi,4)
addq %rdx, %rdx
cmpl $0x2, 0x7c0(%rbx)
leaq (%rdx,%rdx,2), %rdx
jg 0x57acf
cmpb $0x0, 0x97376(%r15,%rdx)
jne 0x57a4f
movb $0x1, 0x97376(%r15,%rdx)
addq %rcx, %rcx
leaq (%rcx,%rcx,2), %rcx
cmpb $0x0, 0x97376(%r15,%rcx)
jne 0x57a6a
movb $0x1, 0x97376(%r15,%rcx)
addq %rax, %rax
leaq (%rax,%rax,2), %rax
cmpb $0x0, 0x97376(%r15,%rax)
jne 0x57c17
movb $0x1, 0x97376(%r15,%rax)
jmp 0x57c17
cmpb $0x0, 0xc(%rsp)
je 0x57b98
movq 0x38(%rsp), %r15
cmpb $0x7, 0x97374(%r15,%rcx)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %r11
ja 0x57bc5
movb $0x8, 0x97374(%r15,%rcx)
jmp 0x57bc5
cmpb $0x1, 0x97376(%r15,%rdx)
ja 0x57ae3
movb $0x2, 0x97376(%r15,%rdx)
addq %rcx, %rcx
leaq (%rcx,%rcx,2), %rcx
cmpb $0x1, 0x97376(%r15,%rcx)
ja 0x57afe
movb $0x2, 0x97376(%r15,%rcx)
addq %rax, %rax
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x97376(%r15,%rax)
ja 0x57c17
movb $0x2, 0x97376(%r15,%rax)
jmp 0x57c17
cmpb $0x6, 0x97372(%r15,%rax)
ja 0x57c17
movb $0x7, 0x97372(%r15,%rax)
jmp 0x57c17
movq 0x38(%rsp), %r15
cmpb $0x1, 0x97374(%r15,%rcx)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %r11
ja 0x57b6c
movb $0x2, 0x97374(%r15,%rcx)
addq %r13, %r13
leaq (,%r13,2), %rcx
addq %r13, %rcx
testb %al, %al
je 0x57bed
cmpb $0x5, 0x97374(%r15,%rcx)
ja 0x57c17
movb $0x6, 0x97374(%r15,%rcx)
jmp 0x57c17
movq 0x38(%rsp), %r15
cmpb $0x3, 0x97374(%r15,%rcx)
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %r11
ja 0x57bc5
movb $0x4, 0x97374(%r15,%rcx)
addq %r13, %r13
leaq (,%r13,2), %rcx
addq %r13, %rcx
testb %al, %al
je 0x57c03
cmpb $0x7, 0x97374(%r15,%rcx)
ja 0x57c17
movb $0x8, 0x97374(%r15,%rcx)
jmp 0x57c17
cmpb $0x1, 0x97374(%r15,%rcx)
ja 0x57c17
movb $0x2, 0x97374(%r15,%rcx)
jmp 0x57c17
cmpb $0x3, 0x97374(%r15,%rcx)
ja 0x57c17
movb $0x4, 0x97374(%r15,%rcx)
movzwl 0x57c(%r11,%r12,2), %ebp
cmpl $0x11f, %ebp            # imm = 0x11F
jne 0x578d7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq