static int pic_arrays_init(HEVCContext *s)

{

    int log2_min_cb_size     = s->sps->log2_min_cb_size;

    int width                = s->sps->width;

    int height               = s->sps->height;

    int pic_size             = width * height;

    int pic_size_in_ctb      = ((width  >> log2_min_cb_size) + 1) *

                               ((height >> log2_min_cb_size) + 1);

    int ctb_count            = s->sps->ctb_width * s->sps->ctb_height;

    int min_pu_width  = width  >> s->sps->log2_min_pu_size;

    int pic_height_in_min_pu = height >> s->sps->log2_min_pu_size;

    int pic_size_in_min_pu   = min_pu_width * pic_height_in_min_pu;

    int pic_width_in_min_tu  = width  >> s->sps->log2_min_tb_size;

    int pic_height_in_min_tu = height >> s->sps->log2_min_tb_size;



    s->bs_width  = width  >> 3;

    s->bs_height = height >> 3;



    s->sao           = av_mallocz_array(ctb_count, sizeof(*s->sao));

    s->deblock       = av_mallocz_array(ctb_count, sizeof(*s->deblock));

    s->split_cu_flag = av_malloc(pic_size);

    if (!s->sao || !s->deblock || !s->split_cu_flag)

        goto fail;



    s->skip_flag    = av_malloc(pic_size_in_ctb);

    s->tab_ct_depth = av_malloc(s->sps->min_cb_height * s->sps->min_cb_width);

    if (!s->skip_flag || !s->tab_ct_depth)

        goto fail;



    s->tab_ipm  = av_malloc(pic_size_in_min_pu);

    s->cbf_luma = av_malloc(pic_width_in_min_tu * pic_height_in_min_tu);

    s->is_pcm   = av_malloc(pic_size_in_min_pu);

    if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)

        goto fail;



    s->filter_slice_edges = av_malloc(ctb_count);

    s->tab_slice_address  = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address));

    s->qp_y_tab           = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab));

    if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)

        goto fail;



    s->horizontal_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));

    s->vertical_bs   = av_mallocz(2 * s->bs_width * (s->bs_height + 1));

    if (!s->horizontal_bs || !s->vertical_bs)

        goto fail;



    s->tab_mvf_pool = av_buffer_pool_init(pic_size_in_min_pu * sizeof(MvField),

                                          av_buffer_alloc);

    s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),

                                          av_buffer_allocz);

    if (!s->tab_mvf_pool || !s->rpl_tab_pool)

        goto fail;



    return 0;

fail:

    pic_arrays_free(s);

    return AVERROR(ENOMEM);

}

static int pic_arrays_init(HEVCContext *s)

{

    int log2_min_cb_size     = s->sps->log2_min_cb_size;

    int width                = s->sps->width;

    int height               = s->sps->height;

    int pic_size             = width * height;

    int pic_size_in_ctb      = ((width  >> log2_min_cb_size) + 1) *

                               ((height >> log2_min_cb_size) + 1);

    int ctb_count            = s->sps->ctb_width * s->sps->ctb_height;

    int min_pu_width  = width  >> s->sps->log2_min_pu_size;

    int pic_height_in_min_pu = height >> s->sps->log2_min_pu_size;

    int pic_size_in_min_pu   = min_pu_width * pic_height_in_min_pu;

    int pic_width_in_min_tu  = width  >> s->sps->log2_min_tb_size;

    int pic_height_in_min_tu = height >> s->sps->log2_min_tb_size;



    s->bs_width  = width  >> 3;

    s->bs_height = height >> 3;



    s->sao           = av_mallocz_array(ctb_count, sizeof(*s->sao));

    s->deblock       = av_mallocz_array(ctb_count, sizeof(*s->deblock));

    s->split_cu_flag = av_malloc(pic_size);

    if (!s->sao || !s->deblock || !s->split_cu_flag)

        goto fail;



    s->skip_flag    = av_malloc(pic_size_in_ctb);

    s->tab_ct_depth = av_malloc(s->sps->min_cb_height * s->sps->min_cb_width);

    if (!s->skip_flag || !s->tab_ct_depth)

        goto fail;



    s->tab_ipm  = av_malloc(pic_size_in_min_pu);

    s->cbf_luma = av_malloc(pic_width_in_min_tu * pic_height_in_min_tu);

    s->is_pcm   = av_malloc(pic_size_in_min_pu);

    if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)

        goto fail;



    s->filter_slice_edges = av_malloc(ctb_count);

    s->tab_slice_address  = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address));

    s->qp_y_tab           = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab));

    if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)

        goto fail;



    s->horizontal_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));

    s->vertical_bs   = av_mallocz(2 * s->bs_width * (s->bs_height + 1));

    if (!s->horizontal_bs || !s->vertical_bs)

        goto fail;



    s->tab_mvf_pool = av_buffer_pool_init(pic_size_in_min_pu * sizeof(MvField),

                                          av_buffer_alloc);

    s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),

                                          av_buffer_allocz);

    if (!s->tab_mvf_pool || !s->rpl_tab_pool)

        goto fail;



    return 0;

