// File: /workspace/github_cpp_makefile_star2_O2/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), %rbx
movq %rsi, 0x10(%rsp)
movslq 0x7bc(%rsi), %r12
movl 0x956f0(%rdi,%r12,4), %eax
movl %eax, 0xc(%rsp)
leaq 0x4718(%rdi), %r15
leaq 0x27c7e(%rip), %rbp     # 0x618bc
movslq %r12d, %r13
movb $0x0, 0x43cc(%r14,%r13)
movb $0x1, 0x96cb0(%r14,%r13)
movq %r15, %rdi
movl %r13d, %esi
callq 0x36555
movslq (%rbp), %rax
movq %r13, %rcx
subq %rax, %rcx
movslq 0x956f0(%r14,%rcx,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbx,%rdi)
jne 0x39c8e
addq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3a1ae
movslq 0x956ec(%r14,%r13,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbx,%rdi)
jne 0x39cb4
addq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3a1ae
movslq 0x956f4(%r14,%r13,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbx,%rdi)
jne 0x39cda
addq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3a1ae
movslq (%rbp), %rax
addq %r13, %rax
movslq 0x956f0(%r14,%rax,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbx,%rdi)
jne 0x39d07
addq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3a1ae
movl 0x961d0(%r14,%r13,4), %r12d
andl $0x0, 0x961d0(%r14,%r13,4)
andl $0x0, 0x956f0(%r14,%r13,4)
cmpl $0x2b7, %r12d           # imm = 0x2B7
jne 0x39c3e
movq 0x10(%rsp), %r12
leaq 0x57c(%r12), %r14
movq %r14, %rax
movl 0xc(%rsp), %ebp
movswq (%rax), %r15
cmpq $0x11f, %r15            # imm = 0x11F
je 0x39d66
imulq $0x7c8, %r15, %rdi      # imm = 0x7C8
addq %rbx, %rdi
movl %ebp, %esi
callq 0x3a219
leaq (%r14,%r15,2), %rax
jmp 0x39d42
movb $0x0, 0x7c4(%r12)
movl 0x7c0(%r12), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq