// File: kobanium[P]Ray/src/board/String.cpp
// Function: MergeString(game_info_t*, string_t*, string_t**, int)
static void
MergeString( game_info_t *game, string_t *dst, string_t *src[3], const int n )
{
  int tmp, pos, prev, neighbor;
  int *string_next = game->string_next;
  int *string_id = game->string_id;
  int id = string_id[dst->origin], rm_id;
  string_t *string = game->string;

  for (int i = 0; i < n; i++) {
    // 接続で消える連のID
    rm_id = string_id[src[i]->origin];

    // 呼吸点をマージ
    prev = 0;
    pos = src[i]->lib[0];
    while (pos != LIBERTY_END) {
      prev = AddLiberty(dst, pos, prev);
      pos = src[i]->lib[pos];
    }

    // 連のIDを更新
    prev = 0;
    pos = src[i]->origin;
    while (pos != STRING_END) {
      string_id[pos] = id;
      tmp = string_next[pos];
      AddStoneToString(game, dst, pos, prev);
      prev = pos;
      pos = tmp;
    }

    // 隣接する敵連の情報をマージ
    prev = 0;
    neighbor = src[i]->neighbor[0];
    while (neighbor != NEIGHBOR_END) {
      RemoveNeighborString(&string[neighbor], rm_id);
      AddNeighbor(dst, neighbor, prev);
      AddNeighbor(&string[neighbor], id, prev);
      prev = neighbor;
      neighbor = src[i]->neighbor[neighbor];
    }

    // 使用済みフラグをオフ
    src[i]->flag = false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
addq $0x96200, %rax          # imm = 0x96200
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x7bc(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x9aa97
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x54(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x7bc(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movswl 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x2b7, -0x24(%rbp)     # imm = 0x2B7
je 0x9a985
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x9a3e0
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x24(%rbp)
jmp 0x9a950
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x7bc(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x2b7, -0x24(%rbp)     # imm = 0x2B7
je 0x9a9e7
movl -0x44(%rbp), %edx
movq -0x40(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x9a680
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x9a9a1
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x11f, -0x2c(%rbp)     # imm = 0x11F
je 0x9aa76
movq -0x50(%rbp), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x9b080
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x9a480
movq -0x50(%rbp), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x44(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x9a480
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x2c(%rbp)
jmp 0x9aa04
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, 0x7c4(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x9a90d
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)