// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r8
movq %rdi, %rbx
movl 0x8(%rsi), %eax
cmpl $0x1, 0x4(%rsi)
movl %edx, 0x20(%rsp)
jne 0x3aee
addl %eax, 0xc(%rbx)
jmp 0x3af1
addl %eax, 0x8(%rbx)
testl %eax, %eax
jle 0x3dc7
xorl %ebp, %ebp
movq %r8, 0x8(%rsp)
movzwl 0x10(%r8,%rbp,2), %eax
movl %eax, %r13d
shrl $0x8, %r13d
movl %eax, 0x4(%rsp)
movzbl %al, %r14d
movq (%rbx), %rax
movl 0x866e(%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 0x8655(%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 0x862d(%rip), %edx      # 0xc188
addl 0x4(%r8), %ecx
addl %edx, %ecx
addl $-0x3, %ecx
movslq %ecx, %rcx
leaq 0x8662(%rip), %rdx      # 0xc1d0
movq (%rdx,%rcx,8), %rcx
xorq %rcx, 0x10(%rbx)
movl 0x8610(%rip), %ecx      # 0xc18c
imull %r14d, %ecx
addl %r13d, %ecx
incl %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
testl %eax, %eax
je 0x3be1
cmpl (%r8), %eax
je 0x3be1
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3bb3
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3bb6
incl %edx
cmpl %edx, %ecx
jne 0x3ba0
xorl %r15d, %r15d
movzwl 0x4(%rsp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x580a
movq 0x8(%rsp), %r8
cmpl $-0x1, %eax
jne 0x3be1
movq %r15, %rdi
movl %r12d, %esi
callq 0x5830
movq 0x8(%rsp), %r8
leal 0x1(%r13), %edi
movq 0x20(%rbx), %rcx
movl 0x859d(%rip), %edx      # 0xc18c
imull %r14d, %edx
leal (%rdx,%r13), %eax
decl %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3c68
cmpl (%r8), %eax
je 0x3c68
addl %edi, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3c68
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3c30
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3c33
incl %edx
cmpl %edx, %ecx
jne 0x3c1d
xorl %r15d, %r15d
movzwl 0x4(%rsp), %esi
movq %rdi, %r12
movq %r15, %rdi
movl %esi, 0x18(%rsp)
callq 0x580a
movq %r12, %rdi
movq 0x8(%rsp), %r8
cmpl $-0x1, %eax
jne 0x3c68
movq %r15, %rdi
movl 0x18(%rsp), %esi
callq 0x5830
movq %r12, %rdi
movq 0x8(%rsp), %r8
leal -0x1(%r13), %r9d
movq 0x20(%rbx), %rcx
leal 0x1(%r14), %r12d
movl 0x8512(%rip), %edx      # 0xc18c
movl %edx, %eax
imull %r12d, %eax
addl %r13d, %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3d1f
cmpl (%r8), %eax
je 0x3d1f
imull %r14d, %edx
leal (%rdx,%rdi), %esi
movslq %esi, %rsi
cmpl (%rcx,%rsi,4), %eax
je 0x3d1f
addl %r9d, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3d1f
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3cd2
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3cd5
incl %edx
cmpl %edx, %ecx
jne 0x3cbf
xorl %r15d, %r15d
movzwl 0x4(%rsp), %esi
movq %rdi, 0x18(%rsp)
movq %r15, %rdi
movl %esi, 0x24(%rsp)
movl %r9d, 0x14(%rsp)
callq 0x580a
movl 0x14(%rsp), %r9d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r8
cmpl $-0x1, %eax
jne 0x3d1f
movq %r15, %rdi
movl 0x24(%rsp), %esi
callq 0x5830
movl 0x14(%rsp), %r9d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r8
movq 0x20(%rbx), %rcx
leal -0x1(%r14), %eax
movl 0x845f(%rip), %edx      # 0xc18c
imull %edx, %eax
addl %r13d, %eax
cltq
movl (%rcx,%rax,4), %eax
testl %eax, %eax
je 0x3db7
cmpl (%r8), %eax
je 0x3db7
imull %edx, %r14d
addl %r14d, %edi
movslq %edi, %rsi
cmpl (%rcx,%rsi,4), %eax
je 0x3db7
addl %r9d, %r14d
movslq %r14d, %rsi
cmpl (%rcx,%rsi,4), %eax
je 0x3db7
imull %r12d, %edx
addl %r13d, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x3db7
movl 0x1028(%rbx), %ecx
testl %ecx, %ecx
je 0x3d89
xorl %edx, %edx
movslq %edx, %rsi
movq 0x28(%rbx,%rsi,8), %r15
cmpl %eax, (%r15)
je 0x3d8c
incl %edx
cmpl %edx, %ecx
jne 0x3d76
xorl %r15d, %r15d
movzwl 0x4(%rsp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x580a
movq 0x8(%rsp), %r8
cmpl $-0x1, %eax
jne 0x3db7
movq %r15, %rdi
movl %r12d, %esi
callq 0x5830
movq 0x8(%rsp), %r8
incq %rbp
movslq 0x8(%r8), %rax
cmpq %rax, %rbp
jl 0x3b00
movq %r8, %rdi
movq %r8, %r14
callq 0x57f8
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