// File: kobanium[P]Ray/src/board/String.cpp
// Function: PoRemoveString(game_info_t*, string_t*, int)
int
PoRemoveString( 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 *capture_pos = game->capture_pos[color - 1];
  int &capture_num = game->capture_num[color - 1];
  int *update_pos = game->update_pos[color - 1];
  int &update_num = game->update_num[color - 1];
  int lib, head = 0;

  // 隣接する連の呼吸点を更新の対象に加える
  neighbor = string->neighbor[0];
  while (neighbor != NEIGHBOR_END) {
    if (str[neighbor].libs < 3) {
      lib = str[neighbor].lib[0];
      while (lib != LIBERTY_END) {
        update_pos[update_num++] = lib;
        game->seki[lib] = false;
        lib = str[neighbor].lib[lib];
      }
    }
    neighbor = string->neighbor[neighbor];
  }

  do {
    // 空点に戻す
    board[pos] = S_EMPTY;
    // 候補手に追加する
    candidates[pos] = true;

    // レーティング更新対象に追加
    head = AddCapture(capture_pos, pos, head);

    // 3x3のパターンの更新
    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];
  }

  capture_num += string->size;

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %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 -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, -0x58(%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, -0x60(%rbp)
movq -0x8(%rbp), %rax
addq $0x99d00, %rax          # imm = 0x99D00
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x5a4, %rcx, %rcx      # imm = 0x5A4
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
addq $0x99cf8, %rax          # imm = 0x99CF8
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x78(%rbp)
movq -0x10(%rbp), %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x11f, -0x4c(%rbp)     # imm = 0x11F
je 0x9b2ec
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x3, 0x4(%rax)
jge 0x9b2d4
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x74(%rbp)
cmpl $0x2b7, -0x74(%rbp)     # imm = 0x2B7
je 0x9b2d2
movl -0x74(%rbp), %edx
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x74(%rbp), %rcx
movb $0x0, 0x97029(%rax,%rcx)
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x74(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x74(%rbp)
jmp 0x9b27f
jmp 0x9b2d4
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x4c(%rbp)
jmp 0x9b241
jmp 0x9b2ee
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 -0x58(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x78(%rbp), %edx
callq 0x9b000
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x34(%rbp), %esi
callq 0x90ae0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %edx
leaq 0x4c70f(%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 0x9b388
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
leaq 0x4c6e1(%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 0x9b3d9
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 0x9b42a
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 0x4c610(%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 0x9b487
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
leaq 0x4c5e2(%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 0x9b2ee
movq -0x10(%rbp), %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x11f, -0x4c(%rbp)     # imm = 0x11F
je 0x9b50c
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 0x9b4d4
movq -0x10(%rbp), %rax
movl 0x7c0(%rax), %ecx
movq -0x60(%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 $0x80, %rsp
popq %rbp
retq
nopl (%rax)