// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x96200, %rax          # imm = 0x96200
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x7bc(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
addq $0x96ce0, %rax          # imm = 0x96CE0
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x7bc(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rax
addq $0x98738, %rax          # imm = 0x98738
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xae0, %rcx, %rcx      # imm = 0xAE0
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
addq $0x98728, %rax          # imm = 0x98728
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movq -0x60(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x6c(%rbp), %edx
callq 0x9b000
movl %eax, -0x6c(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x34(%rbp), %esi
callq 0x90f10
movslq -0x34(%rbp), %rcx
leaq 0x1c704108(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
xorq 0x43d0(%rax), %rcx
movq %rcx, 0x43d0(%rax)
movslq -0x34(%rbp), %rcx
leaq 0x1c7040dc(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
xorq 0x43e8(%rax), %rcx
movq %rcx, 0x43e8(%rax)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %edx
leaq 0x4cc55(%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 0x9ae42
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
leaq 0x4cc27(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x34(%rbp), %esi
xorl %edx, %edx
callq 0x9a3e0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%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 0x9ae93
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x34(%rbp), %esi
xorl %edx, %edx
callq 0x9a3e0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%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 0x9aee4
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x34(%rbp), %esi
xorl %edx, %edx
callq 0x9a3e0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %edx
leaq 0x4cb56(%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 0x9af41
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
leaq 0x4cb28(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x34(%rbp), %esi
xorl %edx, %edx
callq 0x9a3e0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x2b7, -0x34(%rbp)     # imm = 0x2B7
jne 0x9ad50
movq -0x10(%rbp), %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x11f, -0x4c(%rbp)     # imm = 0x11F
je 0x9afc6
movq -0x20(%rbp), %rdi
movslq -0x4c(%rbp), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rdi
movl -0x50(%rbp), %esi
callq 0x9b080
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x4c(%rbp)
jmp 0x9af8e
movq -0x10(%rbp), %rax
movl 0x7c0(%rax), %ecx
movq -0x68(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x7c4(%rax)
movq -0x10(%rbp), %rax
movl 0x7c0(%rax), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)