// File: /workspace/github_cpp_makefile_star2_O1/jeffreyan11[P]go-engine/board.cpp
// Function: Board::captureChain(Chain*, int)
void Board::captureChain(Chain *node, int nodeIndex) {
    Player victim = node->color;
    if (victim == BLACK)
        whiteCaptures += node->size;
    else
        blackCaptures += node->size;

    for (int i = 0; i < node->size; i++) {
        int rx = getX(node->squares[i]);
        int ry = getY(node->squares[i]);
        pieces[index(rx, ry)] = EMPTY;
        chainID[index(rx, ry)] = 0;
        zobristKey ^= zobristTable[zobristIndex(node->color, rx, ry)];

        // Add this square to adjacent chains' liberties
        int addID = chainID[index(rx+1, ry)];
        if (addID
         && addID != node->id) {
            Chain *temp = nullptr;
            searchChainsByID(temp, addID);

            if (temp->findLiberty(coordToMove(rx, ry)) == -1)
                temp->addLiberty(coordToMove(rx, ry));
        }

        addID = chainID[index(rx-1, ry)];
        if (addID
         && addID != node->id
         && addID != chainID[index(rx+1, ry)]) {
            Chain *temp = nullptr;
            searchChainsByID(temp, addID);

            if (temp->findLiberty(coordToMove(rx, ry)) == -1)
                temp->addLiberty(coordToMove(rx, ry));
        }

        addID = chainID[index(rx, ry+1)];
        if (addID
         && addID != node->id
         && addID != chainID[index(rx+1, ry)]
         && addID != chainID[index(rx-1, ry)]) {
            Chain *temp = nullptr;
            searchChainsByID(temp, addID);

            if (temp->findLiberty(coordToMove(rx, ry)) == -1)
                temp->addLiberty(coordToMove(rx, ry));
        }

        addID = chainID[index(rx, ry-1)];
        if (addID
         && addID != node->id
         && addID != chainID[index(rx+1, ry)]
         && addID != chainID[index(rx-1, ry)]
         && addID != chainID[index(rx, ry+1)]) {
            Chain *temp = nullptr;
            searchChainsByID(temp, addID);

            if (temp->findLiberty(coordToMove(rx, ry)) == -1)
                temp->addLiberty(coordToMove(rx, ry));
        }
    }

    // Remove this chain since it has been captured
    delete node;
    chainList.removeFast(nodeIndex);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl 0x8(%rsi), %eax
cmpl $0x1, 0x4(%rsi)
movl %edx, 0x20(%rsp)
jne 0x3afd
addl %eax, 0xc(%rbx)
jmp 0x3b00
addl %eax, 0x8(%rbx)
cmpl $0x0, 0x8(%rsi)
jle 0x3dd4
xorl %ebp, %ebp
movq %rsi, 0x8(%rsp)
movzwl 0x10(%rsi,%rbp,2), %eax
movl %eax, %r13d
shrl $0x8, %r13d
movl %eax, 0x4(%rsp)
movzbl %al, %r14d
movq (%rbx), %rax
movl 0x865e(%rip), %ecx      # 0xc18c
imull %r14d, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
xorl %edx, %edx
movl %edx, (%rax,%rcx,4)
movq 0x20(%rbx), %rax
movl 0x8645(%rip), %ecx      # 0xc18c
imull %r14d, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
leal (,%r13,2), %ecx
leal -0x2(,%r14,2), %edx
imull 0x861d(%rip), %edx      # 0xc188
addl 0x4(%rsi), %ecx
addl %edx, %ecx
addl $-0x3, %ecx
movslq %ecx, %rcx
leaq 0x8653(%rip), %rdx      # 0xc1d0
movq (%rdx,%rcx,8), %rcx
xorq %rcx, 0x10(%rbx)
movl 0x8601(%rip), %ecx      # 0xc18c
imull %r14d, %ecx
addl %r13d, %ecx
incl %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
testl %eax, %eax
je 0x3bef
cmpl (%rsi), %eax
je 0x3bef
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3bc1
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3bc4
incl %edx
cmpl %edx, %ecx
jne 0x3bae
xorl %r15d, %r15d
movzwl 0x4(%rsp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x586c
movq 0x8(%rsp), %rsi
cmpl $-0x1, %eax
jne 0x3bef
movq %r15, %rdi
movl %r12d, %esi
callq 0x5892
movq 0x8(%rsp), %rsi
leal 0x1(%r13), %r8d
movq 0x20(%rbx), %rcx
movl 0x858f(%rip), %edx      # 0xc18c
imull %r14d, %edx
leal (%rdx,%r13), %eax
decl %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3c76
cmpl (%rsi), %eax
je 0x3c76
addl %r8d, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3c76
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3c3e
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3c41
incl %edx
cmpl %edx, %ecx
jne 0x3c2b
xorl %r15d, %r15d
movzwl 0x4(%rsp), %esi
movq %r15, %rdi
movl %esi, 0x18(%rsp)
movq %r8, %r12
callq 0x586c
movq %r12, %r8
movq 0x8(%rsp), %rsi
cmpl $-0x1, %eax
jne 0x3c76
movq %r15, %rdi
movl 0x18(%rsp), %esi
callq 0x5892
movq %r12, %r8
movq 0x8(%rsp), %rsi
leal -0x1(%r13), %r9d
movq 0x20(%rbx), %rcx
leal 0x1(%r14), %r12d
movl 0x8504(%rip), %edx      # 0xc18c
movl %edx, %eax
imull %r12d, %eax
addl %r13d, %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3d2d
cmpl (%rsi), %eax
je 0x3d2d
imull %r14d, %edx
leal (%rdx,%r8), %edi
movslq %edi, %rdi
cmpl (%rcx,%rdi,4), %eax
je 0x3d2d
addl %r9d, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3d2d
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3ce0
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3ce3
incl %edx
cmpl %edx, %ecx
jne 0x3ccd
xorl %r15d, %r15d
movzwl 0x4(%rsp), %esi
movq %r15, %rdi
movl %esi, 0x24(%rsp)
movq %r8, 0x18(%rsp)
movl %r9d, 0x14(%rsp)
callq 0x586c
movl 0x14(%rsp), %r9d
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rsi
cmpl $-0x1, %eax
jne 0x3d2d
movq %r15, %rdi
movl 0x24(%rsp), %esi
callq 0x5892
movl 0x14(%rsp), %r9d
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rsi
movq 0x20(%rbx), %rcx
leal -0x1(%r14), %eax
movl 0x8451(%rip), %edx      # 0xc18c
imull %edx, %eax
addl %r13d, %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3dc4
cmpl (%rsi), %eax
je 0x3dc4
imull %edx, %r14d
addl %r14d, %r8d
movslq %r8d, %rdi
cmpl (%rcx,%rdi,4), %eax
je 0x3dc4
addl %r9d, %r14d
movslq %r14d, %rdi
cmpl (%rcx,%rdi,4), %eax
je 0x3dc4
imull %r12d, %edx
addl %r13d, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3dc4
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3d96
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3d99
incl %edx
cmpl %edx, %ecx
jne 0x3d83
xorl %r15d, %r15d
movzwl 0x4(%rsp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x586c
movq 0x8(%rsp), %rsi
cmpl $-0x1, %eax
jne 0x3dc4
movq %r15, %rdi
movl %r12d, %esi
callq 0x5892
movq 0x8(%rsp), %rsi
incq %rbp
movslq 0x8(%rsi), %rax
cmpq %rax, %rbp
jl 0x3b11
testq %rsi, %rsi
je 0x3df1
movq %rsi, %rdi
movq %rsi, %r14
callq 0x585a
movl $0x610, %esi            # imm = 0x610
movq %r14, %rdi
callq 0x21c0
movl 0x1028(%rbx), %eax
decl %eax
movq 0x28(%rbx,%rax,8), %rcx
movslq 0x20(%rsp), %rdx
movq %rcx, 0x28(%rbx,%rdx,8)
movl %eax, 0x1028(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop