// File: /workspace/github_cpp_makefile_star2_O1/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), %r8
movslq 0x7bc(%rsi), %rax
movslq 0x95720(%rdi,%rax,4), %r13
decl %edx
movslq %edx, %rbx
imulq $0xae0, %rbx, %rcx      # imm = 0xAE0
movzwl 0x57c(%rsi), %edi
cmpl $0x11f, %edi            # imm = 0x11F
movq %r8, 0x8(%rsp)
je 0x536fa
imulq $0x5a4, %rbx, %rdx      # imm = 0x5A4
addq %r14, %rdx
addq $0x99d00, %rdx          # imm = 0x99D00
movswq %di, %r11
imulq $0x7c8, %r11, %rdi      # imm = 0x7C8
cmpl $0x2, 0x4(%r8,%rdi)
jg 0x536e4
addq 0x8(%rsp), %rdi
movzwl 0x8(%rdi), %r8d
cmpl $0x2b7, %r8d            # imm = 0x2B7
je 0x536e4
movswl %r8w, %r8d
movslq 0x99cf8(%r14,%rbx,4), %r9
leal 0x1(%r9), %r10d
movl %r10d, 0x99cf8(%r14,%rbx,4)
movl %r8d, (%rdx,%r9,4)
movswq %r8w, %r8
movb $0x0, 0x97029(%r14,%r8)
movzwl 0x8(%rdi,%r8,2), %r8d
jmp 0x536aa
movzwl 0x57c(%rsi,%r11,2), %edi
cmpl $0x11f, %edi            # imm = 0x11F
movq 0x8(%rsp), %r8
jne 0x5368d
movq %rbx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
leaq (%r14,%rcx), %r15
addq $0x98738, %r15          # imm = 0x98738
leaq 0x4748(%r14), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x2219a(%rip), %rbx     # 0x758bc
xorl %ebp, %ebp
movl %ebp, %ecx
movl %eax, %ebp
movslq %eax, %r12
movb $0x0, 0x43f8(%r14,%r12)
movb $0x1, 0x96ce0(%r14,%r12)
cmpl $0x0, (%r15,%r12,4)
jne 0x53757
movslq %ecx, %rax
movl (%r15,%rax,4), %ecx
cmpl %ebp, %ecx
jl 0x53744
movl %ecx, (%r15,%r12,4)
movl %ebp, (%r15,%rax,4)
movq 0x20(%rsp), %rdi
movl %ebp, %esi
callq 0x4df88
movslq (%rbx), %rax
movq %r12, %rcx
subq %rax, %rcx
movslq 0x95720(%r14,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x8(%rsp), %r8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x537b6
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x537b6
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x53799
movw %si, 0x8(%rax,%r12,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x9571c(%r14,%r12,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x537fb
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x537fb
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x537de
movw %si, 0x8(%rax,%r12,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq 0x95724(%r14,%r12,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x53840
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x53840
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x53823
movw %si, 0x8(%rax,%r12,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movslq (%rbx), %rax
addq %r12, %rax
movslq 0x95720(%r14,%rax,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpb $0x1, 0x7c4(%r8,%rax)
jne 0x5388b
addq %r8, %rax
cmpw $0x0, 0x8(%rax,%r12,2)
jne 0x5388b
xorl %edx, %edx
movslq %edx, %rcx
movzwl 0x8(%rax,%rcx,2), %esi
movswl %si, %edx
cmpl %edx, %ebp
jg 0x5386e
movw %si, 0x8(%rax,%r12,2)
movw %bp, 0x8(%rax,%rcx,2)
incl 0x4(%rax)
movl 0x96200(%r14,%r12,4), %eax
xorl %ecx, %ecx
movl %ecx, 0x96200(%r14,%r12,4)
movl %ecx, 0x95720(%r14,%r12,4)
cmpl $0x2b7, %eax            # imm = 0x2B7
jne 0x53724
movq 0x18(%rsp), %rdi
movzwl 0x57c(%rdi), %eax
cmpl $0x11f, %eax            # imm = 0x11F
movq 0x10(%rsp), %r9
je 0x53927
movswq %ax, %rax
imulq $0x7c8, %rax, %rcx      # imm = 0x7C8
addq %r8, %rcx
cmpw $0x0, 0x57c(%rcx,%r13,2)
je 0x53918
xorl %edx, %edx
movslq %edx, %rsi
movswl 0x57c(%rcx,%rsi,2), %edx
cmpl %edx, %r13d
jne 0x538e4
movslq %edx, %rdx
movzwl 0x57c(%rcx,%rdx,2), %edx
movw %dx, 0x57c(%rcx,%rsi,2)
movw $0x0, 0x57c(%rcx,%r13,2)
decl 0x578(%rcx)
movzwl 0x57c(%rdi,%rax,2), %eax
cmpl $0x11f, %eax            # imm = 0x11F
jne 0x538c8
movl 0x7c0(%rdi), %eax
addl %eax, 0x98728(%r14,%r9,4)
movb $0x0, 0x7c4(%rdi)
movl 0x7c0(%rdi), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)