// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
movl (%r8), %ebp
leaq 0x9620(%rdi), %r14
xorl %r15d, %r15d
cmpl $0x2, %ecx
jl 0x53055
movl %ecx, %eax
xorl %r15d, %r15d
movl $0x1, %ecx
movl (%r8,%rcx,4), %edi
xorl %r9d, %r9d
cmpl %edi, (%r8,%r9,4)
je 0x5304d
incq %r9
cmpq %r9, %rcx
jne 0x53017
movl (%r8,%rcx,4), %edi
cmpl %edi, %ebp
movl %edi, %r9d
cmovgl %ebp, %r9d
movslq %r15d, %r15
cmovgel %edi, %ebp
movslq %r9d, %rdi
imulq $0x7c8, %rdi, %rdi      # imm = 0x7C8
addq %r14, %rdi
movq %rdi, 0x20(%rsp,%r15,8)
incl %r15d
incq %rcx
cmpq %rax, %rcx
jne 0x53010
movq %rbx, %rdi
movl %ebp, %ecx
callq 0x52e3c
testl %r15d, %r15d
jle 0x532a2
movslq %ebp, %rax
imulq $0x7c8, %rax, %rdx      # imm = 0x7C8
leaq (%r14,%rdx), %rax
leaq 0x96200(%rbx), %rcx
addq %r14, %rdx
addq $0x7bc, %rdx            # imm = 0x7BC
movslq (%rdx), %rsi
movl 0x95720(%rbx,%rsi,4), %esi
movslq %esi, %rdi
movl %r15d, %r8d
movq %r8, 0x8(%rsp)
xorl %r8d, %r8d
movq %r8, 0x10(%rsp)
movq 0x20(%rsp,%r8,8), %r10
movslq 0x7bc(%r10), %r15
movslq 0x95720(%rbx,%r15,4), %r11
movzwl 0x8(%r10), %ebp
cmpl $0x2b7, %ebp            # imm = 0x2B7
je 0x53108
xorl %r13d, %r13d
movswq %bp, %r12
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x530f7
movq %r13, %r8
movzwl 0x8(%rax,%r13,2), %r9d
movswq %r9w, %r13
cmpw %bp, %r9w
jl 0x530d5
movw %r9w, 0x8(%rax,%r12,2)
movw %bp, 0x8(%rax,%r8,2)
incl 0x4(%rax)
movzwl 0x8(%r10,%r12,2), %ebp
movq %r12, %r13
cmpl $0x2b7, %ebp            # imm = 0x2B7
jne 0x530c8
cmpl $0x2b7, %r15d           # imm = 0x2B7
je 0x53167
xorl %r8d, %r8d
movl %r15d, %ebp
movslq %r15d, %r12
movl %esi, 0x95720(%rbx,%r12,4)
movl (%rdx), %r13d
cmpl %r12d, %r13d
jle 0x5312f
movq %rdx, %r8
jmp 0x53146
testl %r8d, %r8d
cmovnel %r8d, %r13d
movslq %r13d, %r8
movl (%rcx,%r8,4), %r13d
cmpl %ebp, %r13d
jl 0x53136
leaq (%rcx,%r8,4), %r8
movl 0x96200(%rbx,%r12,4), %r15d
movl %r13d, (%rcx,%r12,4)
movl %ebp, (%r8)
incl 0x7c0(%rax)
movl %ebp, %r8d
cmpl $0x2b7, %r15d           # imm = 0x2B7
jne 0x53114
movzwl 0x57c(%r10), %r13d
cmpl $0x11f, %r13d           # imm = 0x11F
je 0x53287
xorl %ebp, %ebp
movq %r10, 0x18(%rsp)
movswq %r13w, %r15
imulq $0x7c8, %r15, %r12      # imm = 0x7C8
addq %r14, %r12
cmpw $0x0, 0x57c(%r12,%r11,2)
je 0x531d9
xorl %r8d, %r8d
movslq %r8d, %r9
movswl 0x57c(%r12,%r9,2), %r8d
cmpl %r8d, %r11d
jne 0x531a0
movslq %r8d, %r8
movzwl 0x57c(%r12,%r8,2), %r8d
movw %r8w, 0x57c(%r12,%r9,2)
movw $0x0, 0x57c(%r12,%r11,2)
decl 0x578(%r12)
cmpw $0x0, 0x57c(%rax,%r15,2)
jne 0x53233
movq %rdi, %r10
movq %rdx, %rdi
movq %rbx, %rdx
movq %r14, %rbx
movl %ebp, %r9d
movslq %r9d, %r8
movzwl 0x57c(%rax,%r8,2), %r14d
movswl %r14w, %r9d
cmpw %r13w, %r14w
jl 0x531f4
movw %r14w, 0x57c(%rax,%r15,2)
movw %r13w, 0x57c(%rax,%r8,2)
incl 0x578(%rax)
movq %rbx, %r14
movq %rdx, %rbx
movq %rdi, %rdx
movq %r10, %rdi
movq 0x18(%rsp), %r10
cmpw $0x0, 0x57c(%r12,%rdi,2)
jne 0x5326d
movslq %ebp, %r8
movzwl 0x57c(%r12,%r8,2), %r9d
movswl %r9w, %ebp
cmpl %ebp, %esi
jg 0x5323f
movw %r9w, 0x57c(%r12,%rdi,2)
movw %di, 0x57c(%r12,%r8,2)
incl 0x578(%r12)
movswl %r15w, %ebp
movzwl 0x57c(%r10,%r15,2), %r13d
cmpl $0x11f, %r13d           # imm = 0x11F
jne 0x53183
movb $0x0, 0x7c4(%r10)
movq 0x10(%rsp), %r8
incq %r8
cmpq 0x8(%rsp), %r8
jne 0x5309f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq