int ffio_ensure_seekback(AVIOContext *s, int buf_size)

{

    uint8_t *buffer;

    int max_buffer_size = s->max_packet_size ?

                          s->max_packet_size : IO_BUFFER_SIZE;



    buf_size += s->buf_ptr - s->buffer + max_buffer_size;



    if (buf_size < s->buffer_size || s->seekable)

        return 0;

    av_assert0(!s->write_flag);



    buffer = av_malloc(buf_size);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, s->buffer, s->buffer_size);

    av_free(s->buffer);

    s->buf_ptr = buffer + (s->buf_ptr - s->buffer);

    s->buf_end = buffer + (s->buf_end - s->buffer);

    s->buffer = buffer;

    s->buffer_size = buf_size;

    return 0;

}

int ffio_ensure_seekback(AVIOContext *s, int buf_size)

{

    uint8_t *buffer;

    int max_buffer_size = s->max_packet_size ?

                          s->max_packet_size : IO_BUFFER_SIZE;



    buf_size += s->buf_ptr - s->buffer + max_buffer_size;



    if (buf_size < s->buffer_size || s->seekable)

        return 0;

    av_assert0(!s->write_flag);



    buffer = av_malloc(buf_size);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, s->buffer, s->buffer_size);

    av_free(s->buffer);

    s->buf_ptr = buffer + (s->buf_ptr - s->buffer);

    s->buf_end = buffer + (s->buf_end - s->buffer);

    s->buffer = buffer;

    s->buffer_size = buf_size;

    return 0;

}

int FUNC_0(AVIOContext *VAR_0, int VAR_1)

{

    uint8_t *buffer;

    int VAR_2 = VAR_0->max_packet_size ?

                          VAR_0->max_packet_size : IO_BUFFER_SIZE;



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



    if (VAR_1 < VAR_0->buffer_size || VAR_0->seekable)

        return 0;

    av_assert0(!VAR_0->write_flag);



    buffer = av_malloc(VAR_1);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, VAR_0->buffer, VAR_0->buffer_size);

    av_free(VAR_0->buffer);

    VAR_0->buf_ptr = buffer + (VAR_0->buf_ptr - VAR_0->buffer);

    VAR_0->buf_end = buffer + (VAR_0->buf_end - VAR_0->buffer);

    VAR_0->buffer = buffer;

    VAR_0->buffer_size = VAR_1;

    return 0;

}

int FUNC_0(AVIOContext *VAR_0, int VAR_1)
{ uint8_t *buffer; int VAR_2 = VAR_0->max_packet_size ?
VAR_0->max_packet_size : IO_BUFFER_SIZE; VAR_1 += VAR_0->buf_ptr - VAR_0->buffer + VAR_2; if (VAR_1 < VAR_0->buffer_size || VAR_0->seekable)
return 0; av_assert0(!VAR_0->write_flag); buffer = av_malloc(VAR_1); if (!buffer)
return AVERROR(ENOMEM); memcpy(buffer, VAR_0->buffer, VAR_0->buffer_size); av_free(VAR_0->buffer); VAR_0->buf_ptr = buffer + (VAR_0->buf_ptr - VAR_0->buffer); VAR_0->buf_end = buffer + (VAR_0->buf_end - VAR_0->buffer); VAR_0->buffer = buffer; VAR_0->buffer_size = VAR_1; return 0; }