static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)

{

    int log2_min_cb_size = sps->log2_min_cb_size;

    int width            = sps->width;

    int height           = sps->height;

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

                           ((height >> log2_min_cb_size) + 1);

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

    int min_pu_size      = sps->min_pu_width * sps->min_pu_height;



    s->bs_width  = (width  >> 2) + 1;

    s->bs_height = (height >> 2) + 1;



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

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

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

        goto fail;



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

    s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);

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

        goto fail;



    s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);

    s->tab_ipm  = av_mallocz(min_pu_size);

    s->is_pcm   = av_malloc((sps->min_pu_width + 1) * (sps->min_pu_height + 1));

    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_array(pic_size_in_ctb,

                                      sizeof(*s->tab_slice_address));

    s->qp_y_tab           = av_malloc_array(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_array(s->bs_width, s->bs_height);

    s->vertical_bs   = av_mallocz_array(s->bs_width, s->bs_height);

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

        goto fail;



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

                                          av_buffer_allocz);

    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, const HEVCSPS *sps)

{

    int log2_min_cb_size = sps->log2_min_cb_size;

    int width            = sps->width;

    int height           = sps->height;

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

                           ((height >> log2_min_cb_size) + 1);

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

    int min_pu_size      = sps->min_pu_width * sps->min_pu_height;



    s->bs_width  = (width  >> 2) + 1;

    s->bs_height = (height >> 2) + 1;



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

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

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

        goto fail;



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

    s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);

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

        goto fail;



    s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);

    s->tab_ipm  = av_mallocz(min_pu_size);

    s->is_pcm   = av_malloc((sps->min_pu_width + 1) * (sps->min_pu_height + 1));

    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_array(pic_size_in_ctb,

                                      sizeof(*s->tab_slice_address));

    s->qp_y_tab           = av_malloc_array(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_array(s->bs_width, s->bs_height);

    s->vertical_bs   = av_mallocz_array(s->bs_width, s->bs_height);

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

        goto fail;



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

                                          av_buffer_allocz);

    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);

}

    s->filter_slice_edges = av_malloc(ctb_count);
static int FUNC_0(HEVCContext *VAR_0, const HEVCSPS *VAR_1)

{

    int VAR_2 = VAR_1->VAR_2;

    int VAR_3            = VAR_1->VAR_3;

    int VAR_4           = VAR_1->VAR_4;

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

                           ((VAR_4 >> VAR_2) + 1);

    int VAR_6        = VAR_1->ctb_width * VAR_1->ctb_height;

    int VAR_7      = VAR_1->min_pu_width * VAR_1->min_pu_height;



    VAR_0->bs_width  = (VAR_3  >> 2) + 1;

    VAR_0->bs_height = (VAR_4 >> 2) + 1;



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

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

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

        goto fail;



    VAR_0->skip_flag    = av_malloc(VAR_1->min_cb_height * VAR_1->min_cb_width);

    VAR_0->tab_ct_depth = av_malloc_array(VAR_1->min_cb_height, VAR_1->min_cb_width);

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

        goto fail;



    VAR_0->cbf_luma = av_malloc_array(VAR_1->min_tb_width, VAR_1->min_tb_height);

    VAR_0->tab_ipm  = av_mallocz(VAR_7);

    VAR_0->is_pcm   = av_malloc((VAR_1->min_pu_width + 1) * (VAR_1->min_pu_height + 1));

    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_array(VAR_5,

                                      sizeof(*VAR_0->tab_slice_address));

    VAR_0->qp_y_tab           = av_malloc_array(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_array(VAR_0->bs_width, VAR_0->bs_height);

    VAR_0->vertical_bs   = av_mallocz_array(VAR_0->bs_width, VAR_0->bs_height);

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

        goto fail;



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

                                          av_buffer_allocz);

    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, const HEVCSPS *VAR_1)
{ int VAR_2 = VAR_1->VAR_2; int VAR_3            = VAR_1->VAR_3; int VAR_4           = VAR_1->VAR_4; int VAR_5  = ((VAR_3  >> VAR_2) + 1) *
((VAR_4 >> VAR_2) + 1); int VAR_6        = VAR_1->ctb_width * VAR_1->ctb_height; int VAR_7      = VAR_1->min_pu_width * VAR_1->min_pu_height; VAR_0->bs_width  = (VAR_3  >> 2) + 1; VAR_0->bs_height = (VAR_4 >> 2) + 1; VAR_0->sao           = av_mallocz_array(VAR_6, sizeof(*VAR_0->sao)); VAR_0->deblock       = av_mallocz_array(VAR_6, sizeof(*VAR_0->deblock)); if (!VAR_0->sao || !VAR_0->deblock)
goto fail; VAR_0->skip_flag    = av_malloc(VAR_1->min_cb_height * VAR_1->min_cb_width); VAR_0->tab_ct_depth = av_malloc_array(VAR_1->min_cb_height, VAR_1->min_cb_width); if (!VAR_0->skip_flag || !VAR_0->tab_ct_depth)
goto fail; VAR_0->cbf_luma = av_malloc_array(VAR_1->min_tb_width, VAR_1->min_tb_height); VAR_0->tab_ipm  = av_mallocz(VAR_7); VAR_0->is_pcm   = av_malloc((VAR_1->min_pu_width + 1) * (VAR_1->min_pu_height + 1)); 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_array(VAR_5,
sizeof(*VAR_0->tab_slice_address)); VAR_0->qp_y_tab           = av_malloc_array(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_array(VAR_0->bs_width, VAR_0->bs_height); VAR_0->vertical_bs   = av_mallocz_array(VAR_0->bs_width, VAR_0->bs_height); if (!VAR_0->horizontal_bs || !VAR_0->vertical_bs)
goto fail; VAR_0->tab_mvf_pool = av_buffer_pool_init(VAR_7 * sizeof(MvField),
av_buffer_allocz); 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); }