static int read_dct_coeffs(BitstreamContext *bc, int32_t block[64],

                           const uint8_t *scan,

                           const int32_t quant_matrices[16][64], int q)

{

    int coef_list[128];

    int mode_list[128];

    int i, t, bits, ccoef, mode;

    int list_start = 64, list_end = 64, list_pos;

    int coef_count = 0;

    int coef_idx[64];

    int quant_idx;

    const int32_t *quant;



    coef_list[list_end] = 4;  mode_list[list_end++] = 0;

    coef_list[list_end] = 24; mode_list[list_end++] = 0;

    coef_list[list_end] = 44; mode_list[list_end++] = 0;

    coef_list[list_end] = 1;  mode_list[list_end++] = 3;

    coef_list[list_end] = 2;  mode_list[list_end++] = 3;

    coef_list[list_end] = 3;  mode_list[list_end++] = 3;



    for (bits = bitstream_read(bc, 4) - 1; bits >= 0; bits--) {

        list_pos = list_start;

        while (list_pos < list_end) {

            if (!(mode_list[list_pos] | coef_list[list_pos]) || !bitstream_read_bit(bc)) {

                list_pos++;

                continue;

            }

            ccoef = coef_list[list_pos];

            mode  = mode_list[list_pos];

            switch (mode) {

            case 0:

                coef_list[list_pos] = ccoef + 4;

                mode_list[list_pos] = 1;

            case 2:

                if (mode == 2) {

                    coef_list[list_pos]   = 0;

                    mode_list[list_pos++] = 0;

                }

                for (i = 0; i < 4; i++, ccoef++) {

                    if (bitstream_read_bit(bc)) {

                        coef_list[--list_start] = ccoef;

                        mode_list[  list_start] = 3;

                    } else {

                        if (!bits) {

                            t = 1 - (bitstream_read_bit(bc) << 1);

                        } else {

                            t = bitstream_read(bc, bits) | 1 << bits;

                            t = bitstream_apply_sign(bc, t);

                        }

                        block[scan[ccoef]] = t;

                        coef_idx[coef_count++] = ccoef;

                    }

                }

                break;

            case 1:

                mode_list[list_pos] = 2;

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

                    ccoef += 4;

                    coef_list[list_end]   = ccoef;

                    mode_list[list_end++] = 2;

                }

                break;

            case 3:

                if (!bits) {

                    t = 1 - (bitstream_read_bit(bc) << 1);

                } else {

                    t = bitstream_read(bc, bits) | 1 << bits;

                    t = bitstream_apply_sign(bc, t);

                }

                block[scan[ccoef]] = t;

                coef_idx[coef_count++] = ccoef;

                coef_list[list_pos]   = 0;

                mode_list[list_pos++] = 0;

                break;

            }

        }

    }



    if (q == -1) {

        quant_idx = bitstream_read(bc, 4);

    } else {

        quant_idx = q;

    }



    if (quant_idx >= 16)

        return AVERROR_INVALIDDATA;



    quant = quant_matrices[quant_idx];



    block[0] = (block[0] * quant[0]) >> 11;

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

        int idx = coef_idx[i];

        block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;

    }



    return 0;

}

static int read_dct_coeffs(BitstreamContext *bc, int32_t block[64],

                           const uint8_t *scan,

                           const int32_t quant_matrices[16][64], int q)

