// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/board/String.cpp
// Function: ConnectString(game_info_t*, int, int, int, int const*)
void
ConnectString( game_info_t *game, const int pos, const int color, const int connection, const int id[] )
{
  int min = id[0];
  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]];
      }
      connections++;
    }
  }

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r13
movl (%r8), %ebp
leaq 0x9620(%rdi), %rax
movq %rax, 0x18(%rsp)
movslq %ecx, %rax
xorl %r15d, %r15d
pushq $0x1
popq %rcx
cmpq %rax, %rcx
jge 0x3a5a6
movl (%r8,%rcx,4), %edi
xorl %r9d, %r9d
cmpq %r9, %rcx
je 0x3a57b
leaq 0x1(%r9), %r10
cmpl %edi, (%r8,%r9,4)
movq %r10, %r9
jne 0x3a567
jmp 0x3a5a1
cmpl %edi, %ebp
movl %edi, %r9d
cmovgl %ebp, %r9d
movslq %r15d, %r10
cmovgel %edi, %ebp
movslq %r9d, %rdi
imulq $0x7c8, %rdi, %rdi      # imm = 0x7C8
addq 0x18(%rsp), %rdi
movq %rdi, 0x40(%rsp,%r10,8)
incl %r15d
incq %rcx
jmp 0x3a55b
movq %r13, %rdi
movl %ebp, %ecx
callq 0x3a413
testl %r15d, %r15d
jle 0x3a70b
movslq %ebp, %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %r14
movslq 0x7bc(%rcx,%rax), %rax
movl 0x95720(%r13,%rax,4), %eax
movl %eax, 0xc(%rsp)
movl %r15d, %eax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %r13, 0x28(%rsp)
cmpq 0x30(%rsp), %rax
je 0x3a70b
movq %rax, 0x38(%rsp)
movq 0x40(%rsp,%rax,8), %rcx
movslq 0x7bc(%rcx), %rax
movl 0x95720(%r13,%rax,4), %eax
movl %eax, 0x24(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x8(%rcx), %rbx
xorl %edx, %edx
movq %rbx, %rax
movswl (%rax), %r12d
cmpl $0x2b7, %r12d           # imm = 0x2B7
je 0x3a649
movq %r14, %rdi
movl %r12d, %esi
callq 0x3a3aa
movslq %r12d, %rax
leaq (%rbx,%rax,2), %rax
movl %r12d, %edx
jmp 0x3a625
movq 0x10(%rsp), %rax
movl 0x7bc(%rax), %r12d
xorl %ecx, %ecx
cmpl $0x2b7, %r12d           # imm = 0x2B7
je 0x3a68d
movslq %r12d, %rax
movl 0xc(%rsp), %edx
movl %edx, 0x95720(%r13,%rax,4)
movl 0x96200(%r13,%rax,4), %ebx
movq %r13, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x3a4ed
movl %r12d, %ecx
movl %ebx, %r12d
jmp 0x3a657
movq 0x10(%rsp), %rax
leaq 0x57c(%rax), %rbx
xorl %r12d, %r12d
movq %rbx, %rax
movswl (%rax), %r13d
cmpl $0x11f, %r13d           # imm = 0x11F
je 0x3a6ed
movslq %r13d, %rbp
imulq $0x7c8, %rbp, %r15      # imm = 0x7C8
addq 0x18(%rsp), %r15
movq %r15, %rdi
movl 0x24(%rsp), %esi
callq 0x3aa00
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x3a3d8
movq %r15, %rdi
movl 0xc(%rsp), %esi
movl %r12d, %edx
callq 0x3a3d8
leaq (%rbx,%rbp,2), %rax
movl %r13d, %r12d
jmp 0x3a69f
movq 0x10(%rsp), %rax
movb $0x0, 0x7c4(%rax)
movq 0x38(%rsp), %rax
incq %rax
movq 0x28(%rsp), %r13
jmp 0x3a5ef
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq