static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
                               int log2_cb_size, int cb_depth)
{
    HEVCLocalContext *lc = &s->HEVClc;
    const int cb_size    = 1 << log2_cb_size;

    lc->ct.depth = cb_depth;
    if (x0 + cb_size <= s->sps->width  &&
        y0 + cb_size <= s->sps->height &&
        log2_cb_size > s->sps->log2_min_cb_size) {
        SAMPLE(s->split_cu_flag, x0, y0) =
            ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
    } else {
        SAMPLE(s->split_cu_flag, x0, y0) =
            (log2_cb_size > s->sps->log2_min_cb_size);
    }
    if (s->pps->cu_qp_delta_enabled_flag &&
        log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {
        lc->tu.is_cu_qp_delta_coded = 0;
        lc->tu.cu_qp_delta          = 0;
    }

    if (SAMPLE(s->split_cu_flag, x0, y0)) {
        const int cb_size_split = cb_size >> 1;
        const int x1 = x0 + cb_size_split;
        const int y1 = y0 + cb_size_split;

        log2_cb_size--;
        cb_depth++;

#define SUBDIVIDE(x, y)                                                \
do {                                                                   \
    if (x < s->sps->width && y < s->sps->height) {                     \
        int ret = hls_coding_quadtree(s, x, y, log2_cb_size, cb_depth);\
        if (ret < 0)                                                   \
            return ret;                                                \
    }                                                                  \
} while (0)

        SUBDIVIDE(x0, y0);
        SUBDIVIDE(x1, y0);
        SUBDIVIDE(x0, y1);
        SUBDIVIDE(x1, y1);
    } else {
        int ret = hls_coding_unit(s, x0, y0, log2_cb_size);
        if (ret < 0)
            return ret;
    }

    return 0;
}
static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
                               int log2_cb_size, int cb_depth)
{
    HEVCLocalContext *lc = &s->HEVClc;
    const int cb_size    = 1 << log2_cb_size;

    lc->ct.depth = cb_depth;
    if (x0 + cb_size <= s->sps->width  &&
        y0 + cb_size <= s->sps->height &&
        log2_cb_size > s->sps->log2_min_cb_size) {
        SAMPLE(s->split_cu_flag, x0, y0) =
            ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
    } else {
        SAMPLE(s->split_cu_flag, x0, y0) =
            (log2_cb_size > s->sps->log2_min_cb_size);
    }
    if (s->pps->cu_qp_delta_enabled_flag &&
        log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {
        lc->tu.is_cu_qp_delta_coded = 0;
        lc->tu.cu_qp_delta          = 0;
    }

    if (SAMPLE(s->split_cu_flag, x0, y0)) {
        const int cb_size_split = cb_size >> 1;
        const int x1 = x0 + cb_size_split;
        const int y1 = y0 + cb_size_split;

        log2_cb_size--;
        cb_depth++;

#define SUBDIVIDE(x, y)                                                \
do {                                                                   \
    if (x < s->sps->width && y < s->sps->height) {                     \
        int ret = hls_coding_quadtree(s, x, y, log2_cb_size, cb_depth);\
        if (ret < 0)                                                   \
            return ret;                                                \
    }                                                                  \
} while (0)

        SUBDIVIDE(x0, y0);
        SUBDIVIDE(x1, y0);
        SUBDIVIDE(x0, y1);
        SUBDIVIDE(x1, y1);
    } else {
        int ret = hls_coding_unit(s, x0, y0, log2_cb_size);
        if (ret < 0)
            return ret;
    }

    return 0;
}