 }
 
 
-__device__ static void
-gpujpeg_huffman_gpu_encode_value(unsigned int & out_nbits, unsigned int & out_cword, const int preceding_zero_count, const int value,
+__device__ static unsigned int
+gpujpeg_huffman_gpu_encode_value(const int preceding_zero_count, const int value,
                                  const struct gpujpeg_table_huffman_encoder * const d_table) {
-    out_cword = value;
+    unsigned int out_cword = value;
     int absolute = value;
     if ( value < 0 ) {
         // valu eis now absolute value of input

    }
    
    // each thread gets codeword for its two pixels
    unsigned int even_code_size = 0, even_code_value = 0, odd_code_size = 0, odd_code_value = 0;
    if(nonzero_follows || !tid) {
        gpujpeg_huffman_gpu_encode_value(even_code_size, even_code_value, zeros_before_even & 0xf, in_even, d_table_even);
        gpujpeg_huffman_gpu_encode_value(odd_code_size, odd_code_value, zeros_before_odd & 0xf, in_odd, d_table_ac);
    }
    
    // last thread writes "end of block" value if last coefficient is zero
    if(tid == 31 && !in_odd) {
        odd_code_size = d_table_ac->size[256];
        odd_code_value = d_table_ac->code[256];
    }
    
    // concatenate both codewords into one if they are short enough
    if(even_code_size + odd_code_size < 27) {
        even_code_value = (even_code_value << odd_code_size) | odd_code_value;
        even_code_size += odd_code_size;
        odd_code_size = 0;
        odd_code_value = 0;
    }
    
    // each thread get number of preceding nonzero codewords and total number of nonzero codewords in this block
    const unsigned int even_codeword_presence = __ballot(even_code_size);
    const unsigned int odd_codeword_presence = __ballot(odd_code_size);
    const int codeword_offset = __popc(nonzero_mask & even_codeword_presence)
                              + __popc(nonzero_mask & odd_codeword_presence);
    
    // each thread saves its values into temporary shared buffer
    if(even_code_size) {
        s_out[remaining_codewords + codeword_offset] = even_code_size + (even_code_value << (32 - even_code_size));
        if(odd_code_size) {
            s_out[remaining_codewords + codeword_offset + 1] = odd_code_size + (odd_code_value << (32 - odd_code_size));
        }
    }
    

    }

    // Find the number of bits needed for the magnitude of the coefficient
    unsigned int out_nbits = 0;
    while ( absolute ) {
        out_nbits++;
        absolute >>= 1;
