static int read_dct_coeffs(GetBitContext *gb, 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, mask, bits, ccoef, mode, sign;

    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;



    bits = get_bits(gb, 4) - 1;

    for (mask = 1 << bits; bits >= 0; mask >>= 1, bits--) {

        list_pos = list_start;

        while (list_pos < list_end) {

            if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) {

                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 (get_bits1(gb)) {

                        coef_list[--list_start] = ccoef;

                        mode_list[  list_start] = 3;

                    } else {

                        if (!bits) {

                            t = 1 - (get_bits1(gb) << 1);

                        } else {

                            t = get_bits(gb, bits) | mask;

                            sign = -get_bits1(gb);

                            t = (t ^ sign) - sign;

                        }

                        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 - (get_bits1(gb) << 1);

                } else {

                    t = get_bits(gb, bits) | mask;

                    sign = -get_bits1(gb);

                    t = (t ^ sign) - sign;

                }

                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 = get_bits(gb, 4);

    } else {

        quant_idx = q;

    }



    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(GetBitContext *gb, 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, mask, bits, ccoef, mode, sign;

    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;



    bits = get_bits(gb, 4) - 1;

    for (mask = 1 << bits; bits >= 0; mask >>= 1, bits--) {

        list_pos = list_start;

        while (list_pos < list_end) {

            if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) {

                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 (get_bits1(gb)) {

                        coef_list[--list_start] = ccoef;

                        mode_list[  list_start] = 3;

                    } else {

                        if (!bits) {

                            t = 1 - (get_bits1(gb) << 1);

                        } else {

                            t = get_bits(gb, bits) | mask;

                            sign = -get_bits1(gb);

                            t = (t ^ sign) - sign;

                        }

                        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 - (get_bits1(gb) << 1);

                } else {

                    t = get_bits(gb, bits) | mask;

                    sign = -get_bits1(gb);

                    t = (t ^ sign) - sign;

                }

                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 = get_bits(gb, 4);

    } else {

        quant_idx = q;

    }



    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(GetBitContext *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, VAR_12, VAR_13;

    int VAR_14 = 64, VAR_15 = 64, VAR_16;

    int VAR_17 = 0;

    int VAR_18[64];

    int VAR_19;

    const int32_t *VAR_20;



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

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

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

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

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

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



    VAR_10 = get_bits(VAR_0, 4) - 1;

    for (VAR_9 = 1 << VAR_10; VAR_10 >= 0; VAR_9 >>= 1, VAR_10--) {

        VAR_16 = VAR_14;

        while (VAR_16 < VAR_15) {

            if (!(VAR_6[VAR_16] | VAR_5[VAR_16]) || !get_bits1(VAR_0)) {

                VAR_16++;

                continue;

            }

            VAR_11 = VAR_5[VAR_16];

            VAR_12  = VAR_6[VAR_16];

            switch (VAR_12) {

            case 0:

                VAR_5[VAR_16] = VAR_11 + 4;

                VAR_6[VAR_16] = 1;

            case 2:

                if (VAR_12 == 2) {

                    VAR_5[VAR_16]   = 0;

                    VAR_6[VAR_16++] = 0;

                }

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

                    if (get_bits1(VAR_0)) {

                        VAR_5[--VAR_14] = VAR_11;

                        VAR_6[  VAR_14] = 3;

                    } else {

                        if (!VAR_10) {

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

                        } else {

                            VAR_8 = get_bits(VAR_0, VAR_10) | VAR_9;

                            VAR_13 = -get_bits1(VAR_0);

                            VAR_8 = (VAR_8 ^ VAR_13) - VAR_13;

                        }

                        VAR_1[VAR_2[VAR_11]] = VAR_8;

                        VAR_18[VAR_17++] = VAR_11;

                    }

                }

                break;

            case 1:

                VAR_6[VAR_16] = 2;

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

                    VAR_11 += 4;

                    VAR_5[VAR_15]   = VAR_11;

                    VAR_6[VAR_15++] = 2;

                }

                break;

            case 3:

                if (!VAR_10) {

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

                } else {

                    VAR_8 = get_bits(VAR_0, VAR_10) | VAR_9;

                    VAR_13 = -get_bits1(VAR_0);

                    VAR_8 = (VAR_8 ^ VAR_13) - VAR_13;

                }

                VAR_1[VAR_2[VAR_11]] = VAR_8;

                VAR_18[VAR_17++] = VAR_11;

                VAR_5[VAR_16]   = 0;

                VAR_6[VAR_16++] = 0;

                break;

            }

        }

    }



    if (VAR_4 == -1) {

        VAR_19 = get_bits(VAR_0, 4);

    } else {

        VAR_19 = VAR_4;

    }



    VAR_20 = VAR_3[VAR_19];



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

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

        int VAR_21 = VAR_18[VAR_7];

        VAR_1[VAR_2[VAR_21]] = (VAR_1[VAR_2[VAR_21]] * VAR_20[VAR_21]) >> 11;

    }



    return 0;

}

static int FUNC_0(GetBitContext *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, VAR_12, VAR_13; int VAR_14 = 64, VAR_15 = 64, VAR_16; int VAR_17 = 0; int VAR_18[64]; int VAR_19; const int32_t *VAR_20; VAR_5[VAR_15] = 4;  VAR_6[VAR_15++] = 0; VAR_5[VAR_15] = 24; VAR_6[VAR_15++] = 0; VAR_5[VAR_15] = 44; VAR_6[VAR_15++] = 0; VAR_5[VAR_15] = 1;  VAR_6[VAR_15++] = 3; VAR_5[VAR_15] = 2;  VAR_6[VAR_15++] = 3; VAR_5[VAR_15] = 3;  VAR_6[VAR_15++] = 3; VAR_10 = get_bits(VAR_0, 4) - 1; for (VAR_9 = 1 << VAR_10; VAR_10 >= 0; VAR_9 >>= 1, VAR_10--) { VAR_16 = VAR_14; while (VAR_16 < VAR_15) { if (!(VAR_6[VAR_16] | VAR_5[VAR_16]) || !get_bits1(VAR_0)) { VAR_16++; continue; } VAR_11 = VAR_5[VAR_16]; VAR_12  = VAR_6[VAR_16]; switch (VAR_12) { case 0:
VAR_5[VAR_16] = VAR_11 + 4; VAR_6[VAR_16] = 1; case 2:
if (VAR_12 == 2) { VAR_5[VAR_16]   = 0; VAR_6[VAR_16++] = 0; } for (VAR_7 = 0; VAR_7 < 4; VAR_7++, VAR_11++) { if (get_bits1(VAR_0)) { VAR_5[--VAR_14] = VAR_11; VAR_6[  VAR_14] = 3; } else { if (!VAR_10) { VAR_8 = 1 - (get_bits1(VAR_0) << 1); } else { VAR_8 = get_bits(VAR_0, VAR_10) | VAR_9; VAR_13 = -get_bits1(VAR_0); VAR_8 = (VAR_8 ^ VAR_13) - VAR_13; } VAR_1[VAR_2[VAR_11]] = VAR_8; VAR_18[VAR_17++] = VAR_11; } } break; case 1:
VAR_6[VAR_16] = 2; for (VAR_7 = 0; VAR_7 < 3; VAR_7++) { VAR_11 += 4; VAR_5[VAR_15]   = VAR_11; VAR_6[VAR_15++] = 2; } break; case 3:
if (!VAR_10) { VAR_8 = 1 - (get_bits1(VAR_0) << 1); } else { VAR_8 = get_bits(VAR_0, VAR_10) | VAR_9; VAR_13 = -get_bits1(VAR_0); VAR_8 = (VAR_8 ^ VAR_13) - VAR_13; } VAR_1[VAR_2[VAR_11]] = VAR_8; VAR_18[VAR_17++] = VAR_11; VAR_5[VAR_16]   = 0; VAR_6[VAR_16++] = 0; break; } } } if (VAR_4 == -1) { VAR_19 = get_bits(VAR_0, 4); } else { VAR_19 = VAR_4; } VAR_20 = VAR_3[VAR_19]; VAR_1[0] = (VAR_1[0] * VAR_20[0]) >> 11; for (VAR_7 = 0; VAR_7 < VAR_17; VAR_7++) { int VAR_21 = VAR_18[VAR_7]; VAR_1[VAR_2[VAR_21]] = (VAR_1[VAR_2[VAR_21]] * VAR_20[VAR_21]) >> 11; } return 0; }