// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
leaq 0x9620(%rdi), %rbp
movslq 0x7bc(%rsi), %rax
movl 0x95720(%rdi,%rax,4), %r10d
decl %edx
movslq %edx, %r15
imulq $0x5a4, %r15, %rcx      # imm = 0x5A4
addq %rdi, %rcx
addq $0x99d00, %rcx          # imm = 0x99D00
movq %rsi, 0x10(%rsp)
leaq 0x57c(%rsi), %r12
movq %r12, %rdx
movswq (%rdx), %rdx
cmpq $0x11f, %rdx            # imm = 0x11F
je 0x3aaee
imulq $0x7c8, %rdx, %rsi      # imm = 0x7C8
cmpl $0x2, 0x4(%rbp,%rsi)
jg 0x3aae8
addq %rbp, %rsi
addq $0x8, %rsi
movq %rsi, %rdi
movswl (%rdi), %edi
cmpl $0x2b7, %edi            # imm = 0x2B7
je 0x3aae8
movslq 0x99cf8(%r14,%r15,4), %r8
leal 0x1(%r8), %r9d
movl %r9d, 0x99cf8(%r14,%r15,4)
movl %edi, (%rcx,%r8,4)
movslq %edi, %rdi
movb $0x0, 0x97029(%r14,%rdi)
leaq (%rsi,%rdi,2), %rdi
jmp 0x3aab3
leaq (%r12,%rdx,2), %rdx
jmp 0x3aa8e
movl %r10d, 0xc(%rsp)
imulq $0xae0, %r15, %rcx      # imm = 0xAE0
addq %r14, %rcx
addq $0x98738, %rcx          # imm = 0x98738
movq %rcx, 0x20(%rsp)
leaq 0x4748(%r14), %rcx
movq %rcx, 0x18(%rsp)
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 0x18(%rsp), %rdi
movl %ebx, %esi
callq 0x36555
leaq 0x26d6a(%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 0x3ab81
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 0x3aba7
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 0x3abcd
addq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3a3aa
leaq 0x26ce8(%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 0x3ac00
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 0x3ab18
movq %r12, %rax
movl 0xc(%rsp), %r13d
movswq (%rax), %rbx
cmpq $0x11f, %rbx            # imm = 0x11F
je 0x3ac52
imulq $0x7c8, %rbx, %rdi      # imm = 0x7C8
addq %rbp, %rdi
movl %r13d, %esi
callq 0x3aa00
leaq (%r12,%rbx,2), %rax
jmp 0x3ac2d
movq 0x10(%rsp), %rcx
movl 0x7c0(%rcx), %eax
addl %eax, 0x98728(%r14,%r15,4)
movb $0x0, 0x7c4(%rcx)
movl 0x7c0(%rcx), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)