  */
 __device__ int
 gpujpeg_huffman_gpu_encoder_encode_block(const int16_t * block, unsigned int * &data_compressed, unsigned int * const s_out,
-                int & remaining_codewords, int *last_dc, int tid,
+                int & remaining_codewords, const int last_dc_idx, int tid,
                 struct gpujpeg_table_huffman_encoder* d_table_dc, struct gpujpeg_table_huffman_encoder* d_table_ac)
 {
     // each thread loads a pair of values (pair after zigzag reordering)

    int warpidx = threadIdx.x >> 5;
    int tid = threadIdx.x & 31;

    __shared__ uint4 s_out_all[64 * WARPS_NUM];
    unsigned int * s_out = (unsigned int*)(s_out_all + warpidx * 64);
    
    // Number of remaining codewords in shared buffer
    int remaining_codewords = 0;

        // first thread uses DC table for its even value
        d_table_even = d_table_dc;
        
        // update last DC coefficient (saved at the special place at the end of the shared bufer)
        const int original_in_even = in_even;
        in_even -= ((int*)s_out)[last_dc_idx];
        ((int*)s_out)[last_dc_idx] = original_in_even;
    }
    
    // last thread handles special block-termination symbol
