def revf64decode(rev):
    """Convert rev encoded by revf64encode back to the original rev

    >>> revs = [i + j for i in [0, 1 << 56] for j in range(2)] + [None]
    >>> encoded = [revf64encode(i) for i in revs]
    >>> decoded = [revf64decode(i) for i in encoded]
    >>> revs == decoded
    True
    """
    if rev is not None and 0x1000000000000 <= rev < 0x100000000000000:
        rev += 0xFF000000000000
    return rev