```\nfunction sliceUnchecked(bytes memory encoded, uint256 offset, uint256 length)\n    internal\n    pure\n    returns (bytes memory ret, uint256 nextOffset)\n{\n    //bail early for degenerate case\n    if (length == 0) {\n        return (new bytes(0), offset);\n    }\n\n    assembly ("memory-safe") {\n        nextOffset := add(offset, length)\n        ret := mload(freeMemoryPtr)\n\n        /* snip: inline dev comments */\n\n        let shift := and(length, 31) //equivalent to `mod(length, 32)` but 2 gas cheaper\n        if iszero(shift) { shift := wordSize }\n\n        let dest := add(ret, shift)\n        let end := add(dest, length)\n        for { let src := add(add(encoded, shift), offset) } lt(dest, end) {\n            src := add(src, wordSize)\n            dest := add(dest, wordSize)\n        } { mstore(dest, mload(src)) }\n\n        mstore(ret, length)\n        //When compiling with --via-ir then normally allocated memory (i.e. via new) will have 32 byte\n        //  memory alignment and so we enforce the same memory alignment here.\n        mstore(freeMemoryPtr, and(add(dest, 31), not(31)))\n    }\n}\n```\n