// File: /workspace/github_cpp_makefile_star2_O3/kobanium[P]Ray/src/board/String.cpp
// Function: RemoveString(game_info_t*, string_t*, int)
int
RemoveString( game_info_t *game, string_t *string, const int color )
{
  string_t *str = game->string;
  int *string_next = game->string_next;
  int *string_id = game->string_id;
  int pos = string->origin, next;
  char *board = game->board;
  bool *candidates = game->candidates;
  int neighbor, rm_id = string_id[string->origin];
  int removed_color = board[pos];
  int *capture_pos = game->capture_pos[color - 1];
  int &capture_num = game->capture_num[color - 1];
  int head = 0;

  do {
    // 空点に戻す
    board[pos] = S_EMPTY;

    // 候補手に追加する
    candidates[pos] = true;

    // 打ち上げた石の記録
    head = AddCapture(capture_pos, pos, head);

    // パターンの更新
    UpdatePatternEmpty(game->pat, pos);

    game->current_hash ^= hash_bit[pos][removed_color];
    game->positional_hash ^= hash_bit[pos][removed_color];

    // 上下左右を確認する
    // 隣接する連があれば呼吸点を追加する
    if (str[string_id[NORTH(pos)]].flag) AddLiberty(&str[string_id[NORTH(pos)]], pos, 0);
    if (str[string_id[ WEST(pos)]].flag) AddLiberty(&str[string_id[ WEST(pos)]], pos, 0);
    if (str[string_id[ EAST(pos)]].flag) AddLiberty(&str[string_id[ EAST(pos)]], pos, 0);
    if (str[string_id[SOUTH(pos)]].flag) AddLiberty(&str[string_id[SOUTH(pos)]], pos, 0);

    // 連を構成する次の石の座標を記録
    next = string_next[pos];

    // 連の構成要素から取り除き,
    // 石を取り除いた箇所の連IDを元に戻す
    string_next[pos] = 0;
    string_id[pos] = 0;

    // 連を構成する次の石の座標に移動
    pos = next;
  } while (pos != STRING_END);

  // 取り除いた連に隣接する連から隣接情報を取り除く
  neighbor = string->neighbor[0];
  while (neighbor != NEIGHBOR_END) {
    RemoveNeighborString(&str[neighbor], rm_id);
    neighbor = string->neighbor[neighbor];
  }

  capture_num += string->size;

  // 連の存在フラグをオフ
  string->flag = false;

  // 打ち上げた石の数を返す
  return string->size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
leaq 0x9620(%rdi), %r8
movq %rsi, 0x8(%rsp)
movslq 0x7bc(%rsi), %rax
movslq 0x95720(%rdi,%rax,4), %r13
movsbq 0x43f8(%rdi,%rax), %rcx
movq %rcx, 0x20(%rsp)
decl %edx
movslq %edx, %rdx
movq %rdx, (%rsp)
imulq $0xae0, %rdx, %rcx      # imm = 0xAE0
leaq (%rdi,%rcx), %r15
addq $0x98738, %r15          # imm = 0x98738
leaq 0x4748(%rdi), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x230c7(%rip), %r12     # 0x768bc
xorl %ebp, %ebp
movq %r8, 0x10(%rsp)
movl %ebp, %ecx
movl %eax, %ebp
movslq %eax, %rbx
movb $0x0, 0x43f8(%r14,%rbx)
movb $0x1, 0x96ce0(%r14,%rbx)
cmpl $0x0, (%r15,%rbx,4)
jne 0x5382f
movslq %ecx, %rax
movl (%r15,%rax,4), %ecx
cmpl %ebp, %ecx
jl 0x5381c
movl %ecx, (%r15,%rbx,4)
movl %ebp, (%r15,%rax,4)
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x4e48f
movq %rbx, %rax
shlq $0x5, %rax
addq 0x22707(%rip), %rax     # 0x75f50
movq 0x20(%rsp), %rdx
movq (%rax,%rdx,8), %rcx
xorq %rcx, 0x43d0(%r14)
movq (%rax,%rdx,8), %rax
xorq %rax, 0x43e8(%r14)
movslq (%r12), %rax
movq %rbx, %rcx
subq %rax, %rcx
movslq 0x95720(%r14,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x10(%rsp), %r8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x538b6
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%rbx,2)
jne 0x538b6
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x5389a
movw %si, 0x8(%rax,%rbx,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x9571c(%r14,%rbx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x538f9
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%rbx,2)
jne 0x538f9
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x538dd
movw %si, 0x8(%rax,%rbx,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x95724(%r14,%rbx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x5393c
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%rbx,2)
jne 0x5393c
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x53920
movw %si, 0x8(%rax,%rbx,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq (%r12), %rax
addq %rbx, %rax
movslq 0x95720(%r14,%rax,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x53986
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%rbx,2)
jne 0x53986
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x5396a
movw %si, 0x8(%rax,%rbx,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movl 0x96200(%r14,%rbx,4), %eax
xorl %ecx, %ecx
movl %ecx, 0x96200(%r14,%rbx,4)
movl %ecx, 0x95720(%r14,%rbx,4)
cmpl $0x2b7, %eax            # imm = 0x2B7
jne 0x537fc
movq 0x8(%rsp), %rdi
movzwl 0x57c(%rdi), %eax
cmpl $0x11f, %eax            # imm = 0x11F
je 0x53a18
movswq %ax, %rax
imulq $0x7c8, %rax, %rcx      # imm = 0x7C8
addq %r8, %rcx
cmpw $0x0, 0x57c(%rcx,%r13,2)
je 0x53a0e
xorl %edx, %edx
movslq %edx, %rsi
movswl 0x57c(%rcx,%rsi,2), %edx
cmpl %edx, %r13d
jne 0x539da
movslq %edx, %rdx
movzwl 0x57c(%rcx,%rdx,2), %edx
movw %dx, 0x57c(%rcx,%rsi,2)
movw $0x0, 0x57c(%rcx,%r13,2)
decl 0x578(%rcx)
movzwl 0x57c(%rdi,%rax,2), %eax
jmp 0x539b7
movl 0x7c0(%rdi), %eax
movq (%rsp), %rcx
addl %eax, 0x98728(%r14,%rcx,4)
movb $0x0, 0x7c4(%rdi)
movl 0x7c0(%rdi), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq