// File: /workspace/github_cpp_makefile_star2_O1/kobanium[P]Ray/src/feature/Seki.cpp
// Function: CheckSeki(game_info_t const*, bool*)
void
CheckSeki( const game_info_t *game, bool seki[] )
{
  const char *board = game->board;
  const int *string_id = game->string_id;
  const string_t *string = game->string;
  int id, lib1, lib2;
  int lib1_id[4], lib2_id[4], lib1_ids, lib2_ids;
  int neighbor1_lib, neighbor2_lib;
  int neighbor4[4];
  bool seki_candidate[BOARD_MAX] = {false};
  bool already_checked;

  // 双方が自己アタリになっている座標を抽出
  for (int i = 0; i < pure_board_max; i++) {
    const int pos = onboard_pos[i];
    if (IsSelfAtari(game, S_BLACK, pos) &&
        IsSelfAtari(game, S_WHITE, pos)) {
      seki_candidate[pos] = true;
    }
  }

  for (int i = 0; i < MAX_STRING; i++) {
    // 連が存在しない,
    // または連の呼吸点数が2個でなければ次を調べる
    if (!string[i].flag || string[i].libs != 2) continue;

    // 連の大きさが6以上ならシミュレーションで
    // 自己アタリを打たないので次を調べる
    if (string[i].size >= 6) continue;

    lib1 = string[i].lib[0];
    lib2 = string[i].lib[lib1];
    // 連の持つ呼吸点がともにセキの候補
    if (seki_candidate[lib1] &&
        seki_candidate[lib2]) {
      // 呼吸点1の周囲の連のIDを取り出す
      GetNeighbor4(neighbor4, lib1);
      lib1_ids = 0;
      for (int j = 0; j < 4; j++) {
        if (board[neighbor4[j]] == S_BLACK ||
            board[neighbor4[j]] == S_WHITE) {
          id = string_id[neighbor4[j]];
          if (id != i) {
            already_checked = false;
            for (int k = 0; k < lib1_ids; k++) {
              if (lib1_id[k] == id) {
                already_checked = true;
                break;
              }
            }
            if (!already_checked) {
              lib1_id[lib1_ids++] = id;
            }
          }
        }
      }
      // 呼吸点2の周囲の連のIDを取り出す
      GetNeighbor4(neighbor4, lib2);
      lib2_ids = 0;
      for (int j = 0; j < 4; j++) {
        if (board[neighbor4[j]] == S_BLACK ||
            board[neighbor4[j]] == S_WHITE) {
          id = string_id[neighbor4[j]];
          if (id != i) {
            already_checked = false;
            for (int k = 0; k < lib2_ids; k++) {
              if (lib2_id[k] == id) {
          already_checked = true;
          break;
              }
            }
            if (!already_checked) {
              lib2_id[lib2_ids++] = id;
            }
          }
        }
      }

      if (lib1_ids == 1 && lib2_ids == 1) {
        neighbor1_lib = string[lib1_id[0]].lib[0];
        if (neighbor1_lib == lib1 ||
            neighbor1_lib == lib2) {
          neighbor1_lib = string[lib1_id[0]].lib[neighbor1_lib];
        }
        neighbor2_lib = string[lib2_id[0]].lib[0];
        if (neighbor2_lib == lib1 ||
            neighbor2_lib == lib2) {
          neighbor2_lib = string[lib2_id[0]].lib[neighbor2_lib];
        }
        if (neighbor1_lib == neighbor2_lib) {
          if (eye_condition[Pat3(game->pat, neighbor1_lib)] != E_NOT_EYE) {
            seki[lib1] = seki[lib2] = true;
            seki[neighbor1_lib] = true;
          }
        } else if (eye_condition[Pat3(game->pat, neighbor1_lib)] == E_COMPLETE_HALF_EYE &&
                   eye_condition[Pat3(game->pat, neighbor2_lib)] == E_COMPLETE_HALF_EYE) {
          int tmp_id1 = 0, tmp_id2 = 0;
          GetNeighbor4(neighbor4, neighbor1_lib);
          for (int j = 0; j < 4; j++) {
            if (board[neighbor4[j]] == S_BLACK ||
                board[neighbor4[j]] == S_WHITE) {
              id = string_id[neighbor4[j]];
              if (id != lib1_id[0] &&
                  id != lib2_id[0] &&
                  id != tmp_id1) {
              tmp_id1 = id;
              }
            }
          }
          GetNeighbor4(neighbor4, neighbor2_lib);
          for (int j = 0; j < 4; j++) {
            if (board[neighbor4[j]] == S_BLACK ||
                board[neighbor4[j]] == S_WHITE) {
              id = string_id[neighbor4[j]];
              if (id != lib1_id[0] &&
                  id != lib2_id[0] &&
                  id != tmp_id2) {
                tmp_id2 = id;
              }
            }
          }
          if (tmp_id1 == tmp_id2) {
            seki[lib1] = seki[lib2] = true;
            seki[neighbor1_lib] = seki[neighbor2_lib] = true;
          }
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
leaq 0x60(%rsp), %rdi
movl $0x349, %edx            # imm = 0x349
xorl %esi, %esi
callq 0x6210
leaq 0x1f4a3(%rip), %rbx     # 0x758b0
cmpl $0x0, (%rbx)
jle 0x56459
xorl %r15d, %r15d
leaq 0x1ab0a2d4(%rip), %r12  # 0x1ab606f0
movl (%r12,%r15,4), %ebp
movq %r14, %rdi
movl $0x1, %esi
movl %ebp, %edx
callq 0x5b63e
testb %al, %al
je 0x5644e
movq %r14, %rdi
movl $0x2, %esi
movl %ebp, %edx
callq 0x5b63e
testb %al, %al
je 0x5644e
movslq %ebp, %rax
movb $0x1, 0x60(%rsp,%rax)
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0x5641c
leaq 0x9620(%r14), %rbx
leaq 0x4748(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
imulq $0x7c8, %r12, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbx,%rax)
jne 0x5672f
addq %rbx, %rax
cmpl $0x2, 0x4(%rax)
jne 0x5672f
cmpl $0x5, 0x7c0(%rax)
jg 0x5672f
movswq 0x8(%rax), %r13
cmpb $0x1, 0x60(%rsp,%r13)
jne 0x5672f
movswl 0x8(%rax,%r13,2), %ebp
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
cmpb $0x1, 0x60(%rsp,%rax)
jne 0x5672f
movq %rsp, %rdi
movl %r13d, %esi
callq 0x53e40
xorl %eax, %eax
xorl %r15d, %r15d
movslq (%rsp,%rax,4), %rcx
movb 0x43f8(%r14,%rcx), %dl
decb %dl
cmpb $0x1, %dl
ja 0x5651a
movl 0x95720(%r14,%rcx,4), %ecx
cmpq %rcx, %r12
je 0x5651a
testl %r15d, %r15d
jle 0x56510
movl %r15d, %edx
xorl %esi, %esi
cmpl %ecx, 0x50(%rsp,%rsi,4)
je 0x5651a
incq %rsi
cmpq %rsi, %rdx
jne 0x56502
movslq %r15d, %rdx
incl %r15d
movl %ecx, 0x50(%rsp,%rdx,4)
incq %rax
cmpq $0x4, %rax
jne 0x564d8
movq %rsp, %rdi
movl %ebp, %esi
callq 0x53e40
xorl %ecx, %ecx
xorl %eax, %eax
movslq (%rsp,%rcx,4), %rdx
movb 0x43f8(%r14,%rdx), %sil
decb %sil
cmpb $0x1, %sil
ja 0x56572
movl 0x95720(%r14,%rdx,4), %edx
cmpq %rdx, %r12
je 0x56572
testl %eax, %eax
jle 0x56569
movl %eax, %esi
xorl %edi, %edi
cmpl %edx, 0x40(%rsp,%rdi,4)
je 0x56572
incq %rdi
cmpq %rdi, %rsi
jne 0x5655b
movslq %eax, %rsi
incl %eax
movl %edx, 0x40(%rsp,%rsi,4)
incq %rcx
cmpq $0x4, %rcx
jne 0x56531
xorl $0x1, %r15d
xorl $0x1, %eax
orl %r15d, %eax
jne 0x5672f
movslq 0x50(%rsp), %rsi
imulq $0x7c8, %rsi, %rcx      # imm = 0x7C8
movzwl 0x8(%rbx,%rcx), %eax
cmpw %r13w, %ax
je 0x565a9
cmpw 0x18(%rsp), %ax
jne 0x565b5
movswq %ax, %rax
addq %rbx, %rcx
movzwl 0x8(%rcx,%rax,2), %eax
movslq 0x40(%rsp), %rdi
imulq $0x7c8, %rdi, %rcx      # imm = 0x7C8
movzwl 0x8(%rbx,%rcx), %r15d
cmpw %r13w, %r15w
je 0x565d3
cmpw %bp, %r15w
jne 0x565e0
movswq %r15w, %rdx
addq %rbx, %rcx
movzwl 0x8(%rcx,%rdx,2), %r15d
movswl %ax, %ebp
cmpw %r15w, %bp
jne 0x56627
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x4f84b
movl %eax, %eax
leaq 0x1aaf80e2(%rip), %rcx  # 0x1ab4e6e0
cmpb $0x0, (%rcx,%rax)
je 0x5672f
movq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rax
movb $0x1, (%rcx,%rax)
movb $0x1, %dl
movb %dl, (%rcx,%r13)
movslq %ebp, %rax
movb %dl, (%rcx,%rax)
jmp 0x5672f
movq %rdi, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x4f84b
movl %eax, %eax
leaq 0x1aaf809a(%rip), %rcx  # 0x1ab4e6e0
cmpb $0x1, (%rcx,%rax)
jne 0x5672f
movswl %r15w, %esi
movq 0x10(%rsp), %rdi
movl %esi, %r15d
callq 0x4f84b
movl %eax, %eax
leaq 0x1aaf8076(%rip), %rcx  # 0x1ab4e6e0
cmpb $0x1, (%rcx,%rax)
jne 0x5672f
movq %rsp, %rdi
movl %ebp, 0x24(%rsp)
movl %ebp, %esi
callq 0x53e40
xorl %eax, %eax
xorl %ebp, %ebp
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
movslq (%rsp,%rax,4), %rcx
movb 0x43f8(%r14,%rcx), %dl
decb %dl
cmpb $0x1, %dl
ja 0x566b7
movl 0x95720(%r14,%rcx,4), %ecx
cmpl %edi, %ecx
movl %ecx, %edx
cmovel %ebp, %edx
cmpl %esi, %ecx
cmovnel %edx, %ebp
incq %rax
cmpq $0x4, %rax
jne 0x56690
movq %rsp, %rdi
movl %r15d, %esi
callq 0x53e40
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %rdi
xorl %eax, %eax
xorl %ecx, %ecx
movslq (%rsp,%rax,4), %rdx
movb 0x43f8(%r14,%rdx), %sil
decb %sil
cmpb $0x1, %sil
ja 0x56703
movl 0x95720(%r14,%rdx,4), %edx
cmpl %r8d, %edx
movl %edx, %esi
cmovel %ecx, %esi
cmpl %edi, %edx
cmovnel %esi, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x566d9
cmpl %ecx, %ebp
movl 0x24(%rsp), %ebp
jne 0x5672f
movq 0x38(%rsp), %rcx
movb $0x1, %al
movq 0x18(%rsp), %rdx
movb %al, (%rcx,%rdx)
movb %al, (%rcx,%r13)
movslq %r15d, %r13
jmp 0x56616
incq %r12
cmpq $0x120, %r12            # imm = 0x120
jne 0x5646f
addq $0x3b8, %rsp            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)