static const uint8_t *read_huffman_tables(FourXContext *f,

                                          const uint8_t * const buf, int buf_size)

{

    int frequency[512] = { 0 };

    uint8_t flag[512];

    int up[512];

    uint8_t len_tab[257];

    int bits_tab[257];

    int start, end;

    const uint8_t *ptr = buf;

    const uint8_t *ptr_end = buf + buf_size;

    int j;



    memset(up, -1, sizeof(up));



    start = *ptr++;

    end   = *ptr++;

    for (;;) {

        int i;



        if (start <= end && ptr_end - ptr < end - start + 1 + 1)

            return NULL;

        for (i = start; i <= end; i++)

            frequency[i] = *ptr++;

        start = *ptr++;

        if (start == 0)

            break;



        end = *ptr++;

    }

    frequency[256] = 1;



    while ((ptr - buf) & 3)

        ptr++; // 4byte align



    for (j = 257; j < 512; j++) {

        int min_freq[2] = { 256 * 256, 256 * 256 };

        int smallest[2] = { 0, 0 };

        int i;

        for (i = 0; i < j; i++) {

            if (frequency[i] == 0)

                continue;

            if (frequency[i] < min_freq[1]) {

                if (frequency[i] < min_freq[0]) {

                    min_freq[1] = min_freq[0];

                    smallest[1] = smallest[0];

                    min_freq[0] = frequency[i];

                    smallest[0] = i;

                } else {

                    min_freq[1] = frequency[i];

                    smallest[1] = i;

                }

            }

        }

        if (min_freq[1] == 256 * 256)

            break;



        frequency[j]           = min_freq[0] + min_freq[1];

        flag[smallest[0]]      = 0;

        flag[smallest[1]]      = 1;

        up[smallest[0]]        =

        up[smallest[1]]        = j;

        frequency[smallest[0]] = frequency[smallest[1]] = 0;

    }



    for (j = 0; j < 257; j++) {

        int node, len = 0, bits = 0;



        for (node = j; up[node] != -1; node = up[node]) {

            bits += flag[node] << len;

            len++;

            if (len > 31)

                // can this happen at all ?

                av_log(f->avctx, AV_LOG_ERROR,

                       "vlc length overflow\n");

        }



        bits_tab[j] = bits;

        len_tab[j]  = len;

    }



    if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1,

                 bits_tab, 4, 4, 0))

        return NULL;



    return ptr;

}

static const uint8_t *read_huffman_tables(FourXContext *f,

                                          const uint8_t * const buf, int buf_size)

{

    int frequency[512] = { 0 };

    uint8_t flag[512];

    int up[512];

    uint8_t len_tab[257];

    int bits_tab[257];

    int start, end;

    const uint8_t *ptr = buf;

    const uint8_t *ptr_end = buf + buf_size;

    int j;



    memset(up, -1, sizeof(up));



    start = *ptr++;

    end   = *ptr++;

    for (;;) {

        int i;



        if (start <= end && ptr_end - ptr < end - start + 1 + 1)

            return NULL;

        for (i = start; i <= end; i++)

            frequency[i] = *ptr++;

        start = *ptr++;

        if (start == 0)

            break;



        end = *ptr++;

    }

    frequency[256] = 1;



    while ((ptr - buf) & 3)

        ptr++; 



    for (j = 257; j < 512; j++) {

        int min_freq[2] = { 256 * 256, 256 * 256 };

        int smallest[2] = { 0, 0 };

        int i;

        for (i = 0; i < j; i++) {

            if (frequency[i] == 0)

                continue;

            if (frequency[i] < min_freq[1]) {

                if (frequency[i] < min_freq[0]) {

                    min_freq[1] = min_freq[0];

                    smallest[1] = smallest[0];

                    min_freq[0] = frequency[i];

                    smallest[0] = i;

                } else {

                    min_freq[1] = frequency[i];

                    smallest[1] = i;

                }

            }

        }

        if (min_freq[1] == 256 * 256)

            break;



        frequency[j]           = min_freq[0] + min_freq[1];

        flag[smallest[0]]      = 0;

        flag[smallest[1]]      = 1;

        up[smallest[0]]        =

        up[smallest[1]]        = j;

        frequency[smallest[0]] = frequency[smallest[1]] = 0;

    }



    for (j = 0; j < 257; j++) {

        int node, len = 0, bits = 0;



        for (node = j; up[node] != -1; node = up[node]) {

            bits += flag[node] << len;

            len++;

            if (len > 31)

                

                av_log(f->avctx, AV_LOG_ERROR,

                       "vlc length overflow\n");

        }



        bits_tab[j] = bits;

        len_tab[j]  = len;

    }



    if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1,

                 bits_tab, 4, 4, 0))

        return NULL;



    return ptr;

}

        if (start <= end && ptr_end - ptr < end - start + 1 + 1)
static const uint8_t *FUNC_0(FourXContext *f,

                                          const uint8_t * const buf, int buf_size)

{

    int VAR_0[512] = { 0 };

    uint8_t flag[512];

    int VAR_1[512];

    uint8_t len_tab[257];

    int VAR_2[257];

    int VAR_3, VAR_4;

    const uint8_t *VAR_5 = buf;

    const uint8_t *VAR_6 = buf + buf_size;

    int VAR_7;



    memset(VAR_1, -1, sizeof(VAR_1));



    VAR_3 = *VAR_5++;

    VAR_4   = *VAR_5++;

    for (;;) {

        int VAR_11;



        if (VAR_3 <= VAR_4 && VAR_6 - VAR_5 < VAR_4 - VAR_3 + 1 + 1)

            return NULL;

        for (VAR_11 = VAR_3; VAR_11 <= VAR_4; VAR_11++)

            VAR_0[VAR_11] = *VAR_5++;

        VAR_3 = *VAR_5++;

        if (VAR_3 == 0)

            break;



        VAR_4 = *VAR_5++;

    }

    VAR_0[256] = 1;



    while ((VAR_5 - buf) & 3)

        VAR_5++; 



    for (VAR_7 = 257; VAR_7 < 512; VAR_7++) {

        int VAR_9[2] = { 256 * 256, 256 * 256 };

        int VAR_10[2] = { 0, 0 };

        int VAR_11;

        for (VAR_11 = 0; VAR_11 < VAR_7; VAR_11++) {

            if (VAR_0[VAR_11] == 0)

                continue;

            if (VAR_0[VAR_11] < VAR_9[1]) {

                if (VAR_0[VAR_11] < VAR_9[0]) {

                    VAR_9[1] = VAR_9[0];

                    VAR_10[1] = VAR_10[0];

                    VAR_9[0] = VAR_0[VAR_11];

                    VAR_10[0] = VAR_11;

                } else {

                    VAR_9[1] = VAR_0[VAR_11];

                    VAR_10[1] = VAR_11;

                }

            }

        }

        if (VAR_9[1] == 256 * 256)

            break;



        VAR_0[VAR_7]           = VAR_9[0] + VAR_9[1];

        flag[VAR_10[0]]      = 0;

        flag[VAR_10[1]]      = 1;

        VAR_1[VAR_10[0]]        =

        VAR_1[VAR_10[1]]        = VAR_7;

        VAR_0[VAR_10[0]] = VAR_0[VAR_10[1]] = 0;

    }



    for (VAR_7 = 0; VAR_7 < 257; VAR_7++) {

        int VAR_11, VAR_12 = 0, VAR_13 = 0;



        for (VAR_11 = VAR_7; VAR_1[VAR_11] != -1; VAR_11 = VAR_1[VAR_11]) {

            VAR_13 += flag[VAR_11] << VAR_12;

            VAR_12++;

            if (VAR_12 > 31)

                

                av_log(f->avctx, AV_LOG_ERROR,

                       "vlc length overflow\n");

        }



        VAR_2[VAR_7] = VAR_13;

        len_tab[VAR_7]  = VAR_12;

    }



    if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1,

                 VAR_2, 4, 4, 0))

        return NULL;



    return VAR_5;

}

static const uint8_t *FUNC_0(FourXContext *f,
const uint8_t * const buf, int buf_size)
{ int VAR_0[512] = { 0 }; uint8_t flag[512]; int VAR_1[512]; uint8_t len_tab[257]; int VAR_2[257]; int VAR_3, VAR_4; const uint8_t *VAR_5 = buf; const uint8_t *VAR_6 = buf + buf_size; int VAR_7; memset(VAR_1, -1, sizeof(VAR_1)); VAR_3 = *VAR_5++; VAR_4   = *VAR_5++; for (;;) { int VAR_11; if (VAR_3 <= VAR_4 && VAR_6 - VAR_5 < VAR_4 - VAR_3 + 1 + 1)
return NULL; for (VAR_11 = VAR_3; VAR_11 <= VAR_4; VAR_11++) VAR_0[VAR_11] = *VAR_5++; VAR_3 = *VAR_5++; if (VAR_3 == 0)
break; VAR_4 = *VAR_5++; } VAR_0[256] = 1; while ((VAR_5 - buf) & 3)
VAR_5++; for (VAR_7 = 257; VAR_7 < 512; VAR_7++) { int VAR_9[2] = { 256 * 256, 256 * 256 }; int VAR_10[2] = { 0, 0 }; int VAR_11; for (VAR_11 = 0; VAR_11 < VAR_7; VAR_11++) { if (VAR_0[VAR_11] == 0)
continue; if (VAR_0[VAR_11] < VAR_9[1]) { if (VAR_0[VAR_11] < VAR_9[0]) { VAR_9[1] = VAR_9[0]; VAR_10[1] = VAR_10[0]; VAR_9[0] = VAR_0[VAR_11]; VAR_10[0] = VAR_11; } else { VAR_9[1] = VAR_0[VAR_11]; VAR_10[1] = VAR_11; } } } if (VAR_9[1] == 256 * 256)
break; VAR_0[VAR_7]           = VAR_9[0] + VAR_9[1]; flag[VAR_10[0]]      = 0; flag[VAR_10[1]]      = 1; VAR_1[VAR_10[0]]        =
VAR_1[VAR_10[1]]        = VAR_7; VAR_0[VAR_10[0]] = VAR_0[VAR_10[1]] = 0; } for (VAR_7 = 0; VAR_7 < 257; VAR_7++) { int VAR_11, VAR_12 = 0, VAR_13 = 0; for (VAR_11 = VAR_7; VAR_1[VAR_11] != -1; VAR_11 = VAR_1[VAR_11]) { VAR_13 += flag[VAR_11] << VAR_12; VAR_12++; if (VAR_12 > 31)
av_log(f->avctx, AV_LOG_ERROR,
"vlc length overflow\n"); } VAR_2[VAR_7] = VAR_13; len_tab[VAR_7]  = VAR_12; } if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1,
VAR_2, 4, 4, 0))
return NULL; return VAR_5; }