// File: kobanium[P]Ray/src/board/SearchBoard.cpp
// Function: MakeString(search_game_info_t*, int, int)
static void
MakeString( search_game_info_t *game, const int pos, const int color )
{
  string_t *string = game->string;
  string_t *new_string;
  char *board = game->board;
  int *string_id = game->string_id;
  int id = 1;
  int lib_add = 0;
  int other = GetOppositeColor(color);
  int neighbor, neighbor4[4];

  // 未使用の連のインデックスを見つける
  while (string[id].flag) { id++; }

  // 新しく連のデータを格納する箇所を保持
  new_string = &game->string[id];

  // 連のデータの初期化
  std::fill_n(new_string->lib, STRING_LIB_MAX, 0);
  std::fill_n(new_string->neighbor, MAX_NEIGHBOR, 0);
  new_string->color = static_cast<char>(color);
  new_string->lib[0] = LIBERTY_END;
  new_string->neighbor[0] = NEIGHBOR_END;
  new_string->libs = 0;
  new_string->origin = pos;
  new_string->size = 1;
  new_string->neighbors = 0;
  game->string_id[pos] = id;
  game->string_next[pos] = STRING_END;

  // 上下左右の座標の導出
  GetNeighbor4(neighbor4, pos);

  // 新しく作成した連の上下左右の座標を確認
  // 空点ならば, 作成した連に呼吸点を追加する
  // 敵の連ならば, 隣接する連をお互いに追加する
  for (int i = 0; i < 4; i++) {
    if (board[neighbor4[i]] == S_EMPTY) {
      lib_add = AddLiberty(new_string, neighbor4[i], lib_add);
    } else if (board[neighbor4[i]] == other) {
      neighbor = string_id[neighbor4[i]];
      AddNeighbor(&string[neighbor], id);
      AddNeighbor(&string[id], neighbor);
    }
  }

  // 連の存在フラグをオンにする
  new_string->flag = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x43cc, %rax           # imm = 0x43CC
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x956f0, %rax          # imm = 0x956F0
movq %rax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x10(%rbp), %edi
callq 0x25810
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
testb $0x1, 0x7c4(%rax)
je 0x9900b
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x98fe5
movq -0x8(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movslq -0x34(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
movl $0x0, -0x54(%rbp)
movl $0x2b8, %esi            # imm = 0x2B8
leaq -0x54(%rbp), %rdx
callq 0x9a090
movq -0x20(%rbp), %rdi
addq $0x57c, %rdi            # imm = 0x57C
movl $0x0, -0x58(%rbp)
movl $0x120, %esi            # imm = 0x120
leaq -0x58(%rbp), %rdx
callq 0x9a090
movl -0x10(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movw $0x2b7, 0x8(%rax)       # imm = 0x2B7
movq -0x20(%rbp), %rax
movw $0x11f, 0x57c(%rax)     # imm = 0x11F
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x7bc(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x7c0(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x578(%rax)
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x956f0(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl $0x2b7, 0x961d0(%rax,%rcx,4) # imm = 0x2B7
leaq -0x50(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x9bc90
movl $0x0, -0x5c(%rbp)
cmpl $0x4, -0x5c(%rbp)
jge 0x9919a
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x9912b
movq -0x20(%rbp), %rdi
movslq -0x5c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
movl -0x38(%rbp), %edx
callq 0x99a30
movl %eax, -0x38(%rbp)
jmp 0x9918a
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0x99188
movq -0x30(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x99ad0
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x40(%rbp), %esi
callq 0x99ad0
jmp 0x9918a
jmp 0x9918c
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x990f2
movq -0x20(%rbp), %rax
movb $0x1, 0x7c4(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)