static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)

{

    DynBuffer *d = opaque;

    int new_size, new_allocated_size;



    /* reallocate buffer if needed */

    new_size = d->pos + buf_size;

    new_allocated_size = d->allocated_size;

    if(new_size < d->pos || new_size > INT_MAX/2)

        return -1;

    while (new_size > new_allocated_size) {

        if (!new_allocated_size)

            new_allocated_size = new_size;

        else

            new_allocated_size += new_allocated_size / 2 + 1;

    }



    if (new_allocated_size > d->allocated_size) {

        d->buffer = av_realloc(d->buffer, new_allocated_size);

        if(d->buffer == NULL)

             return -1234;

        d->allocated_size = new_allocated_size;

    }

    memcpy(d->buffer + d->pos, buf, buf_size);

    d->pos = new_size;

    if (d->pos > d->size)

        d->size = d->pos;

    return buf_size;

}

static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)

{

    DynBuffer *d = opaque;

    int new_size, new_allocated_size;



    

    new_size = d->pos + buf_size;

    new_allocated_size = d->allocated_size;

    if(new_size < d->pos || new_size > INT_MAX/2)

        return -1;

    while (new_size > new_allocated_size) {

        if (!new_allocated_size)

            new_allocated_size = new_size;

        else

            new_allocated_size += new_allocated_size / 2 + 1;

    }



    if (new_allocated_size > d->allocated_size) {

        d->buffer = av_realloc(d->buffer, new_allocated_size);

        if(d->buffer == NULL)

             return -1234;

        d->allocated_size = new_allocated_size;

    }

    memcpy(d->buffer + d->pos, buf, buf_size);

    d->pos = new_size;

    if (d->pos > d->size)

        d->size = d->pos;

    return buf_size;

}

    int new_size, new_allocated_size;
static int FUNC_0(void *VAR_0, uint8_t *VAR_1, int VAR_2)

{

    DynBuffer *d = VAR_0;

    int VAR_3, VAR_4;



    

    VAR_3 = d->pos + VAR_2;

    VAR_4 = d->allocated_size;

    if(VAR_3 < d->pos || VAR_3 > INT_MAX/2)

        return -1;

    while (VAR_3 > VAR_4) {

        if (!VAR_4)

            VAR_4 = VAR_3;

        else

            VAR_4 += VAR_4 / 2 + 1;

    }



    if (VAR_4 > d->allocated_size) {

        d->buffer = av_realloc(d->buffer, VAR_4);

        if(d->buffer == NULL)

             return -1234;

        d->allocated_size = VAR_4;

    }

    memcpy(d->buffer + d->pos, VAR_1, VAR_2);

    d->pos = VAR_3;

    if (d->pos > d->size)

        d->size = d->pos;

    return VAR_2;

}

static int FUNC_0(void *VAR_0, uint8_t *VAR_1, int VAR_2)
{ DynBuffer *d = VAR_0; int VAR_3, VAR_4; VAR_3 = d->pos + VAR_2; VAR_4 = d->allocated_size; if(VAR_3 < d->pos || VAR_3 > INT_MAX/2)
return -1; while (VAR_3 > VAR_4) { if (!VAR_4)
VAR_4 = VAR_3; else
VAR_4 += VAR_4 / 2 + 1; } if (VAR_4 > d->allocated_size) { d->buffer = av_realloc(d->buffer, VAR_4); if(d->buffer == NULL)
return -1234; d->allocated_size = VAR_4; } memcpy(d->buffer + d->pos, VAR_1, VAR_2); d->pos = VAR_3; if (d->pos > d->size)
d->size = d->pos; return VAR_2; }