fail:

    pic_arrays_free(s);

    return AVERROR(ENOMEM);

}

static int FUNC_0(HEVCContext *VAR_0)

{

    int VAR_1     = VAR_0->sps->VAR_1;

    int VAR_2                = VAR_0->sps->VAR_2;

    int VAR_3               = VAR_0->sps->VAR_3;

    int VAR_4             = VAR_2 * VAR_3;

    int VAR_5      = ((VAR_2  >> VAR_1) + 1) *

                               ((VAR_3 >> VAR_1) + 1);

    int VAR_6            = VAR_0->sps->ctb_width * VAR_0->sps->ctb_height;

    int VAR_7  = VAR_2  >> VAR_0->sps->log2_min_pu_size;

    int VAR_8 = VAR_3 >> VAR_0->sps->log2_min_pu_size;

    int VAR_9   = VAR_7 * VAR_8;

    int VAR_10  = VAR_2  >> VAR_0->sps->log2_min_tb_size;

    int VAR_11 = VAR_3 >> VAR_0->sps->log2_min_tb_size;



    VAR_0->bs_width  = VAR_2  >> 3;

    VAR_0->bs_height = VAR_3 >> 3;



    VAR_0->sao           = av_mallocz_array(VAR_6, sizeof(*VAR_0->sao));

    VAR_0->deblock       = av_mallocz_array(VAR_6, sizeof(*VAR_0->deblock));

    VAR_0->split_cu_flag = av_malloc(VAR_4);

    if (!VAR_0->sao || !VAR_0->deblock || !VAR_0->split_cu_flag)

        goto fail;



    VAR_0->skip_flag    = av_malloc(VAR_5);

    VAR_0->tab_ct_depth = av_malloc(VAR_0->sps->min_cb_height * VAR_0->sps->min_cb_width);

    if (!VAR_0->skip_flag || !VAR_0->tab_ct_depth)

        goto fail;



    VAR_0->tab_ipm  = av_malloc(VAR_9);

    VAR_0->cbf_luma = av_malloc(VAR_10 * VAR_11);

    VAR_0->is_pcm   = av_malloc(VAR_9);

    if (!VAR_0->tab_ipm || !VAR_0->cbf_luma || !VAR_0->is_pcm)

        goto fail;



    VAR_0->filter_slice_edges = av_malloc(VAR_6);

    VAR_0->tab_slice_address  = av_malloc(VAR_5 * sizeof(*VAR_0->tab_slice_address));

    VAR_0->qp_y_tab           = av_malloc(VAR_5 * sizeof(*VAR_0->qp_y_tab));

    if (!VAR_0->qp_y_tab || !VAR_0->filter_slice_edges || !VAR_0->tab_slice_address)

        goto fail;



    VAR_0->horizontal_bs = av_mallocz(2 * VAR_0->bs_width * (VAR_0->bs_height + 1));

    VAR_0->vertical_bs   = av_mallocz(2 * VAR_0->bs_width * (VAR_0->bs_height + 1));

    if (!VAR_0->horizontal_bs || !VAR_0->vertical_bs)

        goto fail;



    VAR_0->tab_mvf_pool = av_buffer_pool_init(VAR_9 * sizeof(MvField),

                                          av_buffer_alloc);

    VAR_0->rpl_tab_pool = av_buffer_pool_init(VAR_6 * sizeof(RefPicListTab),

                                          av_buffer_allocz);

    if (!VAR_0->tab_mvf_pool || !VAR_0->rpl_tab_pool)

        goto fail;



    return 0;

fail:

    pic_arrays_free(VAR_0);

    return AVERROR(ENOMEM);

}

static int FUNC_0(HEVCContext *VAR_0)
{ int VAR_1     = VAR_0->sps->VAR_1; int VAR_2                = VAR_0->sps->VAR_2; int VAR_3               = VAR_0->sps->VAR_3; int VAR_4             = VAR_2 * VAR_3; int VAR_5      = ((VAR_2  >> VAR_1) + 1) *
((VAR_3 >> VAR_1) + 1); int VAR_6            = VAR_0->sps->ctb_width * VAR_0->sps->ctb_height; int VAR_7  = VAR_2  >> VAR_0->sps->log2_min_pu_size; int VAR_8 = VAR_3 >> VAR_0->sps->log2_min_pu_size; int VAR_9   = VAR_7 * VAR_8; int VAR_10  = VAR_2  >> VAR_0->sps->log2_min_tb_size; int VAR_11 = VAR_3 >> VAR_0->sps->log2_min_tb_size; VAR_0->bs_width  = VAR_2  >> 3; VAR_0->bs_height = VAR_3 >> 3; VAR_0->sao           = av_mallocz_array(VAR_6, sizeof(*VAR_0->sao)); VAR_0->deblock       = av_mallocz_array(VAR_6, sizeof(*VAR_0->deblock)); VAR_0->split_cu_flag = av_malloc(VAR_4); if (!VAR_0->sao || !VAR_0->deblock || !VAR_0->split_cu_flag)
goto fail; VAR_0->skip_flag    = av_malloc(VAR_5); VAR_0->tab_ct_depth = av_malloc(VAR_0->sps->min_cb_height * VAR_0->sps->min_cb_width); if (!VAR_0->skip_flag || !VAR_0->tab_ct_depth)
goto fail; VAR_0->tab_ipm  = av_malloc(VAR_9); VAR_0->cbf_luma = av_malloc(VAR_10 * VAR_11); VAR_0->is_pcm   = av_malloc(VAR_9); if (!VAR_0->tab_ipm || !VAR_0->cbf_luma || !VAR_0->is_pcm)
goto fail; VAR_0->filter_slice_edges = av_malloc(VAR_6); VAR_0->tab_slice_address  = av_malloc(VAR_5 * sizeof(*VAR_0->tab_slice_address)); VAR_0->qp_y_tab           = av_malloc(VAR_5 * sizeof(*VAR_0->qp_y_tab)); if (!VAR_0->qp_y_tab || !VAR_0->filter_slice_edges || !VAR_0->tab_slice_address)
goto fail; VAR_0->horizontal_bs = av_mallocz(2 * VAR_0->bs_width * (VAR_0->bs_height + 1)); VAR_0->vertical_bs   = av_mallocz(2 * VAR_0->bs_width * (VAR_0->bs_height + 1)); if (!VAR_0->horizontal_bs || !VAR_0->vertical_bs)
goto fail; VAR_0->tab_mvf_pool = av_buffer_pool_init(VAR_9 * sizeof(MvField),
av_buffer_alloc); VAR_0->rpl_tab_pool = av_buffer_pool_init(VAR_6 * sizeof(RefPicListTab),
av_buffer_allocz); if (!VAR_0->tab_mvf_pool || !VAR_0->rpl_tab_pool)
goto fail; return 0; fail:
pic_arrays_free(VAR_0); return AVERROR(ENOMEM); }