 +					return ERROR(GENERIC);
 +				norm[s] = (short)weight;
 +				tmpTotal = end;
-+	}   }   }
++			}
++		}
++	}
 +
 +	return 0;
 +}
 +
-+
-+size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
-+						   const unsigned* count, size_t total,
-+						   unsigned maxSymbolValue)
++size_t FSE_normalizeCount(short *normalizedCounter, unsigned tableLog, const unsigned *count, size_t total, unsigned maxSymbolValue)
 +{
 +	/* Sanity checks */
-+	if (tableLog==0) tableLog = FSE_DEFAULT_TABLELOG;
-+	if (tableLog < FSE_MIN_TABLELOG) return ERROR(GENERIC);   /* Unsupported size */
-+	if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);   /* Unsupported size */
-+	if (tableLog < FSE_minTableLog(total, maxSymbolValue)) return ERROR(GENERIC);   /* Too small tableLog, compression potentially impossible */
-+
-+	{	U32 const rtbTable[] = {     0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
++	if (tableLog == 0)
++		tableLog = FSE_DEFAULT_TABLELOG;
++	if (tableLog < FSE_MIN_TABLELOG)
++		return ERROR(GENERIC); /* Unsupported size */
++	if (tableLog > FSE_MAX_TABLELOG)
++		return ERROR(tableLog_tooLarge); /* Unsupported size */
++	if (tableLog < FSE_minTableLog(total, maxSymbolValue))
++		return ERROR(GENERIC); /* Too small tableLog, compression potentially impossible */
++
++	{
++		U32 const rtbTable[] = {0, 473195, 504333, 520860, 550000, 700000, 750000, 830000};
 +		U64 const scale = 62 - tableLog;
-+		U64 const step = ((U64)1<<62) / total;   /* <== here, one division ! */
-+		U64 const vStep = 1ULL<<(scale-20);
-+		int stillToDistribute = 1<<tableLog;
++		U64 const step = ((U64)1 << 62) / total; /* <== here, one division ! */
++		U64 const vStep = 1ULL << (scale - 20);
++		int stillToDistribute = 1 << tableLog;
 +		unsigned s;
-+		unsigned largest=0;
-+		short largestP=0;
++		unsigned largest = 0;
++		short largestP = 0;
 +		U32 lowThreshold = (U32)(total >> tableLog);
 +
-+		for (s=0; s<=maxSymbolValue; s++) {
-+			if (count[s] == total) return 0;   /* rle special case */
-+			if (count[s] == 0) { normalizedCounter[s]=0; continue; }
++		for (s = 0; s <= maxSymbolValue; s++) {
++			if (count[s] == total)
++				return 0; /* rle special case */
++			if (count[s] == 0) {
++				normalizedCounter[s] = 0;
++				continue;
++			}
 +			if (count[s] <= lowThreshold) {
 +				normalizedCounter[s] = -1;
 +				stillToDistribute--;
 +			} else {
-+				short proba = (short)((count[s]*step) >> scale);
-+				if (proba<8) {
++				short proba = (short)((count[s] * step) >> scale);
++				if (proba < 8) {
 +					U64 restToBeat = vStep * rtbTable[proba];
-+					proba += (count[s]*step) - ((U64)proba<<scale) > restToBeat;
++					proba += (count[s] * step) - ((U64)proba << scale) > restToBeat;
 +				}
-+				if (proba > largestP) largestP=proba, largest=s;
++				if (proba > largestP)
++					largestP = proba, largest = s;
 +				normalizedCounter[s] = proba;
 +				stillToDistribute -= proba;
-+		}   }
++			}
++		}
 +		if (-stillToDistribute >= (normalizedCounter[largest] >> 1)) {
 +			/* corner case, need another normalization method */
 +			size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue);
-+			if (FSE_isError(errorCode)) return errorCode;
-+		}
-+		else normalizedCounter[largest] += (short)stillToDistribute;
++			if (FSE_isError(errorCode))
++				return errorCode;
++		} else
++			normalizedCounter[largest] += (short)stillToDistribute;
 +	}
 +
 +	return tableLog;
 +}
 +
-+
 +/* fake FSE_CTable, for raw (uncompressed) input */
-+size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits)
++size_t FSE_buildCTable_raw(FSE_CTable *ct, unsigned nbBits)
 +{
 +	const unsigned tableSize = 1 << nbBits;
 +	const unsigned tableMask = tableSize - 1;
 +	const unsigned maxSymbolValue = tableMask;
-+	void* const ptr = ct;
-+	U16* const tableU16 = ( (U16*) ptr) + 2;
-+	void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableSize>>1);   /* assumption : tableLog >= 1 */
-+	FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
++	void *const ptr = ct;
++	U16 *const tableU16 = ((U16 *)ptr) + 2;
++	void *const FSCT = ((U32 *)ptr) + 1 /* header */ + (tableSize >> 1); /* assumption : tableLog >= 1 */
++	FSE_symbolCompressionTransform *const symbolTT = (FSE_symbolCompressionTransform *)(FSCT);
 +	unsigned s;
 +
 +	/* Sanity checks */
-+	if (nbBits < 1) return ERROR(GENERIC);             /* min size */
++	if (nbBits < 1)
++		return ERROR(GENERIC); /* min size */
 +
 +	/* header */
-+	tableU16[-2] = (U16) nbBits;
-+	tableU16[-1] = (U16) maxSymbolValue;
++	tableU16[-2] = (U16)nbBits;
++	tableU16[-1] = (U16)maxSymbolValue;
 +
 +	/* Build table */
-+	for (s=0; s<tableSize; s++)
++	for (s = 0; s < tableSize; s++)
 +		tableU16[s] = (U16)(tableSize + s);
 +
 +	/* Build Symbol Transformation Table */
-+	{	const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits);
-+		for (s=0; s<=maxSymbolValue; s++) {
++	{
++		const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits);
++		for (s = 0; s <= maxSymbolValue; s++) {
 +			symbolTT[s].deltaNbBits = deltaNbBits;
-+			symbolTT[s].deltaFindState = s-1;
-+	}   }
++			symbolTT[s].deltaFindState = s - 1;
++		}
++	}
 +
 +	return 0;
 +}
 +
 +/* fake FSE_CTable, for rle input (always same symbol) */
-+size_t FSE_buildCTable_rle (FSE_CTable* ct, BYTE symbolValue)
-+{
-+	void* ptr = ct;
-+	U16* tableU16 = ( (U16*) ptr) + 2;
-+	void* FSCTptr = (U32*)ptr + 2;
-+	FSE_symbolCompressionTransform* symbolTT = (FSE_symbolCompressionTransform*) FSCTptr;
++size_t FSE_buildCTable_rle(FSE_CTable *ct, BYTE symbolValue)
++{
++	void *ptr = ct;
++	U16 *tableU16 = ((U16 *)ptr) + 2;
++	void *FSCTptr = (U32 *)ptr + 2;
++	FSE_symbolCompressionTransform *symbolTT = (FSE_symbolCompressionTransform *)FSCTptr;
 +
 +	/* header */
-+	tableU16[-2] = (U16) 0;
-+	tableU16[-1] = (U16) symbolValue;
++	tableU16[-2] = (U16)0;
++	tableU16[-1] = (U16)symbolValue;
 +
 +	/* Build table */
 +	tableU16[0] = 0;
-+	tableU16[1] = 0;   /* just in case */
++	tableU16[1] = 0; /* just in case */
 +
 +	/* Build Symbol Transformation Table */
 +	symbolTT[symbolValue].deltaNbBits = 0;

+#define FSE_PUBLIC_API
+
+/*------   Version   ------*/
+#define FSE_VERSION_MAJOR    0
+#define FSE_VERSION_MINOR    9
+#define FSE_VERSION_RELEASE  0
+
+#define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE
+#define FSE_QUOTE(str) #str
+#define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str)
+#define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION)
+
+#define FSE_VERSION_NUMBER  (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE)
+FSE_PUBLIC_API unsigned FSE_versionNumber(void);   /**< library version number; to be used when checking dll version */
+
+/*-*****************************************
+*  Tool functions
+******************************************/
+FSE_PUBLIC_API size_t FSE_compressBound(size_t size);       /* maximum compressed size */
+
+/* Error Management */
+FSE_PUBLIC_API unsigned    FSE_isError(size_t code);        /* tells if a return value is an error code */
+
+
+/*-*****************************************
+*  FSE detailed API

+ *  On 64-bits, maxNbBits==56.
+ *  @return : value extracted
+ */
+ZSTD_STATIC size_t BIT_lookBits(const BIT_DStream_t *bitD, U32 nbBits)
+{
+	U32 const bitMask = sizeof(bitD->bitContainer) * 8 - 1;
+	return ((bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> 1) >> ((bitMask - nbBits) & bitMask);
+}
+
+/*! BIT_lookBitsFast() :
+*   unsafe version; only works only if nbBits >= 1 */
+ZSTD_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t *bitD, U32 nbBits)
+{
+	U32 const bitMask = sizeof(bitD->bitContainer) * 8 - 1;
+	return (bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> (((bitMask + 1) - nbBits) & bitMask);
+}
+
+ZSTD_STATIC void BIT_skipBits(BIT_DStream_t *bitD, U32 nbBits) { bitD->bitsConsumed += nbBits; }
+
+/*! BIT_readBits() :
+ *  Read (consume) next n bits from local register and update.
+ *  Pay attention to not read more than nbBits contained into local register.
+ *  @return : extracted value.
+ */
+ZSTD_STATIC size_t BIT_readBits(BIT_DStream_t *bitD, U32 nbBits)
+{
+	size_t const value = BIT_lookBits(bitD, nbBits);
+	BIT_skipBits(bitD, nbBits);
