// File: /workspace/github_cpp_makefile_star2_O1/kobanium[P]Ray/src/board/SearchBoard.cpp
// Function: RemoveString(search_game_info_t*, string_t*)
static int
RemoveString( search_game_info_t *game, string_t *string )
{
  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];

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

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

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

    // 上下左右を確認する
    // 隣接する連があれば呼吸点を追加する
    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];
  }

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
leaq 0x95f0(%rdi), %r13
movq %rsi, 0x8(%rsp)
movslq 0x7bc(%rsi), %rbx
movslq 0x956f0(%rdi,%rbx,4), %rbp
leaq 0x4718(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x2344b(%rip), %r15     # 0x758bc
movslq %ebx, %r12
movb $0x0, 0x43cc(%r14,%r12)
movb $0x1, 0x96cb0(%r14,%r12)
movq 0x10(%rsp), %rdi
movl %r12d, %esi
callq 0x4df88
movslq (%r15), %rax
movq %r12, %rcx
subq %rax, %rcx
movslq 0x956f0(%r14,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r13,%rax)
jne 0x524e2
addq %r13, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x524e2
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebx
jg 0x524c4
movw %si, 0x8(%rax,%r12,2)
movw %r12w, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x956ec(%r14,%r12,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r13,%rax)
jne 0x52528
addq %r13, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x52528
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebx
jg 0x5250a
movw %si, 0x8(%rax,%r12,2)
movw %r12w, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x956f4(%r14,%r12,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r13,%rax)
jne 0x5256e
addq %r13, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x5256e
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebx
jg 0x52550
movw %si, 0x8(%rax,%r12,2)
movw %r12w, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq (%r15), %rax
addq %r12, %rax
movslq 0x956f0(%r14,%rax,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r13,%rax)
jne 0x525ba
addq %r13, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x525ba
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebx
jg 0x5259c
movw %si, 0x8(%rax,%r12,2)
movw %r12w, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movl 0x961d0(%r14,%r12,4), %ebx
xorl %eax, %eax
movl %eax, 0x961d0(%r14,%r12,4)
movl %eax, 0x956f0(%r14,%r12,4)
cmpl $0x2b7, %ebx            # imm = 0x2B7
jne 0x52471
movq 0x8(%rsp), %rdi
movzwl 0x57c(%rdi), %eax
cmpl $0x11f, %eax            # imm = 0x11F
je 0x5264a
movswq %ax, %rax
imulq $0x7c8, %rax, %rcx      # imm = 0x7C8
addq %r13, %rcx
cmpw $0x0, 0x57c(%rcx,%rbp,2)
je 0x52640
xorl %edx, %edx
movslq %edx, %rsi
movswl 0x57c(%rcx,%rsi,2), %edx
cmpl %edx, %ebp
jne 0x5260e
movslq %edx, %rdx
movzwl 0x57c(%rcx,%rdx,2), %edx
movw %dx, 0x57c(%rcx,%rsi,2)
movw $0x0, 0x57c(%rcx,%rbp,2)
decl 0x578(%rcx)
movzwl 0x57c(%rdi,%rax,2), %eax
jmp 0x525ec
movb $0x0, 0x7c4(%rdi)
movl 0x7c0(%rdi), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq