static int gif_read_header1(GifState *s)

{

    uint8_t sig[6];

    int v, n;

    int background_color_index;



    if (bytestream2_get_bytes_left(&s->gb) < 13)

        return AVERROR_INVALIDDATA;



    /* read gif signature */

    bytestream2_get_bufferu(&s->gb, sig, 6);

    if (memcmp(sig, gif87a_sig, 6) != 0 &&

        memcmp(sig, gif89a_sig, 6) != 0)

        return AVERROR_INVALIDDATA;



    /* read screen header */

    s->transparent_color_index = -1;

    s->screen_width = bytestream2_get_le16u(&s->gb);

    s->screen_height = bytestream2_get_le16u(&s->gb);

    if(   (unsigned)s->screen_width  > 32767

       || (unsigned)s->screen_height > 32767){

        av_log(s->avctx, AV_LOG_ERROR, "picture size too large\n");

        return AVERROR_INVALIDDATA;

    }



    av_fast_malloc(&s->idx_line, &s->idx_line_size, s->screen_width);

    if (!s->idx_line)

        return AVERROR(ENOMEM);



    v = bytestream2_get_byteu(&s->gb);

    s->color_resolution = ((v & 0x70) >> 4) + 1;

    s->has_global_palette = (v & 0x80);

    s->bits_per_pixel = (v & 0x07) + 1;

    background_color_index = bytestream2_get_byteu(&s->gb);

    n = bytestream2_get_byteu(&s->gb);

    if (n) {

        s->avctx->sample_aspect_ratio.num = n + 15;

        s->avctx->sample_aspect_ratio.den = 64;

    }



    av_dlog(s->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",

           s->screen_width, s->screen_height, s->bits_per_pixel,

           s->has_global_palette);



    if (s->has_global_palette) {

        s->background_color_index = background_color_index;

        n = 1 << s->bits_per_pixel;

        if (bytestream2_get_bytes_left(&s->gb) < n * 3)

            return AVERROR_INVALIDDATA;



        gif_read_palette(s, s->global_palette, n);

        s->bg_color = s->global_palette[s->background_color_index];

    } else

        s->background_color_index = -1;



    return 0;

}

static int gif_read_header1(GifState *s)

{

    uint8_t sig[6];

    int v, n;

    int background_color_index;



    if (bytestream2_get_bytes_left(&s->gb) < 13)

        return AVERROR_INVALIDDATA;



    

    bytestream2_get_bufferu(&s->gb, sig, 6);

    if (memcmp(sig, gif87a_sig, 6) != 0 &&

        memcmp(sig, gif89a_sig, 6) != 0)

        return AVERROR_INVALIDDATA;



    

    s->transparent_color_index = -1;

    s->screen_width = bytestream2_get_le16u(&s->gb);

    s->screen_height = bytestream2_get_le16u(&s->gb);

    if(   (unsigned)s->screen_width  > 32767

       || (unsigned)s->screen_height > 32767){

        av_log(s->avctx, AV_LOG_ERROR, "picture size too large\n");

        return AVERROR_INVALIDDATA;

    }



    av_fast_malloc(&s->idx_line, &s->idx_line_size, s->screen_width);

    if (!s->idx_line)

        return AVERROR(ENOMEM);



    v = bytestream2_get_byteu(&s->gb);

    s->color_resolution = ((v & 0x70) >> 4) + 1;

    s->has_global_palette = (v & 0x80);

    s->bits_per_pixel = (v & 0x07) + 1;

    background_color_index = bytestream2_get_byteu(&s->gb);

    n = bytestream2_get_byteu(&s->gb);

    if (n) {

        s->avctx->sample_aspect_ratio.num = n + 15;

        s->avctx->sample_aspect_ratio.den = 64;

    }



    av_dlog(s->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",

           s->screen_width, s->screen_height, s->bits_per_pixel,

           s->has_global_palette);



    if (s->has_global_palette) {

        s->background_color_index = background_color_index;

        n = 1 << s->bits_per_pixel;

        if (bytestream2_get_bytes_left(&s->gb) < n * 3)

            return AVERROR_INVALIDDATA;



        gif_read_palette(s, s->global_palette, n);

        s->bg_color = s->global_palette[s->background_color_index];

    } else

        s->background_color_index = -1;



    return 0;

}

static int FUNC_0(GifState *VAR_0)