{

    int coef_list[128];

    int mode_list[128];

    int i, t, bits, ccoef, mode;

    int list_start = 64, list_end = 64, list_pos;

    int coef_count = 0;

    int coef_idx[64];

    int quant_idx;

    const int32_t *quant;



    coef_list[list_end] = 4;  mode_list[list_end++] = 0;

    coef_list[list_end] = 24; mode_list[list_end++] = 0;

    coef_list[list_end] = 44; mode_list[list_end++] = 0;

    coef_list[list_end] = 1;  mode_list[list_end++] = 3;

    coef_list[list_end] = 2;  mode_list[list_end++] = 3;

    coef_list[list_end] = 3;  mode_list[list_end++] = 3;



    for (bits = bitstream_read(bc, 4) - 1; bits >= 0; bits--) {

        list_pos = list_start;

        while (list_pos < list_end) {

            if (!(mode_list[list_pos] | coef_list[list_pos]) || !bitstream_read_bit(bc)) {

                list_pos++;

                continue;

            }

            ccoef = coef_list[list_pos];

            mode  = mode_list[list_pos];

            switch (mode) {

            case 0:

                coef_list[list_pos] = ccoef + 4;

                mode_list[list_pos] = 1;

            case 2:

                if (mode == 2) {

                    coef_list[list_pos]   = 0;

                    mode_list[list_pos++] = 0;

                }

                for (i = 0; i < 4; i++, ccoef++) {

                    if (bitstream_read_bit(bc)) {

                        coef_list[--list_start] = ccoef;

                        mode_list[  list_start] = 3;

                    } else {

                        if (!bits) {

                            t = 1 - (bitstream_read_bit(bc) << 1);

                        } else {

                            t = bitstream_read(bc, bits) | 1 << bits;

                            t = bitstream_apply_sign(bc, t);

                        }

                        block[scan[ccoef]] = t;

                        coef_idx[coef_count++] = ccoef;

                    }

                }

                break;

            case 1:

                mode_list[list_pos] = 2;

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

                    ccoef += 4;

                    coef_list[list_end]   = ccoef;

                    mode_list[list_end++] = 2;

                }

                break;

            case 3:

                if (!bits) {

                    t = 1 - (bitstream_read_bit(bc) << 1);

                } else {

                    t = bitstream_read(bc, bits) | 1 << bits;

                    t = bitstream_apply_sign(bc, t);

                }

                block[scan[ccoef]] = t;

                coef_idx[coef_count++] = ccoef;

                coef_list[list_pos]   = 0;

                mode_list[list_pos++] = 0;

                break;

            }

        }

    }



    if (q == -1) {

        quant_idx = bitstream_read(bc, 4);

    } else {

        quant_idx = q;

    }



    if (quant_idx >= 16)

        return AVERROR_INVALIDDATA;



    quant = quant_matrices[quant_idx];



    block[0] = (block[0] * quant[0]) >> 11;

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

        int idx = coef_idx[i];

        block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;

    }



    return 0;

}

static int FUNC_0(BitstreamContext *VAR_0, int32_t VAR_1[64],

                           const uint8_t *VAR_2,

                           const int32_t VAR_3[16][64], int VAR_4)

{

    int VAR_5[128];

    int VAR_6[128];

    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    int VAR_12 = 64, VAR_13 = 64, VAR_14;

    int VAR_15 = 0;

    int VAR_16[64];

    int VAR_17;

    const int32_t *VAR_18;



    VAR_5[VAR_13] = 4;  VAR_6[VAR_13++] = 0;

    VAR_5[VAR_13] = 24; VAR_6[VAR_13++] = 0;

    VAR_5[VAR_13] = 44; VAR_6[VAR_13++] = 0;

    VAR_5[VAR_13] = 1;  VAR_6[VAR_13++] = 3;

    VAR_5[VAR_13] = 2;  VAR_6[VAR_13++] = 3;

    VAR_5[VAR_13] = 3;  VAR_6[VAR_13++] = 3;



    for (VAR_9 = bitstream_read(VAR_0, 4) - 1; VAR_9 >= 0; VAR_9--) {

        VAR_14 = VAR_12;

        while (VAR_14 < VAR_13) {

            if (!(VAR_6[VAR_14] | VAR_5[VAR_14]) || !bitstream_read_bit(VAR_0)) {

                VAR_14++;

                continue;

            }

            VAR_10 = VAR_5[VAR_14];

            VAR_11  = VAR_6[VAR_14];

            switch (VAR_11) {

            case 0:

                VAR_5[VAR_14] = VAR_10 + 4;

                VAR_6[VAR_14] = 1;

            case 2:

                if (VAR_11 == 2) {

                    VAR_5[VAR_14]   = 0;

                    VAR_6[VAR_14++] = 0;

                }

                for (VAR_7 = 0; VAR_7 < 4; VAR_7++, VAR_10++) {

                    if (bitstream_read_bit(VAR_0)) {

                        VAR_5[--VAR_12] = VAR_10;

                        VAR_6[  VAR_12] = 3;

                    } else {

                        if (!VAR_9) {

                            VAR_8 = 1 - (bitstream_read_bit(VAR_0) << 1);

                        } else {

                            VAR_8 = bitstream_read(VAR_0, VAR_9) | 1 << VAR_9;

                            VAR_8 = bitstream_apply_sign(VAR_0, VAR_8);

                        }

                        VAR_1[VAR_2[VAR_10]] = VAR_8;

                        VAR_16[VAR_15++] = VAR_10;

                    }

                }

                break;

            case 1:

                VAR_6[VAR_14] = 2;

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

                    VAR_10 += 4;

                    VAR_5[VAR_13]   = VAR_10;

                    VAR_6[VAR_13++] = 2;

                }

                break;

            case 3:

                if (!VAR_9) {

                    VAR_8 = 1 - (bitstream_read_bit(VAR_0) << 1);

                } else {

                    VAR_8 = bitstream_read(VAR_0, VAR_9) | 1 << VAR_9;

                    VAR_8 = bitstream_apply_sign(VAR_0, VAR_8);

                }

                VAR_1[VAR_2[VAR_10]] = VAR_8;

                VAR_16[VAR_15++] = VAR_10;

                VAR_5[VAR_14]   = 0;

                VAR_6[VAR_14++] = 0;

                break;

            }

        }

    }



    if (VAR_4 == -1) {

        VAR_17 = bitstream_read(VAR_0, 4);

    } else {

        VAR_17 = VAR_4;

    }



    if (VAR_17 >= 16)

        return AVERROR_INVALIDDATA;



    VAR_18 = VAR_3[VAR_17];



    VAR_1[0] = (VAR_1[0] * VAR_18[0]) >> 11;

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

        int VAR_19 = VAR_16[VAR_7];

        VAR_1[VAR_2[VAR_19]] = (VAR_1[VAR_2[VAR_19]] * VAR_18[VAR_19]) >> 11;

    }



    return 0;

}

