Code:
static const int32_t lut_code[19] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,-1, 0, 0};
static const uint32_t lut_base_repeats[19] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 11};
static const uint32_t lut_extra_bits[19] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
static int read_in_symbol_lengths(struct Inflate_data *d, struct Huff_node *code_tree,
struct Codetable_entry *table, size_t table_len) {
uint32_t current_code = 0, i = 0;
for(i = 0; i < table_len; i++)
table[i].length = 0;
i = 0;
while(i < table_len) {
uint32_t t = grab_bits(d);
uint32_t s = symbol_decode(code_tree,t);
consume_bits(d,s>>24);
s &=0xFF;
int32_t new_code = lut_code[s];
uint32_t repeat = lut_base_repeats[s];
uint32_t extra_bits = lut_extra_bits[s];
uint32_t mask = (1<<extra_bits)-1;
if(new_code != -1)
current_code = new_code;
if(extra_bits > 0) {
repeat += grab_bits(d) & mask;
consume_bits(d,extra_bits);
}
while(repeat > 0 && i <= table_len) {
table[i].length = current_code;
i++; repeat--;
}
}
return 1;
}