static int mxg_update_cache(AVFormatContext *s, unsigned int cache_size)

{

    MXGContext *mxg = s->priv_data;

    unsigned int current_pos = mxg->buffer_ptr - mxg->buffer;

    unsigned int soi_pos;

    int ret;



    /* reallocate internal buffer */

    if (current_pos > current_pos + cache_size)

        return AVERROR(ENOMEM);

    soi_pos = mxg->soi_ptr - mxg->buffer;

    mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,

                                  current_pos + cache_size +

                                  FF_INPUT_BUFFER_PADDING_SIZE);

    if (!mxg->buffer)

        return AVERROR(ENOMEM);

    mxg->buffer_ptr = mxg->buffer + current_pos;

    if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + soi_pos;



    /* get data */

    ret = avio_read(s->pb, mxg->buffer_ptr + mxg->cache_size,

                     cache_size - mxg->cache_size);

    if (ret < 0)

        return ret;



    mxg->cache_size += ret;



    return ret;

}

static int mxg_update_cache(AVFormatContext *s, unsigned int cache_size)

{

    MXGContext *mxg = s->priv_data;

    unsigned int current_pos = mxg->buffer_ptr - mxg->buffer;

    unsigned int soi_pos;

    int ret;



    

    if (current_pos > current_pos + cache_size)

        return AVERROR(ENOMEM);

    soi_pos = mxg->soi_ptr - mxg->buffer;

    mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,

                                  current_pos + cache_size +

                                  FF_INPUT_BUFFER_PADDING_SIZE);

    if (!mxg->buffer)

        return AVERROR(ENOMEM);

    mxg->buffer_ptr = mxg->buffer + current_pos;

    if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + soi_pos;



    

    ret = avio_read(s->pb, mxg->buffer_ptr + mxg->cache_size,

                     cache_size - mxg->cache_size);

    if (ret < 0)

        return ret;



    mxg->cache_size += ret;



    return ret;

}

    mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,                                   current_pos + cache_size +                                   FF_INPUT_BUFFER_PADDING_SIZE);     if (!mxg->buffer)
static int FUNC_0(AVFormatContext *VAR_0, unsigned int VAR_1)

{

    MXGContext *mxg = VAR_0->priv_data;

    unsigned int VAR_2 = mxg->buffer_ptr - mxg->buffer;

    unsigned int VAR_3;

    int VAR_4;



    

    if (VAR_2 > VAR_2 + VAR_1)

        return AVERROR(ENOMEM);

    VAR_3 = mxg->soi_ptr - mxg->buffer;

    mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,

                                  VAR_2 + VAR_1 +

                                  FF_INPUT_BUFFER_PADDING_SIZE);

    if (!mxg->buffer)

        return AVERROR(ENOMEM);

    mxg->buffer_ptr = mxg->buffer + VAR_2;

    if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + VAR_3;



    

    VAR_4 = avio_read(VAR_0->pb, mxg->buffer_ptr + mxg->VAR_1,

                     VAR_1 - mxg->VAR_1);

    if (VAR_4 < 0)

        return VAR_4;



    mxg->VAR_1 += VAR_4;



    return VAR_4;

}

static int FUNC_0(AVFormatContext *VAR_0, unsigned int VAR_1)
{ MXGContext *mxg = VAR_0->priv_data; unsigned int VAR_2 = mxg->buffer_ptr - mxg->buffer; unsigned int VAR_3; int VAR_4; if (VAR_2 > VAR_2 + VAR_1)
return AVERROR(ENOMEM); VAR_3 = mxg->soi_ptr - mxg->buffer; mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,
VAR_2 + VAR_1 +
FF_INPUT_BUFFER_PADDING_SIZE); if (!mxg->buffer)
return AVERROR(ENOMEM); mxg->buffer_ptr = mxg->buffer + VAR_2; if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + VAR_3; VAR_4 = avio_read(VAR_0->pb, mxg->buffer_ptr + mxg->VAR_1,
VAR_1 - mxg->VAR_1); if (VAR_4 < 0)
return VAR_4; mxg->VAR_1 += VAR_4; return VAR_4; }