int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)

{

    int64_t buffer_start;

    int buffer_size;

    int overlap, new_size, alloc_size;



    if (s->write_flag)

        return AVERROR(EINVAL);



    buffer_size = s->buf_end - s->buffer;



    /* the buffers must touch or overlap */

    if ((buffer_start = s->pos - buffer_size) > buf_size)

        return AVERROR(EINVAL);



    overlap = buf_size - buffer_start;

    new_size = buf_size + buffer_size - overlap;



    alloc_size = FFMAX(s->buffer_size, new_size);

    if (alloc_size > buf_size)

        if (!(buf = av_realloc_f(buf, 1, alloc_size)))

            return AVERROR(ENOMEM);



    if (new_size > buf_size) {

        memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);

        buf_size = new_size;

    }



    av_free(s->buffer);

    s->buf_ptr = s->buffer = buf;

    s->buffer_size = alloc_size;

    s->pos = buf_size;

    s->buf_end = s->buf_ptr + buf_size;

    s->eof_reached = 0;

    s->must_flush = 0;



    return 0;

}

int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)

{

    int64_t buffer_start;

    int buffer_size;

    int overlap, new_size, alloc_size;



    if (s->write_flag)

        return AVERROR(EINVAL);



    buffer_size = s->buf_end - s->buffer;



    

    if ((buffer_start = s->pos - buffer_size) > buf_size)

        return AVERROR(EINVAL);



    overlap = buf_size - buffer_start;

    new_size = buf_size + buffer_size - overlap;



    alloc_size = FFMAX(s->buffer_size, new_size);

    if (alloc_size > buf_size)

        if (!(buf = av_realloc_f(buf, 1, alloc_size)))

            return AVERROR(ENOMEM);



    if (new_size > buf_size) {

        memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);

        buf_size = new_size;

    }



    av_free(s->buffer);

    s->buf_ptr = s->buffer = buf;

    s->buffer_size = alloc_size;

    s->pos = buf_size;

    s->buf_end = s->buf_ptr + buf_size;

    s->eof_reached = 0;

    s->must_flush = 0;



    return 0;

}

int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)     if (s->write_flag)     if ((buffer_start = s->pos - buffer_size) > buf_size)         if (!(buf = av_realloc_f(buf, 1, alloc_size)))
int FUNC_0(AVIOContext *VAR_0, unsigned char *VAR_1, int VAR_2)

{

    int64_t buffer_start;

    int VAR_3;

    int VAR_4, VAR_5, VAR_6;



    if (VAR_0->write_flag)

        return AVERROR(EINVAL);



    VAR_3 = VAR_0->buf_end - VAR_0->buffer;



    

    if ((buffer_start = VAR_0->pos - VAR_3) > VAR_2)

        return AVERROR(EINVAL);



    VAR_4 = VAR_2 - buffer_start;

    VAR_5 = VAR_2 + VAR_3 - VAR_4;



    VAR_6 = FFMAX(VAR_0->VAR_3, VAR_5);

    if (VAR_6 > VAR_2)

        if (!(VAR_1 = av_realloc_f(VAR_1, 1, VAR_6)))

            return AVERROR(ENOMEM);



    if (VAR_5 > VAR_2) {

        memcpy(VAR_1 + VAR_2, VAR_0->buffer + VAR_4, VAR_3 - VAR_4);

        VAR_2 = VAR_5;

    }



    av_free(VAR_0->buffer);

    VAR_0->buf_ptr = VAR_0->buffer = VAR_1;

    VAR_0->VAR_3 = VAR_6;

    VAR_0->pos = VAR_2;

    VAR_0->buf_end = VAR_0->buf_ptr + VAR_2;

    VAR_0->eof_reached = 0;

    VAR_0->must_flush = 0;



    return 0;

}

int FUNC_0(AVIOContext *VAR_0, unsigned char *VAR_1, int VAR_2)
{ int64_t buffer_start; int VAR_3; int VAR_4, VAR_5, VAR_6; if (VAR_0->write_flag)
return AVERROR(EINVAL); VAR_3 = VAR_0->buf_end - VAR_0->buffer; if ((buffer_start = VAR_0->pos - VAR_3) > VAR_2)
return AVERROR(EINVAL); VAR_4 = VAR_2 - buffer_start; VAR_5 = VAR_2 + VAR_3 - VAR_4; VAR_6 = FFMAX(VAR_0->VAR_3, VAR_5); if (VAR_6 > VAR_2)
if (!(VAR_1 = av_realloc_f(VAR_1, 1, VAR_6)))
return AVERROR(ENOMEM); if (VAR_5 > VAR_2) { memcpy(VAR_1 + VAR_2, VAR_0->buffer + VAR_4, VAR_3 - VAR_4); VAR_2 = VAR_5; } av_free(VAR_0->buffer); VAR_0->buf_ptr = VAR_0->buffer = VAR_1; VAR_0->VAR_3 = VAR_6; VAR_0->pos = VAR_2; VAR_0->buf_end = VAR_0->buf_ptr + VAR_2; VAR_0->eof_reached = 0; VAR_0->must_flush = 0; return 0; }