// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x18(%rbp)
jne 0x4ea1
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
jmp 0x4eb2
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x539a
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzwl 0x10(%rax,%rcx,2), %edi
callq 0x8b80
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzwl 0x10(%rax,%rcx,2), %edi
callq 0x8ba0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, -0x24(%rbp)
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0x68(%rbp), %rcx
movl %eax, %edx
movq -0x50(%rbp), %rax
movslq %edx, %rdx
movl $0x0, (%rcx,%rdx,4)
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x8be0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rdx
leaq 0xf2cc(%rip), %rcx      # 0x14230
movq (%rcx,%rdx,8), %rcx
xorq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %edi
addl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x5003
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x5003
movq -0x50(%rbp), %rdi
movq $0x0, -0x30(%rbp)
movl -0x28(%rbp), %edx
leaq -0x30(%rbp), %rsi
callq 0x8c50
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0x70(%rbp), %rdi
movzwl %ax, %esi
callq 0x9400
cmpl $-0x1, %eax
jne 0x5001
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0x78(%rbp), %rdi
movzwl %ax, %esi
callq 0x9470
jmp 0x5003
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x20(%rbp), %edi
subl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x80(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x50eb
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x50eb
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0x84(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x20(%rbp), %edi
addl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0x90(%rbp), %rcx
movl %eax, %edx
movl -0x84(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x50eb
movq -0x50(%rbp), %rdi
movq $0x0, -0x38(%rbp)
movl -0x28(%rbp), %edx
leaq -0x38(%rbp), %rsi
callq 0x8c50
movq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0x98(%rbp), %rdi
movzwl %ax, %esi
callq 0x9400
cmpl $-0x1, %eax
jne 0x50e9
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0xa0(%rbp), %rdi
movzwl %ax, %esi
callq 0x9470
jmp 0x50eb
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa8(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
addl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x521a
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x521a
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0xac(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0xb8(%rbp)
movl -0x20(%rbp), %edi
addl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0xb8(%rbp), %rcx
movl %eax, %edx
movl -0xac(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x521a
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0xbc(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0xc8(%rbp)
movl -0x20(%rbp), %edi
subl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0xc8(%rbp), %rcx
movl %eax, %edx
movl -0xbc(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x521a
movq -0x50(%rbp), %rdi
movq $0x0, -0x40(%rbp)
movl -0x28(%rbp), %edx
leaq -0x40(%rbp), %rsi
callq 0x8c50
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0xd0(%rbp), %rdi
movzwl %ax, %esi
callq 0x9400
cmpl $-0x1, %eax
jne 0x5218
movq -0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0xd8(%rbp), %rdi
movzwl %ax, %esi
callq 0x9470
jmp 0x521a
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xe0(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
subl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x538a
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x538a
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0xe4(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0xf0(%rbp)
movl -0x20(%rbp), %edi
addl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0xf0(%rbp), %rcx
movl %eax, %edx
movl -0xe4(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x538a
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0xf4(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x100(%rbp)
movl -0x20(%rbp), %edi
subl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x8bc0
movq -0x100(%rbp), %rcx
movl %eax, %edx
movl -0xf4(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x538a
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, -0x104(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x110(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
addl $0x1, %esi
callq 0x8bc0
movq -0x110(%rbp), %rcx
movl %eax, %edx
movl -0x104(%rbp), %eax
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x538a
movq -0x50(%rbp), %rdi
movq $0x0, -0x48(%rbp)
movl -0x28(%rbp), %edx
leaq -0x48(%rbp), %rsi
callq 0x8c50
movq -0x48(%rbp), %rax
movq %rax, -0x118(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0x118(%rbp), %rdi
movzwl %ax, %esi
callq 0x9400
cmpl $-0x1, %eax
jne 0x5388
movq -0x48(%rbp), %rax
movq %rax, -0x120(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x8c30
movq -0x120(%rbp), %rdi
movzwl %ax, %esi
callq 0x9470
jmp 0x538a
jmp 0x538c
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4eb9
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x0, %rax
je 0x53c8
movq -0x128(%rbp), %rdi
callq 0x93c0
movq -0x128(%rbp), %rdi
movl $0x610, %esi            # imm = 0x610
callq 0x2210
movq -0x50(%rbp), %rdi
addq $0x28, %rdi
movl -0x14(%rbp), %esi
callq 0x8f40
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)