function copyFromCompoundDictionary(s, fence) {
    let /** @type{number} */ pos = s.pos;
    let /** @type{number} */ origPos = pos;
    while (s.cdBrLength != s.cdBrCopied) {
      let /** @type{number} */ space = fence - pos;
      let /** @type{number} */ chunkLength = s.cdChunkOffsets[s.cdBrIndex + 1] - s.cdChunkOffsets[s.cdBrIndex];
      let /** @type{number} */ remChunkLength = chunkLength - s.cdBrOffset;
      let /** @type{number} */ length = s.cdBrLength - s.cdBrCopied;
      if (length > remChunkLength) {
        length = remChunkLength;
      }
      if (length > space) {
        length = space;
      }
      copyBytes(s.ringBuffer, pos, s.cdChunks[s.cdBrIndex], s.cdBrOffset, s.cdBrOffset + length);
      pos += length;
      s.cdBrOffset += length;
      s.cdBrCopied += length;
      if (length == remChunkLength) {
        s.cdBrIndex++;
        s.cdBrOffset = 0;
      }
      if (pos >= fence) {
        break;
      }
    }
    return pos - origPos;
  }
@param {!State} s
@param {number} fence
@return {number}