{

    uint8_t sig[6];

    int VAR_1, VAR_2;

    int VAR_3;



    if (bytestream2_get_bytes_left(&VAR_0->gb) < 13)

        return AVERROR_INVALIDDATA;



    

    bytestream2_get_bufferu(&VAR_0->gb, sig, 6);

    if (memcmp(sig, gif87a_sig, 6) != 0 &&

        memcmp(sig, gif89a_sig, 6) != 0)

        return AVERROR_INVALIDDATA;



    

    VAR_0->transparent_color_index = -1;

    VAR_0->screen_width = bytestream2_get_le16u(&VAR_0->gb);

    VAR_0->screen_height = bytestream2_get_le16u(&VAR_0->gb);

    if(   (unsigned)VAR_0->screen_width  > 32767

       || (unsigned)VAR_0->screen_height > 32767){

        av_log(VAR_0->avctx, AV_LOG_ERROR, "picture size too large\VAR_2");

        return AVERROR_INVALIDDATA;

    }



    av_fast_malloc(&VAR_0->idx_line, &VAR_0->idx_line_size, VAR_0->screen_width);

    if (!VAR_0->idx_line)

        return AVERROR(ENOMEM);



    VAR_1 = bytestream2_get_byteu(&VAR_0->gb);

    VAR_0->color_resolution = ((VAR_1 & 0x70) >> 4) + 1;

    VAR_0->has_global_palette = (VAR_1 & 0x80);

    VAR_0->bits_per_pixel = (VAR_1 & 0x07) + 1;

    VAR_3 = bytestream2_get_byteu(&VAR_0->gb);

    VAR_2 = bytestream2_get_byteu(&VAR_0->gb);

    if (VAR_2) {

        VAR_0->avctx->sample_aspect_ratio.num = VAR_2 + 15;

        VAR_0->avctx->sample_aspect_ratio.den = 64;

    }



    av_dlog(VAR_0->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\VAR_2",

           VAR_0->screen_width, VAR_0->screen_height, VAR_0->bits_per_pixel,

           VAR_0->has_global_palette);



    if (VAR_0->has_global_palette) {

        VAR_0->VAR_3 = VAR_3;

        VAR_2 = 1 << VAR_0->bits_per_pixel;

        if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_2 * 3)

            return AVERROR_INVALIDDATA;



        gif_read_palette(VAR_0, VAR_0->global_palette, VAR_2);

        VAR_0->bg_color = VAR_0->global_palette[VAR_0->VAR_3];

    } else

        VAR_0->VAR_3 = -1;



    return 0;

}

static int FUNC_0(GifState *VAR_0)
{ uint8_t sig[6]; int VAR_1, VAR_2; int VAR_3; if (bytestream2_get_bytes_left(&VAR_0->gb) < 13)
return AVERROR_INVALIDDATA; bytestream2_get_bufferu(&VAR_0->gb, sig, 6); if (memcmp(sig, gif87a_sig, 6) != 0 &&
memcmp(sig, gif89a_sig, 6) != 0)
return AVERROR_INVALIDDATA; VAR_0->transparent_color_index = -1; VAR_0->screen_width = bytestream2_get_le16u(&VAR_0->gb); VAR_0->screen_height = bytestream2_get_le16u(&VAR_0->gb); if(   (unsigned)VAR_0->screen_width  > 32767
|| (unsigned)VAR_0->screen_height > 32767){ av_log(VAR_0->avctx, AV_LOG_ERROR, "picture size too large\VAR_2"); return AVERROR_INVALIDDATA; } av_fast_malloc(&VAR_0->idx_line, &VAR_0->idx_line_size, VAR_0->screen_width); if (!VAR_0->idx_line)
return AVERROR(ENOMEM); VAR_1 = bytestream2_get_byteu(&VAR_0->gb); VAR_0->color_resolution = ((VAR_1 & 0x70) >> 4) + 1; VAR_0->has_global_palette = (VAR_1 & 0x80); VAR_0->bits_per_pixel = (VAR_1 & 0x07) + 1; VAR_3 = bytestream2_get_byteu(&VAR_0->gb); VAR_2 = bytestream2_get_byteu(&VAR_0->gb); if (VAR_2) { VAR_0->avctx->sample_aspect_ratio.num = VAR_2 + 15; VAR_0->avctx->sample_aspect_ratio.den = 64; } av_dlog(VAR_0->avctx, "screen_w=%d screen_h=%d bpp=%d global_palette=%d\VAR_2",
VAR_0->screen_width, VAR_0->screen_height, VAR_0->bits_per_pixel,
VAR_0->has_global_palette); if (VAR_0->has_global_palette) { VAR_0->VAR_3 = VAR_3; VAR_2 = 1 << VAR_0->bits_per_pixel; if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_2 * 3)
return AVERROR_INVALIDDATA; gif_read_palette(VAR_0, VAR_0->global_palette, VAR_2); VAR_0->bg_color = VAR_0->global_palette[VAR_0->VAR_3]; } else VAR_0->VAR_3 = -1; return 0; }