def decompress(block, min_code_size):
    clear_code = (1 << min_code_size)
    eoi_code = (clear_code + 1)
    cur_code_size = (min_code_size + 1)
    bit_offset = 0
    code_stream = []
    index_stream = []
    table = []
    prev_code = None
    nextcode = (clear_code + 2)
    while (bit_offset < (8 * (len(block) - 1))):
        if (nextcode == (1 << cur_code_size)):
            cur_code_size += 1
        code = fetch_bits(block, cur_code_size, bit_offset)
        bit_offset += cur_code_size
        if (code == clear_code):
            table = [[i] for i in range((1 << min_code_size))]
            table.append([clear_code])
            table.append([eoi_code])
            nextcode = (clear_code + 2)
            prev_code = None
            print('table reset')
            continue
        elif (code == eoi_code):
            print('stop')
            break
        elif (code < len(table)):
            index_stream.append(table[code])
            k = [table[code][0]]
            if (prev_code is not None):
                table.append((table[prev_code] + k))
                nextcode += 1
        elif (prev_code is None):
            raise ValueError('First code after a reset must be in the table')
        else:
            k = [table[prev_code][0]]
            index_stream.append((table[prev_code] + k))
            table.append((table[prev_code] + k))
            nextcode += 1
        prev_code = code
    index_stream = flatten(index_stream)
    return index_stream
def decompress(block, min_code_size):
    clear_code = (1 << min_code_size)
    eoi_code = (clear_code + 1)
    cur_code_size = (min_code_size + 1)
    bit_offset = 0
    code_stream = []
    index_stream = []
    table = []
    prev_code = None
    nextcode = (clear_code + 2)
    while (bit_offset < (8 * (len(block) - 1))):
        if (nextcode == (1 << cur_code_size)):
            cur_code_size += 1
        code = fetch_bits(block, cur_code_size, bit_offset)
        bit_offset += cur_code_size
        if (code == clear_code):
            table = [[i] for i in range((1 << min_code_size))]
            table.append([clear_code])
            table.append([eoi_code])
            nextcode = (clear_code + 2)
            prev_code = None
            print('table reset')
            continue
        elif (code == eoi_code):
            print('stop')
            break
        elif (code < len(table)):
            index_stream.append(table[code])
            k = [table[code][0]]
            if (prev_code is not None):
                table.append((table[prev_code] + k))
                nextcode += 1
        elif (prev_code is None):
            raise ValueError('First code after a reset must be in the table')
        else:
            k = [table[prev_code][0]]
            index_stream.append((table[prev_code] + k))
            table.append((table[prev_code] + k))
            nextcode += 1
        prev_code = code
    index_stream = flatten(index_stream)
    return index_stream