def fixup(p, data_bits, ptr_bits, bits_set):
    """
    Flip back the pointer qubits that were previously flipped indicated by
    the flags `bits_set`.
    """
    for i in range(ptr_bits):
        if 0 != bits_set & (1 << i):
            p.inst(X(data_bits + i))