libavcodec/hevc.c:1155: error: Uninitialized Value
  The value read from shift was never initialized.

libavcodec/hevc.c:1155:21: 
1153.                         }
1154.                     }
1155.                     trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
                          ^
1156.                     if(trans_coeff_level < 0) {
1157.                         if((~trans_coeff_level) & 0xFffffffffff8000)

static void hls_residual_coding(HEVCContext *s, int x0, int y0,
                                int log2_trafo_size, enum ScanType scan_idx,
                                int c_idx)
{
#define GET_COORD(offset, n)                                    \
    do {                                                        \
        x_c = (scan_x_cg[offset >> 4] << 2) + scan_x_off[n];    \
        y_c = (scan_y_cg[offset >> 4] << 2) + scan_y_off[n];    \
    } while (0)
    HEVCLocalContext *lc    = &s->HEVClc;
    int transform_skip_flag = 0;
    int last_significant_coeff_x, last_significant_coeff_y;
    int last_scan_pos;
    int n_end;
    int num_coeff    = 0;
    int greater1_ctx = 1;
    int num_last_subset;
    int x_cg_last_sig, y_cg_last_sig;
    const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
    ptrdiff_t stride = s->frame->linesize[c_idx];
    int hshift       = s->sps->hshift[c_idx];
    int vshift       = s->sps->vshift[c_idx];
    uint8_t *dst     = &s->frame->data[c_idx][(y0 >> vshift) * stride +
                                              ((x0 >> hshift) << s->sps->pixel_shift)];
    DECLARE_ALIGNED(16, int16_t, coeffs[MAX_TB_SIZE * MAX_TB_SIZE]) = { 0 };
    DECLARE_ALIGNED(8, uint8_t, significant_coeff_group_flag[8][8]) = { { 0 } };
    int trafo_size = 1 << log2_trafo_size;
    int i, qp, shift, add, scale, scale_m;
    const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
    const uint8_t *scale_matrix;
    uint8_t dc_scale;
    if (!lc->cu.cu_transquant_bypass_flag) {
        static const int qp_c[] = {
            29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
        };
        static const uint8_t rem6[51 + 2 * 6 + 1] = {
            0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
            3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
            0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
        };
        static const uint8_t div6[51 + 2 * 6 + 1] = {
            0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,  3,  3,  3,
            3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6,  6,  6,  6,
            7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
        };
        int qp_y = lc->qp_y;
        if (c_idx == 0) {
            qp = qp_y + s->sps->qp_bd_offset;
        } else {
            int qp_i, offset;
            if (c_idx == 1)
                offset = s->pps->cb_qp_offset + s->sh.slice_cb_qp_offset;
            else
                offset = s->pps->cr_qp_offset + s->sh.slice_cr_qp_offset;
            qp_i = av_clip_c(qp_y + offset, -s->sps->qp_bd_offset, 57);
            if (qp_i < 30)
                qp = qp_i;
            else if (qp_i > 43)
                qp = qp_i - 6;
            else
                qp = qp_c[qp_i - 30];
            qp += s->sps->qp_bd_offset;
        }
        shift    = s->sps->bit_depth + log2_trafo_size - 5;
        add      = 1 << (shift - 1);
        scale    = level_scale[rem6[qp]] << (div6[qp]);
        scale_m  = 16;
        dc_scale = 16;
        if (s->sps->scaling_list_enable_flag) {
            const ScalingList *sl = s->pps->scaling_list_data_present_flag ?
                                    &s->pps->scaling_list : &s->sps->scaling_list;
            int matrix_id = lc->cu.pred_mode != MODE_INTRA;
            if (log2_trafo_size != 5)
                matrix_id = 3 * matrix_id + c_idx;
            scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
            if (log2_trafo_size >= 4)
                dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
        }
    }
    if (s->pps->transform_skip_enabled_flag &&
        !lc->cu.cu_transquant_bypass_flag   &&
        log2_trafo_size == 2) {
        transform_skip_flag = ff_hevc_transform_skip_flag_decode(s, c_idx);
    }
    last_significant_coeff_x =
        ff_hevc_last_significant_coeff_x_prefix_decode(s, c_idx, log2_trafo_size);
    last_significant_coeff_y =
        ff_hevc_last_significant_coeff_y_prefix_decode(s, c_idx, log2_trafo_size);
    if (last_significant_coeff_x > 3) {
        int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_x);
        last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
                                   (2 + (last_significant_coeff_x & 1)) +
                                   suffix;
    }
    if (last_significant_coeff_y > 3) {
        int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_y);
        last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
                                   (2 + (last_significant_coeff_y & 1)) +
                                   suffix;
    }
    if (scan_idx == SCAN_VERT)
        FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
    x_cg_last_sig = last_significant_coeff_x >> 2;
    y_cg_last_sig = last_significant_coeff_y >> 2;
    switch (scan_idx) {
    case SCAN_DIAG: {
        int last_x_c = last_significant_coeff_x & 3;
        int last_y_c = last_significant_coeff_y & 3;
        scan_x_off = ff_hevc_diag_scan4x4_x;
        scan_y_off = ff_hevc_diag_scan4x4_y;
        num_coeff  = diag_scan4x4_inv[last_y_c][last_x_c];
        if (trafo_size == 4) {
            scan_x_cg = scan_1x1;
            scan_y_cg = scan_1x1;
        } else if (trafo_size == 8) {
            num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
            scan_x_cg  = diag_scan2x2_x;
            scan_y_cg  = diag_scan2x2_y;
        } else if (trafo_size == 16) {
            num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
            scan_x_cg  = ff_hevc_diag_scan4x4_x;
            scan_y_cg  = ff_hevc_diag_scan4x4_y;
        } else {
            num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
            scan_x_cg  = ff_hevc_diag_scan8x8_x;
            scan_y_cg  = ff_hevc_diag_scan8x8_y;
        }
        break;
    }
    case SCAN_HORIZ:
        scan_x_cg  = horiz_scan2x2_x;
        scan_y_cg  = horiz_scan2x2_y;
        scan_x_off = horiz_scan4x4_x;
        scan_y_off = horiz_scan4x4_y;
        num_coeff  = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
        break;
    default:
        scan_x_cg  = horiz_scan2x2_y;
        scan_y_cg  = horiz_scan2x2_x;
        scan_x_off = horiz_scan4x4_y;
        scan_y_off = horiz_scan4x4_x;
        num_coeff  = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
        break;
    }
    num_coeff++;
    num_last_subset = (num_coeff - 1) >> 4;
    for (i = num_last_subset; i >= 0; i--) {
        int n, m;
        int x_cg, y_cg, x_c, y_c;
        int implicit_non_zero_coeff = 0;
        int64_t trans_coeff_level;
        int prev_sig = 0;
        int offset   = i << 4;
        uint8_t significant_coeff_flag_idx[16];
        uint8_t nb_significant_coeff_flag = 0;
        x_cg = scan_x_cg[i];
        y_cg = scan_y_cg[i];
        if (i < num_last_subset && i > 0) {
            int ctx_cg = 0;
            if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
                ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
            if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
                ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
            significant_coeff_group_flag[x_cg][y_cg] =
                ff_hevc_significant_coeff_group_flag_decode(s, c_idx, ctx_cg);
            implicit_non_zero_coeff = 1;
        } else {
            significant_coeff_group_flag[x_cg][y_cg] =
                ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
                 (x_cg == 0 && y_cg == 0));
        }
        last_scan_pos = num_coeff - offset - 1;
        if (i == num_last_subset) {
            n_end                         = last_scan_pos - 1;
            significant_coeff_flag_idx[0] = last_scan_pos;
            nb_significant_coeff_flag     = 1;
        } else {
            n_end = 15;
        }
        if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
            prev_sig = significant_coeff_group_flag[x_cg + 1][y_cg];
        if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
            prev_sig += significant_coeff_group_flag[x_cg][y_cg + 1] << 1;
        for (n = n_end; n >= 0; n--) {
            GET_COORD(offset, n);
            if (significant_coeff_group_flag[x_cg][y_cg] &&
                (n > 0 || implicit_non_zero_coeff == 0)) {
                if (ff_hevc_significant_coeff_flag_decode(s, c_idx, x_c, y_c,
                                                          log2_trafo_size,
                                                          scan_idx,
                                                          prev_sig) == 1) {
                    significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
                    nb_significant_coeff_flag++;
                    implicit_non_zero_coeff = 0;
                }
            } else {
                int last_cg = (x_c == (x_cg << 2) && y_c == (y_cg << 2));
                if (last_cg && implicit_non_zero_coeff && significant_coeff_group_flag[x_cg][y_cg]) {
                    significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
                    nb_significant_coeff_flag++;
                }
            }
        }
        n_end = nb_significant_coeff_flag;
        if (n_end) {
            int first_nz_pos_in_cg = 16;
            int last_nz_pos_in_cg = -1;
            int c_rice_param = 0;
            int first_greater1_coeff_idx = -1;
            uint8_t coeff_abs_level_greater1_flag[16] = { 0 };
            uint16_t coeff_sign_flag;
            int sum_abs = 0;
            int sign_hidden = 0;
            int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
            if (!(i == num_last_subset) && greater1_ctx == 0)
                ctx_set++;
            greater1_ctx      = 1;
            last_nz_pos_in_cg = significant_coeff_flag_idx[0];
            for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
                int n_idx = significant_coeff_flag_idx[m];
                int inc   = (ctx_set << 2) + greater1_ctx;
                coeff_abs_level_greater1_flag[n_idx] =
                    ff_hevc_coeff_abs_level_greater1_flag_decode(s, c_idx, inc);
                if (coeff_abs_level_greater1_flag[n_idx]) {
                    greater1_ctx = 0;
                } else if (greater1_ctx > 0 && greater1_ctx < 3) {
                    greater1_ctx++;
                }
                if (coeff_abs_level_greater1_flag[n_idx] &&
                    first_greater1_coeff_idx == -1)
                    first_greater1_coeff_idx = n_idx;
            }
            first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
            sign_hidden        = last_nz_pos_in_cg - first_nz_pos_in_cg >= 4 &&
                                 !lc->cu.cu_transquant_bypass_flag;
            if (first_greater1_coeff_idx != -1) {
                coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += ff_hevc_coeff_abs_level_greater2_flag_decode(s, c_idx, ctx_set);
            }
            if (!s->pps->sign_data_hiding_flag || !sign_hidden) {
                coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
            } else {
                coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
            }
            for (m = 0; m < n_end; m++) {
                n = significant_coeff_flag_idx[m];
                GET_COORD(offset, n);
                trans_coeff_level = 1 + coeff_abs_level_greater1_flag[n];
                if (trans_coeff_level == ((m < 8) ?
                                          ((n == first_greater1_coeff_idx) ? 3 : 2) : 1)) {
                    int last_coeff_abs_level_remaining = ff_hevc_coeff_abs_level_remaining(s, trans_coeff_level, c_rice_param);
                    trans_coeff_level += last_coeff_abs_level_remaining;
                    if ((trans_coeff_level) > (3 * (1 << c_rice_param)))
                        c_rice_param = FFMIN(c_rice_param + 1, 4);
                }
                if (s->pps->sign_data_hiding_flag && sign_hidden) {
                    sum_abs += trans_coeff_level;
                    if (n == first_nz_pos_in_cg && ((sum_abs & 1) == 1))
                        trans_coeff_level = -trans_coeff_level;
                }
                if (coeff_sign_flag >> 15)
                    trans_coeff_level = -trans_coeff_level;
                coeff_sign_flag <<= 1;
                if (!lc->cu.cu_transquant_bypass_flag) {
                    if (s->sps->scaling_list_enable_flag) {
                        if (y_c || x_c || log2_trafo_size < 4) {
                            int pos;
                            switch (log2_trafo_size) {
                            case 3:  pos = (y_c        << 3) +  x_c;       break;
                            case 4:  pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
                            case 5:  pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
                            default: pos = (y_c        << 2) +  x_c;
                            }
                            scale_m = scale_matrix[pos];
                        } else {
                            scale_m = dc_scale;
                        }
                    }
                    trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
                    if(trans_coeff_level < 0) {
                        if((~trans_coeff_level) & 0xFffffffffff8000)
                            trans_coeff_level = -32768;
                    } else {
                        if (trans_coeff_level & 0xffffffffffff8000)
                            trans_coeff_level = 32767;
                    }
                }
                coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
            }
        }
    }
    if (lc->cu.cu_transquant_bypass_flag) {
        s->hevcdsp.transquant_bypass[log2_trafo_size - 2](dst, coeffs, stride);
    } else {
        if (transform_skip_flag)
            s->hevcdsp.transform_skip(dst, coeffs, stride);
        else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 &&
                 log2_trafo_size == 2)
            s->hevcdsp.transform_4x4_luma_add(dst, coeffs, stride);
        else
            s->hevcdsp.transform_add[log2_trafo_size - 2](dst, coeffs, stride);
    }
}
['static void hls_residual_coding(HEVCContext *s, int x0, int y0,\n                                int log2_trafo_size, enum ScanType scan_idx,\n                                int c_idx)\n{\n#define GET_COORD(offset, n)                                    \\\n    do {                                                        \\\n        x_c = (scan_x_cg[offset >> 4] << 2) + scan_x_off[n];    \\\n        y_c = (scan_y_cg[offset >> 4] << 2) + scan_y_off[n];    \\\n    } while (0)\n    HEVCLocalContext *lc    = &s->HEVClc;\n    int transform_skip_flag = 0;\n    int last_significant_coeff_x, last_significant_coeff_y;\n    int last_scan_pos;\n    int n_end;\n    int num_coeff    = 0;\n    int greater1_ctx = 1;\n    int num_last_subset;\n    int x_cg_last_sig, y_cg_last_sig;\n    const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;\n    ptrdiff_t stride = s->frame->linesize[c_idx];\n    int hshift       = s->sps->hshift[c_idx];\n    int vshift       = s->sps->vshift[c_idx];\n    uint8_t *dst     = &s->frame->data[c_idx][(y0 >> vshift) * stride +\n                                              ((x0 >> hshift) << s->sps->pixel_shift)];\n    DECLARE_ALIGNED(16, int16_t, coeffs[MAX_TB_SIZE * MAX_TB_SIZE]) = { 0 };\n    DECLARE_ALIGNED(8, uint8_t, significant_coeff_group_flag[8][8]) = { { 0 } };\n    int trafo_size = 1 << log2_trafo_size;\n    int i, qp, shift, add, scale, scale_m;\n    const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };\n    const uint8_t *scale_matrix;\n    uint8_t dc_scale;\n    if (!lc->cu.cu_transquant_bypass_flag) {\n        static const int qp_c[] = {\n            29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37\n        };\n        static const uint8_t rem6[51 + 2 * 6 + 1] = {\n            0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,\n            3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,\n            0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,\n        };\n        static const uint8_t div6[51 + 2 * 6 + 1] = {\n            0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,  3,  3,  3,\n            3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6,  6,  6,  6,\n            7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,\n        };\n        int qp_y = lc->qp_y;\n        if (c_idx == 0) {\n            qp = qp_y + s->sps->qp_bd_offset;\n        } else {\n            int qp_i, offset;\n            if (c_idx == 1)\n                offset = s->pps->cb_qp_offset + s->sh.slice_cb_qp_offset;\n            else\n                offset = s->pps->cr_qp_offset + s->sh.slice_cr_qp_offset;\n            qp_i = av_clip_c(qp_y + offset, -s->sps->qp_bd_offset, 57);\n            if (qp_i < 30)\n                qp = qp_i;\n            else if (qp_i > 43)\n                qp = qp_i - 6;\n            else\n                qp = qp_c[qp_i - 30];\n            qp += s->sps->qp_bd_offset;\n        }\n        shift    = s->sps->bit_depth + log2_trafo_size - 5;\n        add      = 1 << (shift - 1);\n        scale    = level_scale[rem6[qp]] << (div6[qp]);\n        scale_m  = 16;\n        dc_scale = 16;\n        if (s->sps->scaling_list_enable_flag) {\n            const ScalingList *sl = s->pps->scaling_list_data_present_flag ?\n                                    &s->pps->scaling_list : &s->sps->scaling_list;\n            int matrix_id = lc->cu.pred_mode != MODE_INTRA;\n            if (log2_trafo_size != 5)\n                matrix_id = 3 * matrix_id + c_idx;\n            scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];\n            if (log2_trafo_size >= 4)\n                dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];\n        }\n    }\n    if (s->pps->transform_skip_enabled_flag &&\n        !lc->cu.cu_transquant_bypass_flag   &&\n        log2_trafo_size == 2) {\n        transform_skip_flag = ff_hevc_transform_skip_flag_decode(s, c_idx);\n    }\n    last_significant_coeff_x =\n        ff_hevc_last_significant_coeff_x_prefix_decode(s, c_idx, log2_trafo_size);\n    last_significant_coeff_y =\n        ff_hevc_last_significant_coeff_y_prefix_decode(s, c_idx, log2_trafo_size);\n    if (last_significant_coeff_x > 3) {\n        int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_x);\n        last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *\n                                   (2 + (last_significant_coeff_x & 1)) +\n                                   suffix;\n    }\n    if (last_significant_coeff_y > 3) {\n        int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_y);\n        last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *\n                                   (2 + (last_significant_coeff_y & 1)) +\n                                   suffix;\n    }\n    if (scan_idx == SCAN_VERT)\n        FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);\n    x_cg_last_sig = last_significant_coeff_x >> 2;\n    y_cg_last_sig = last_significant_coeff_y >> 2;\n    switch (scan_idx) {\n    case SCAN_DIAG: {\n        int last_x_c = last_significant_coeff_x & 3;\n        int last_y_c = last_significant_coeff_y & 3;\n        scan_x_off = ff_hevc_diag_scan4x4_x;\n        scan_y_off = ff_hevc_diag_scan4x4_y;\n        num_coeff  = diag_scan4x4_inv[last_y_c][last_x_c];\n        if (trafo_size == 4) {\n            scan_x_cg = scan_1x1;\n            scan_y_cg = scan_1x1;\n        } else if (trafo_size == 8) {\n            num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;\n            scan_x_cg  = diag_scan2x2_x;\n            scan_y_cg  = diag_scan2x2_y;\n        } else if (trafo_size == 16) {\n            num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;\n            scan_x_cg  = ff_hevc_diag_scan4x4_x;\n            scan_y_cg  = ff_hevc_diag_scan4x4_y;\n        } else {\n            num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;\n            scan_x_cg  = ff_hevc_diag_scan8x8_x;\n            scan_y_cg  = ff_hevc_diag_scan8x8_y;\n        }\n        break;\n    }\n    case SCAN_HORIZ:\n        scan_x_cg  = horiz_scan2x2_x;\n        scan_y_cg  = horiz_scan2x2_y;\n        scan_x_off = horiz_scan4x4_x;\n        scan_y_off = horiz_scan4x4_y;\n        num_coeff  = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];\n        break;\n    default:\n        scan_x_cg  = horiz_scan2x2_y;\n        scan_y_cg  = horiz_scan2x2_x;\n        scan_x_off = horiz_scan4x4_y;\n        scan_y_off = horiz_scan4x4_x;\n        num_coeff  = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];\n        break;\n    }\n    num_coeff++;\n    num_last_subset = (num_coeff - 1) >> 4;\n    for (i = num_last_subset; i >= 0; i--) {\n        int n, m;\n        int x_cg, y_cg, x_c, y_c;\n        int implicit_non_zero_coeff = 0;\n        int64_t trans_coeff_level;\n        int prev_sig = 0;\n        int offset   = i << 4;\n        uint8_t significant_coeff_flag_idx[16];\n        uint8_t nb_significant_coeff_flag = 0;\n        x_cg = scan_x_cg[i];\n        y_cg = scan_y_cg[i];\n        if (i < num_last_subset && i > 0) {\n            int ctx_cg = 0;\n            if (x_cg < (1 << (log2_trafo_size - 2)) - 1)\n                ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];\n            if (y_cg < (1 << (log2_trafo_size - 2)) - 1)\n                ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];\n            significant_coeff_group_flag[x_cg][y_cg] =\n                ff_hevc_significant_coeff_group_flag_decode(s, c_idx, ctx_cg);\n            implicit_non_zero_coeff = 1;\n        } else {\n            significant_coeff_group_flag[x_cg][y_cg] =\n                ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||\n                 (x_cg == 0 && y_cg == 0));\n        }\n        last_scan_pos = num_coeff - offset - 1;\n        if (i == num_last_subset) {\n            n_end                         = last_scan_pos - 1;\n            significant_coeff_flag_idx[0] = last_scan_pos;\n            nb_significant_coeff_flag     = 1;\n        } else {\n            n_end = 15;\n        }\n        if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)\n            prev_sig = significant_coeff_group_flag[x_cg + 1][y_cg];\n        if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)\n            prev_sig += significant_coeff_group_flag[x_cg][y_cg + 1] << 1;\n        for (n = n_end; n >= 0; n--) {\n            GET_COORD(offset, n);\n            if (significant_coeff_group_flag[x_cg][y_cg] &&\n                (n > 0 || implicit_non_zero_coeff == 0)) {\n                if (ff_hevc_significant_coeff_flag_decode(s, c_idx, x_c, y_c,\n                                                          log2_trafo_size,\n                                                          scan_idx,\n                                                          prev_sig) == 1) {\n                    significant_coeff_flag_idx[nb_significant_coeff_flag] = n;\n                    nb_significant_coeff_flag++;\n                    implicit_non_zero_coeff = 0;\n                }\n            } else {\n                int last_cg = (x_c == (x_cg << 2) && y_c == (y_cg << 2));\n                if (last_cg && implicit_non_zero_coeff && significant_coeff_group_flag[x_cg][y_cg]) {\n                    significant_coeff_flag_idx[nb_significant_coeff_flag] = n;\n                    nb_significant_coeff_flag++;\n                }\n            }\n        }\n        n_end = nb_significant_coeff_flag;\n        if (n_end) {\n            int first_nz_pos_in_cg = 16;\n            int last_nz_pos_in_cg = -1;\n            int c_rice_param = 0;\n            int first_greater1_coeff_idx = -1;\n            uint8_t coeff_abs_level_greater1_flag[16] = { 0 };\n            uint16_t coeff_sign_flag;\n            int sum_abs = 0;\n            int sign_hidden = 0;\n            int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;\n            if (!(i == num_last_subset) && greater1_ctx == 0)\n                ctx_set++;\n            greater1_ctx      = 1;\n            last_nz_pos_in_cg = significant_coeff_flag_idx[0];\n            for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {\n                int n_idx = significant_coeff_flag_idx[m];\n                int inc   = (ctx_set << 2) + greater1_ctx;\n                coeff_abs_level_greater1_flag[n_idx] =\n                    ff_hevc_coeff_abs_level_greater1_flag_decode(s, c_idx, inc);\n                if (coeff_abs_level_greater1_flag[n_idx]) {\n                    greater1_ctx = 0;\n                } else if (greater1_ctx > 0 && greater1_ctx < 3) {\n                    greater1_ctx++;\n                }\n                if (coeff_abs_level_greater1_flag[n_idx] &&\n                    first_greater1_coeff_idx == -1)\n                    first_greater1_coeff_idx = n_idx;\n            }\n            first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];\n            sign_hidden        = last_nz_pos_in_cg - first_nz_pos_in_cg >= 4 &&\n                                 !lc->cu.cu_transquant_bypass_flag;\n            if (first_greater1_coeff_idx != -1) {\n                coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += ff_hevc_coeff_abs_level_greater2_flag_decode(s, c_idx, ctx_set);\n            }\n            if (!s->pps->sign_data_hiding_flag || !sign_hidden) {\n                coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);\n            } else {\n                coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));\n            }\n            for (m = 0; m < n_end; m++) {\n                n = significant_coeff_flag_idx[m];\n                GET_COORD(offset, n);\n                trans_coeff_level = 1 + coeff_abs_level_greater1_flag[n];\n                if (trans_coeff_level == ((m < 8) ?\n                                          ((n == first_greater1_coeff_idx) ? 3 : 2) : 1)) {\n                    int last_coeff_abs_level_remaining = ff_hevc_coeff_abs_level_remaining(s, trans_coeff_level, c_rice_param);\n                    trans_coeff_level += last_coeff_abs_level_remaining;\n                    if ((trans_coeff_level) > (3 * (1 << c_rice_param)))\n                        c_rice_param = FFMIN(c_rice_param + 1, 4);\n                }\n                if (s->pps->sign_data_hiding_flag && sign_hidden) {\n                    sum_abs += trans_coeff_level;\n                    if (n == first_nz_pos_in_cg && ((sum_abs & 1) == 1))\n                        trans_coeff_level = -trans_coeff_level;\n                }\n                if (coeff_sign_flag >> 15)\n                    trans_coeff_level = -trans_coeff_level;\n                coeff_sign_flag <<= 1;\n                if (!lc->cu.cu_transquant_bypass_flag) {\n                    if (s->sps->scaling_list_enable_flag) {\n                        if (y_c || x_c || log2_trafo_size < 4) {\n                            int pos;\n                            switch (log2_trafo_size) {\n                            case 3:  pos = (y_c        << 3) +  x_c;       break;\n                            case 4:  pos = ((y_c >> 1) << 3) + (x_c >> 1); break;\n                            case 5:  pos = ((y_c >> 2) << 3) + (x_c >> 2); break;\n                            default: pos = (y_c        << 2) +  x_c;\n                            }\n                            scale_m = scale_matrix[pos];\n                        } else {\n                            scale_m = dc_scale;\n                        }\n                    }\n                    trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;\n                    if(trans_coeff_level < 0) {\n                        if((~trans_coeff_level) & 0xFffffffffff8000)\n                            trans_coeff_level = -32768;\n                    } else {\n                        if (trans_coeff_level & 0xffffffffffff8000)\n                            trans_coeff_level = 32767;\n                    }\n                }\n                coeffs[y_c * trafo_size + x_c] = trans_coeff_level;\n            }\n        }\n    }\n    if (lc->cu.cu_transquant_bypass_flag) {\n        s->hevcdsp.transquant_bypass[log2_trafo_size - 2](dst, coeffs, stride);\n    } else {\n        if (transform_skip_flag)\n            s->hevcdsp.transform_skip(dst, coeffs, stride);\n        else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 &&\n                 log2_trafo_size == 2)\n            s->hevcdsp.transform_4x4_luma_add(dst, coeffs, stride);\n        else\n            s->hevcdsp.transform_add[log2_trafo_size - 2](dst, coeffs, stride);\n    }\n}']