// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x961d0, %rax          # imm = 0x961D0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x956f0, %rax          # imm = 0x956F0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x7bc(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
addq $0x43cc, %rax           # imm = 0x43CC
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x96cb0, %rax          # imm = 0x96CB0
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x7bc(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x4718, %rdi           # imm = 0x4718
movl -0x2c(%rbp), %esi
callq 0x90ae0
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %edx
leaq 0x4eca7(%rip), %rsi     # 0xe7a4c
subl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
testb $0x1, 0x7c4(%rax)
je 0x98df0
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
leaq 0x4ec79(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x99a30
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
testb $0x1, 0x7c4(%rax)
je 0x98e41
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x99a30
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
testb $0x1, 0x7c4(%rax)
je 0x98e92
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x99a30
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %edx
leaq 0x4eba8(%rip), %rsi     # 0xe7a4c
addl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
testb $0x1, 0x7c4(%rax)
je 0x98eef
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
leaq 0x4eb7a(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x99a30
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x2b7, -0x2c(%rbp)     # imm = 0x2B7
jne 0x98d68
movq -0x10(%rbp), %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x11f, -0x44(%rbp)     # imm = 0x11F
je 0x98f74
movq -0x18(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x99fe0
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x44(%rbp)
jmp 0x98f3c
movq -0x10(%rbp), %rax
movb $0x0, 0x7c4(%rax)
movq -0x10(%rbp), %rax
movl 0x7c0(%rax), %eax
addq $0x50, %rsp
popq %rbp
retq
nop