static int FUNC_0(BitstreamContext *VAR_0, int32_t VAR_1[64],
const uint8_t *VAR_2,
const int32_t VAR_3[16][64], int VAR_4)
{ int VAR_5[128]; int VAR_6[128]; int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; int VAR_12 = 64, VAR_13 = 64, VAR_14; int VAR_15 = 0; int VAR_16[64]; int VAR_17; const int32_t *VAR_18; VAR_5[VAR_13] = 4;  VAR_6[VAR_13++] = 0; VAR_5[VAR_13] = 24; VAR_6[VAR_13++] = 0; VAR_5[VAR_13] = 44; VAR_6[VAR_13++] = 0; VAR_5[VAR_13] = 1;  VAR_6[VAR_13++] = 3; VAR_5[VAR_13] = 2;  VAR_6[VAR_13++] = 3; VAR_5[VAR_13] = 3;  VAR_6[VAR_13++] = 3; for (VAR_9 = bitstream_read(VAR_0, 4) - 1; VAR_9 >= 0; VAR_9--) { VAR_14 = VAR_12; while (VAR_14 < VAR_13) { if (!(VAR_6[VAR_14] | VAR_5[VAR_14]) || !bitstream_read_bit(VAR_0)) { VAR_14++; continue; } VAR_10 = VAR_5[VAR_14]; VAR_11  = VAR_6[VAR_14]; switch (VAR_11) { case 0:
VAR_5[VAR_14] = VAR_10 + 4; VAR_6[VAR_14] = 1; case 2:
if (VAR_11 == 2) { VAR_5[VAR_14]   = 0; VAR_6[VAR_14++] = 0; } for (VAR_7 = 0; VAR_7 < 4; VAR_7++, VAR_10++) { if (bitstream_read_bit(VAR_0)) { VAR_5[--VAR_12] = VAR_10; VAR_6[  VAR_12] = 3; } else { if (!VAR_9) { VAR_8 = 1 - (bitstream_read_bit(VAR_0) << 1); } else { VAR_8 = bitstream_read(VAR_0, VAR_9) | 1 << VAR_9; VAR_8 = bitstream_apply_sign(VAR_0, VAR_8); } VAR_1[VAR_2[VAR_10]] = VAR_8; VAR_16[VAR_15++] = VAR_10; } } break; case 1:
VAR_6[VAR_14] = 2; for (VAR_7 = 0; VAR_7 < 3; VAR_7++) { VAR_10 += 4; VAR_5[VAR_13]   = VAR_10; VAR_6[VAR_13++] = 2; } break; case 3:
if (!VAR_9) { VAR_8 = 1 - (bitstream_read_bit(VAR_0) << 1); } else { VAR_8 = bitstream_read(VAR_0, VAR_9) | 1 << VAR_9; VAR_8 = bitstream_apply_sign(VAR_0, VAR_8); } VAR_1[VAR_2[VAR_10]] = VAR_8; VAR_16[VAR_15++] = VAR_10; VAR_5[VAR_14]   = 0; VAR_6[VAR_14++] = 0; break; } } } if (VAR_4 == -1) { VAR_17 = bitstream_read(VAR_0, 4); } else { VAR_17 = VAR_4; } if (VAR_17 >= 16)
return AVERROR_INVALIDDATA; VAR_18 = VAR_3[VAR_17]; VAR_1[0] = (VAR_1[0] * VAR_18[0]) >> 11; for (VAR_7 = 0; VAR_7 < VAR_15; VAR_7++) { int VAR_19 = VAR_16[VAR_7]; VAR_1[VAR_2[VAR_19]] = (VAR_1[VAR_2[VAR_19]] * VAR_18[VAR_19]) >> 11; } return 0; }