function decodeContextMap(contextMapSize, contextMap, s) {
    if (s.halfOffset > 2030) {
      doReadMoreInput(s);
    }
    let /** @type{number} */ numTrees = decodeVarLenUnsignedByte(s) + 1;
    if (numTrees == 1) {
      contextMap.fill(0, 0, contextMapSize);
      return numTrees;
    }
    if (s.bitOffset >= 16) {
      s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
      s.bitOffset -= 16;
    }
    let /** @type{number} */ useRleForZeros = readFewBits(s, 1);
    let /** @type{number} */ maxRunLengthPrefix = 0;
    if (useRleForZeros != 0) {
      maxRunLengthPrefix = readFewBits(s, 4) + 1;
    }
    let /** @type{number} */ alphabetSize = numTrees + maxRunLengthPrefix;
    let /** @type{number} */ tableSize = MAX_HUFFMAN_TABLE_SIZE[(alphabetSize + 31) >> 5];
    let /** @type{!Int32Array} */ table = new Int32Array(tableSize + 1);
    let /** @type{number} */ tableIdx = table.length - 1;
    readHuffmanCode(alphabetSize, alphabetSize, table, tableIdx, s);
    for (let /** @type{number} */ i = 0; i < contextMapSize; ) {
      if (s.halfOffset > 2030) {
        doReadMoreInput(s);
      }
      if (s.bitOffset >= 16) {
        s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
        s.bitOffset -= 16;
      }
      let /** @type{number} */ code = readSymbol(table, tableIdx, s);
      if (code == 0) {
        contextMap[i] = 0;
        i++;
      } else if (code <= maxRunLengthPrefix) {
        if (s.bitOffset >= 16) {
          s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
          s.bitOffset -= 16;
        }
        let /** @type{number} */ reps = (1 << code) + readFewBits(s, code);
        while (reps != 0) {
          if (i >= contextMapSize) {
            throw "Corrupted context map";
          }
          contextMap[i] = 0;
          i++;
          reps--;
        }
      } else {
        contextMap[i] = (code - maxRunLengthPrefix);
        i++;
      }
    }
    if (s.bitOffset >= 16) {
      s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
      s.bitOffset -= 16;
    }
    if (readFewBits(s, 1) == 1) {
      inverseMoveToFrontTransform(contextMap, contextMapSize);
    }
    return numTrees;
  }
@param {number} contextMapSize
@param {!Int8Array} contextMap
@param {!State} s
@return {number}