// File: kobanium[P]Ray/src/board/SearchBoard.cpp
// Function: ConnectString(search_game_info_t*, int, int, int, int const*)
static void
ConnectString( search_game_info_t *game, const int pos, const int color, const int connection, const int id[] )
{
  int min = id[0];
  int ids[4];
  string_t *string = game->string;
  string_t *str[3];
  int connections = 0;
  bool flag = true;

  // 接続する連の個数を厳密に確認
  for (int i = 1; i < connection; i++) {
    flag = true;
    for (int j = 0; j < i; j++) {
      if (id[j] == id[i]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      if (min > id[i]) {
        str[connections] = &string[min];
        min = id[i];
      } else {
        str[connections] = &string[id[i]];
      }
      ids[connections] = id[i];
      connections++;
    }
  }

  ids[connections] = id[0];

  for (int i = 0; i <= connections; i++) {
    RecordString(game, ids[i]);
  }

  // 石を追加
  AddStone(game, pos, color, min);

  // 複数の連が接続するときの処理
  if (connections > 0) {
    MergeString(game, &game->string[min], str, connections);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x48(%rbp)
movl $0x0, -0x64(%rbp)
movb $0x1, -0x65(%rbp)
movl $0x1, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x9941f
movb $0x1, -0x65(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x9938f
movq -0x20(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movslq -0x6c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x99382
movb $0x0, -0x65(%rbp)
jmp 0x9938f
jmp 0x99384
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x9935c
testb $0x1, -0x65(%rbp)
je 0x9940f
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x6c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x993d0
movq -0x48(%rbp), %rcx
movslq -0x24(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rcx
movslq -0x64(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x20(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0x993f3
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x6c(%rbp), %rdx
movslq (%rax,%rdx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rcx
movslq -0x64(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x20(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movslq -0x64(%rbp), %rax
movl %ecx, -0x40(%rbp,%rax,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x99411
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x99345
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movslq -0x64(%rbp), %rax
movl %ecx, -0x40(%rbp,%rax,4)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x64(%rbp), %eax
jg 0x99458
movq -0x8(%rbp), %rdi
movslq -0x74(%rbp), %rax
movl -0x40(%rbp,%rax,4), %esi
callq 0x98bb0
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x99434
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x24(%rbp), %ecx
callq 0x991b0
cmpl $0x0, -0x64(%rbp)
jle 0x99499
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x95f0, %rsi           # imm = 0x95F0
movslq -0x24(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rsi
leaq -0x60(%rbp), %rdx
movl -0x64(%rbp), %ecx
callq 0x99b70
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)