static int write_header(FlashSV2Context * s, uint8_t * buf, int buf_size)

{

    PutBitContext pb;

    int buf_pos, len;



    if (buf_size < 5)

        return -1;



    init_put_bits(&pb, buf, buf_size * 8);



    put_bits(&pb, 4, (s->block_width  >> 4) - 1);

    put_bits(&pb, 12, s->image_width);

    put_bits(&pb, 4, (s->block_height >> 4) - 1);

    put_bits(&pb, 12, s->image_height);



    flush_put_bits(&pb);

    buf_pos = 4;



    buf[buf_pos++] = s->flags;



    if (s->flags & HAS_PALLET_INFO) {

        len = write_palette(s, buf + buf_pos, buf_size - buf_pos);

        if (len < 0)

            return -1;

        buf_pos += len;

    }



    return buf_pos;

}

static int write_header(FlashSV2Context * s, uint8_t * buf, int buf_size)

{

    PutBitContext pb;

    int buf_pos, len;



    if (buf_size < 5)

        return -1;



    init_put_bits(&pb, buf, buf_size * 8);



    put_bits(&pb, 4, (s->block_width  >> 4) - 1);

    put_bits(&pb, 12, s->image_width);

    put_bits(&pb, 4, (s->block_height >> 4) - 1);

    put_bits(&pb, 12, s->image_height);



    flush_put_bits(&pb);

    buf_pos = 4;



    buf[buf_pos++] = s->flags;



    if (s->flags & HAS_PALLET_INFO) {

        len = write_palette(s, buf + buf_pos, buf_size - buf_pos);

        if (len < 0)

            return -1;

        buf_pos += len;

    }



    return buf_pos;

}

    init_put_bits(&pb, buf, buf_size * 8);     init_put_bits(&pb, buf, buf_size * 8);
static int FUNC_0(FlashSV2Context * VAR_0, uint8_t * VAR_1, int VAR_2)

{

    PutBitContext pb;

    int VAR_3, VAR_4;



    if (VAR_2 < 5)

        return -1;



    init_put_bits(&pb, VAR_1, VAR_2 * 8);



    put_bits(&pb, 4, (VAR_0->block_width  >> 4) - 1);

    put_bits(&pb, 12, VAR_0->image_width);

    put_bits(&pb, 4, (VAR_0->block_height >> 4) - 1);

    put_bits(&pb, 12, VAR_0->image_height);



    flush_put_bits(&pb);

    VAR_3 = 4;



    VAR_1[VAR_3++] = VAR_0->flags;



    if (VAR_0->flags & HAS_PALLET_INFO) {

        VAR_4 = write_palette(VAR_0, VAR_1 + VAR_3, VAR_2 - VAR_3);

        if (VAR_4 < 0)

            return -1;

        VAR_3 += VAR_4;

    }



    return VAR_3;

}

static int FUNC_0(FlashSV2Context * VAR_0, uint8_t * VAR_1, int VAR_2)
{ PutBitContext pb; int VAR_3, VAR_4; if (VAR_2 < 5)
return -1; init_put_bits(&pb, VAR_1, VAR_2 * 8); put_bits(&pb, 4, (VAR_0->block_width  >> 4) - 1); put_bits(&pb, 12, VAR_0->image_width); put_bits(&pb, 4, (VAR_0->block_height >> 4) - 1); put_bits(&pb, 12, VAR_0->image_height); flush_put_bits(&pb); VAR_3 = 4; VAR_1[VAR_3++] = VAR_0->flags; if (VAR_0->flags & HAS_PALLET_INFO) { VAR_4 = write_palette(VAR_0, VAR_1 + VAR_3, VAR_2 - VAR_3); if (VAR_4 < 0)
return -1; VAR_3 += VAR_4; } return VAR_3; }