// File: /workspace/github_cpp_makefile_star2_O2/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), %rbp
movq %rsi, 0x18(%rsp)
movslq 0x7bc(%rsi), %rax
movl 0x95720(%rdi,%rax,4), %ecx
movl %ecx, 0xc(%rsp)
movsbq 0x43f8(%rdi,%rax), %r15
decl %edx
movslq %edx, %rdx
movq %rdx, 0x10(%rsp)
imulq $0xae0, %rdx, %rcx      # imm = 0xAE0
addq %rdi, %rcx
addq $0x98738, %rcx          # imm = 0x98738
movq %rcx, 0x20(%rsp)
leaq 0x4748(%rdi), %r12
xorl %r13d, %r13d
movl %r13d, %edx
movl %eax, %r13d
movslq %eax, %rbx
movb $0x0, 0x43f8(%r14,%rbx)
movb $0x1, 0x96ce0(%r14,%rbx)
movq 0x20(%rsp), %rdi
movl %ebx, %esi
callq 0x3a9e3
movq %r12, %rdi
movl %ebx, %esi
callq 0x3671f
movq %rbx, %rax
shlq $0x5, %rax
addq 0x266ec(%rip), %rax     # 0x60f70
movq (%rax,%r15,8), %rcx
xorq %rcx, 0x43d0(%r14)
movq (%rax,%r15,8), %rax
xorq %rax, 0x43e8(%r14)
leaq 0x2701b(%rip), %rax     # 0x618bc
movslq (%rax), %rax
movq %rbx, %rcx
subq %rax, %rcx
movslq 0x95720(%r14,%rcx,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbp,%rdi)
jne 0x3a8d0
addq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3a3aa
movslq 0x9571c(%r14,%rbx,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbp,%rdi)
jne 0x3a8f6
addq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3a3aa
movslq 0x95724(%r14,%rbx,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbp,%rdi)
jne 0x3a91c
addq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3a3aa
leaq 0x26f99(%rip), %rax     # 0x618bc
movslq (%rax), %rax
addq %rbx, %rax
movslq 0x95720(%r14,%rax,4), %rax
imulq $0x7c8, %rax, %rdi      # imm = 0x7C8
cmpb $0x1, 0x7c4(%rbp,%rdi)
jne 0x3a94f
addq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3a3aa
movl 0x96200(%r14,%rbx,4), %eax
andl $0x0, 0x96200(%r14,%rbx,4)
andl $0x0, 0x95720(%r14,%rbx,4)
cmpl $0x2b7, %eax            # imm = 0x2B7
jne 0x3a845
movq 0x18(%rsp), %r12
leaq 0x57c(%r12), %rbx
movq %rbx, %rax
movl 0xc(%rsp), %r13d
movswq (%rax), %r15
cmpq $0x11f, %r15            # imm = 0x11F
je 0x3a9ae
imulq $0x7c8, %r15, %rdi      # imm = 0x7C8
addq %rbp, %rdi
movl %r13d, %esi
callq 0x3aa00
leaq (%rbx,%r15,2), %rax
jmp 0x3a989
movl 0x7c0(%r12), %eax
movq 0x10(%rsp), %rcx
addl %eax, 0x98728(%r14,%rcx,4)
movb $0x0, 0x7c4(%r12)
movl 0x7c0(%r12), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq