Fix for C code mismatch

This patch is for fix the the binary mismatch in encoded output introduced during
refactorizaton of the transform/quant path. Basically it is original version of
code to make sure all valid inputs are copied in input buffer, in other hand
it is not fully optimized code but this patch is quick fix for the problem and
allow us to optimze one function at a time.