static int expand_rle_row(SgiState *s, uint8_t *out_buf,

                          uint8_t *out_end, int pixelstride)

{

    unsigned char pixel, count;

    unsigned char *orig = out_buf;



    while (1) {

        if (bytestream2_get_bytes_left(&s->g) < 1)

            return AVERROR_INVALIDDATA;

        pixel = bytestream2_get_byteu(&s->g);

        if (!(count = (pixel & 0x7f))) {

            return (out_buf - orig) / pixelstride;

        }



        /* Check for buffer overflow. */

        if(out_buf + pixelstride * count >= out_end) return -1;



        if (pixel & 0x80) {

            while (count--) {

                *out_buf = bytestream2_get_byte(&s->g);

                out_buf += pixelstride;

            }

        } else {

            pixel = bytestream2_get_byte(&s->g);



            while (count--) {

                *out_buf = pixel;

                out_buf += pixelstride;

            }

        }

    }

}

static int expand_rle_row(SgiState *s, uint8_t *out_buf,

                          uint8_t *out_end, int pixelstride)

{

    unsigned char pixel, count;

    unsigned char *orig = out_buf;



    while (1) {

        if (bytestream2_get_bytes_left(&s->g) < 1)

            return AVERROR_INVALIDDATA;

        pixel = bytestream2_get_byteu(&s->g);

        if (!(count = (pixel & 0x7f))) {

            return (out_buf - orig) / pixelstride;

        }



        

        if(out_buf + pixelstride * count >= out_end) return -1;



        if (pixel & 0x80) {

            while (count--) {

                *out_buf = bytestream2_get_byte(&s->g);

                out_buf += pixelstride;

            }

        } else {

            pixel = bytestream2_get_byte(&s->g);



            while (count--) {

                *out_buf = pixel;

                out_buf += pixelstride;

            }

        }

    }

}

        if(out_buf + pixelstride * count >= out_end) return -1;
static int FUNC_0(SgiState *VAR_0, uint8_t *VAR_1,

                          uint8_t *VAR_2, int VAR_3)

{

    unsigned char VAR_4, VAR_5;

    unsigned char *VAR_6 = VAR_1;



    while (1) {

        if (bytestream2_get_bytes_left(&VAR_0->g) < 1)

            return AVERROR_INVALIDDATA;

        VAR_4 = bytestream2_get_byteu(&VAR_0->g);

        if (!(VAR_5 = (VAR_4 & 0x7f))) {

            return (VAR_1 - VAR_6) / VAR_3;

        }



        

        if(VAR_1 + VAR_3 * VAR_5 >= VAR_2) return -1;



        if (VAR_4 & 0x80) {

            while (VAR_5--) {

                *VAR_1 = bytestream2_get_byte(&VAR_0->g);

                VAR_1 += VAR_3;

            }

        } else {

            VAR_4 = bytestream2_get_byte(&VAR_0->g);



            while (VAR_5--) {

                *VAR_1 = VAR_4;

                VAR_1 += VAR_3;

            }

        }

    }

}

static int FUNC_0(SgiState *VAR_0, uint8_t *VAR_1,
uint8_t *VAR_2, int VAR_3)
{ unsigned char VAR_4, VAR_5; unsigned char *VAR_6 = VAR_1; while (1) { if (bytestream2_get_bytes_left(&VAR_0->g) < 1)
return AVERROR_INVALIDDATA; VAR_4 = bytestream2_get_byteu(&VAR_0->g); if (!(VAR_5 = (VAR_4 & 0x7f))) { return (VAR_1 - VAR_6) / VAR_3; } if(VAR_1 + VAR_3 * VAR_5 >= VAR_2) return -1; if (VAR_4 & 0x80) { while (VAR_5--) { *VAR_1 = bytestream2_get_byte(&VAR_0->g); VAR_1 += VAR_3; } } else { VAR_4 = bytestream2_get_byte(&VAR_0->g); while (VAR_5--) { *VAR_1 = VAR_4; VAR_1 += VAR_3; } } } }