static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)

{

    PAFVideoDecContext *c = avctx->priv_data;

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0, a, b, p;

    const uint8_t *src, *send, *opcodes;

    int  i, j, x = 0;



    i = bytestream2_get_byte(&c->gb);

    if (i) {

        if (code & 0x10) {

            int align;



            align = bytestream2_tell(&c->gb) & 3;

            if (align)

                bytestream2_skip(&c->gb, 4 - align);

        }

        do {

            a      = bytestream2_get_byte(&c->gb);

            b      = bytestream2_get_byte(&c->gb);

            p      = (a & 0xC0) >> 6;

            dst    = c->frame[p] + get_video_page_offset(avctx, a, b);

            dend   = c->frame[p] + c->frame_size;

            offset = (b & 0x7F) * 2;

            j      = bytestream2_get_le16(&c->gb) + offset;



            do {

                offset++;

                if (dst + 3 * avctx->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                copy4h(avctx, dst);

                if ((offset & 0x3F) == 0)

                    dst += avctx->width * 3;

                dst += 4;

            } while (offset < j);

        } while (--i);

    }



    dst = c->frame[c->current_frame];

    do {

        a    = bytestream2_get_byte(&c->gb);

        b    = bytestream2_get_byte(&c->gb);

        p    = (a & 0xC0) >> 6;

        src  = c->frame[p] + get_video_page_offset(avctx, a, b);

        send = c->frame[p] + c->frame_size;

        if (src + 3 * avctx->width + 4 > send)

            return AVERROR_INVALIDDATA;

        copy_block4(dst, src, avctx->width, avctx->width, 4);

        i++;

        if ((i & 0x3F) == 0)

            dst += avctx->width * 3;

        dst += 4;

    } while (i < c->video_size / 16);



    opcode_size = bytestream2_get_le16(&c->gb);

    bytestream2_skip(&c->gb, 2);



    if (bytestream2_get_bytes_left(&c->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = pkt + bytestream2_tell(&c->gb);

    bytestream2_skipu(&c->gb, opcode_size);



    dst = c->frame[c->current_frame];



    for (i = 0; i < avctx->height; i += 4, dst += avctx->width * 3) {

        for (j = 0; j < avctx->width; j += 4, dst += 4) {

            int opcode, k = 0;



            if (x > opcode_size)

                return AVERROR_INVALIDDATA;

            if (j & 4) {

                opcode = opcodes[x] & 15;

                x++;

            } else {

                opcode = opcodes[x] >> 4;

            }



            while (block_sequences[opcode][k]) {



                offset = avctx->width * 2;

                code   = block_sequences[opcode][k++];



                switch (code) {

                case 2:

                    offset = 0;

                case 3:

                    color  = bytestream2_get_byte(&c->gb);

                case 4:

                    mask   = bytestream2_get_byte(&c->gb);

                    copy_color_mask(avctx, mask, dst + offset, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    a    = bytestream2_get_byte(&c->gb);

                    b    = bytestream2_get_byte(&c->gb);

                    p    = (a & 0xC0) >> 6;

                    src  = c->frame[p] + get_video_page_offset(avctx, a, b);

                    send = c->frame[p] + c->frame_size;

                case 7:

                    if (src + offset + avctx->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&c->gb);

                    copy_src_mask(avctx, mask, dst + offset, src + offset);

                    break;

                }

            }

        }

    }



    return 0;

}

static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)

{

    PAFVideoDecContext *c = avctx->priv_data;

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0, a, b, p;

    const uint8_t *src, *send, *opcodes;

    int  i, j, x = 0;



    i = bytestream2_get_byte(&c->gb);

    if (i) {

        if (code & 0x10) {

            int align;



            align = bytestream2_tell(&c->gb) & 3;

            if (align)

                bytestream2_skip(&c->gb, 4 - align);

        }

        do {

            a      = bytestream2_get_byte(&c->gb);

            b      = bytestream2_get_byte(&c->gb);

            p      = (a & 0xC0) >> 6;

            dst    = c->frame[p] + get_video_page_offset(avctx, a, b);

            dend   = c->frame[p] + c->frame_size;

            offset = (b & 0x7F) * 2;

            j      = bytestream2_get_le16(&c->gb) + offset;



            do {

                offset++;

                if (dst + 3 * avctx->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                copy4h(avctx, dst);

                if ((offset & 0x3F) == 0)

                    dst += avctx->width * 3;

                dst += 4;

            } while (offset < j);

        } while (--i);

    }



    dst = c->frame[c->current_frame];

    do {

        a    = bytestream2_get_byte(&c->gb);

        b    = bytestream2_get_byte(&c->gb);

        p    = (a & 0xC0) >> 6;

        src  = c->frame[p] + get_video_page_offset(avctx, a, b);

        send = c->frame[p] + c->frame_size;

        if (src + 3 * avctx->width + 4 > send)

            return AVERROR_INVALIDDATA;

        copy_block4(dst, src, avctx->width, avctx->width, 4);

        i++;

        if ((i & 0x3F) == 0)

            dst += avctx->width * 3;

        dst += 4;

    } while (i < c->video_size / 16);



    opcode_size = bytestream2_get_le16(&c->gb);

    bytestream2_skip(&c->gb, 2);



    if (bytestream2_get_bytes_left(&c->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = pkt + bytestream2_tell(&c->gb);

    bytestream2_skipu(&c->gb, opcode_size);



    dst = c->frame[c->current_frame];



    for (i = 0; i < avctx->height; i += 4, dst += avctx->width * 3) {

        for (j = 0; j < avctx->width; j += 4, dst += 4) {

            int opcode, k = 0;



            if (x > opcode_size)

                return AVERROR_INVALIDDATA;

            if (j & 4) {

                opcode = opcodes[x] & 15;

                x++;

            } else {

                opcode = opcodes[x] >> 4;

            }



            while (block_sequences[opcode][k]) {



                offset = avctx->width * 2;

                code   = block_sequences[opcode][k++];



                switch (code) {

                case 2:

                    offset = 0;

                case 3:

                    color  = bytestream2_get_byte(&c->gb);

                case 4:

                    mask   = bytestream2_get_byte(&c->gb);

                    copy_color_mask(avctx, mask, dst + offset, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    a    = bytestream2_get_byte(&c->gb);

                    b    = bytestream2_get_byte(&c->gb);

                    p    = (a & 0xC0) >> 6;

                    src  = c->frame[p] + get_video_page_offset(avctx, a, b);

                    send = c->frame[p] + c->frame_size;

                case 7:

                    if (src + offset + avctx->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&c->gb);

                    copy_src_mask(avctx, mask, dst + offset, src + offset);

                    break;

                }

            }

        }

    }



    return 0;

}

    dst = c->frame[c->current_frame];         if (src + 3 * avctx->width + 4 > send)
static int FUNC_0(AVCodecContext *VAR_0, uint8_t VAR_1, uint8_t *VAR_2)

{

    PAFVideoDecContext *c = VAR_0->priv_data;

    uint32_t opcode_size, offset;

    uint8_t *dst, *dend, mask = 0, color = 0, a, b, p;

    const uint8_t *VAR_3, *send, *opcodes;

    int  VAR_4, VAR_5, VAR_6 = 0;



    VAR_4 = bytestream2_get_byte(&c->gb);

    if (VAR_4) {

        if (VAR_1 & 0x10) {

            int VAR_7;



            VAR_7 = bytestream2_tell(&c->gb) & 3;

            if (VAR_7)

                bytestream2_skip(&c->gb, 4 - VAR_7);

        }

        do {

            a      = bytestream2_get_byte(&c->gb);

            b      = bytestream2_get_byte(&c->gb);

            p      = (a & 0xC0) >> 6;

            dst    = c->frame[p] + get_video_page_offset(VAR_0, a, b);

            dend   = c->frame[p] + c->frame_size;

            offset = (b & 0x7F) * 2;

            VAR_5      = bytestream2_get_le16(&c->gb) + offset;



            do {

                offset++;

                if (dst + 3 * VAR_0->width + 4 > dend)

                    return AVERROR_INVALIDDATA;

                copy4h(VAR_0, dst);

                if ((offset & 0x3F) == 0)

                    dst += VAR_0->width * 3;

                dst += 4;

            } while (offset < VAR_5);

        } while (--VAR_4);

    }



    dst = c->frame[c->current_frame];

    do {

        a    = bytestream2_get_byte(&c->gb);

        b    = bytestream2_get_byte(&c->gb);

        p    = (a & 0xC0) >> 6;

        VAR_3  = c->frame[p] + get_video_page_offset(VAR_0, a, b);

        send = c->frame[p] + c->frame_size;

        if (VAR_3 + 3 * VAR_0->width + 4 > send)

            return AVERROR_INVALIDDATA;

        copy_block4(dst, VAR_3, VAR_0->width, VAR_0->width, 4);

        VAR_4++;

        if ((VAR_4 & 0x3F) == 0)

            dst += VAR_0->width * 3;

        dst += 4;

    } while (VAR_4 < c->video_size / 16);



    opcode_size = bytestream2_get_le16(&c->gb);

    bytestream2_skip(&c->gb, 2);



    if (bytestream2_get_bytes_left(&c->gb) < opcode_size)

        return AVERROR_INVALIDDATA;



    opcodes = VAR_2 + bytestream2_tell(&c->gb);

    bytestream2_skipu(&c->gb, opcode_size);



    dst = c->frame[c->current_frame];



    for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4 += 4, dst += VAR_0->width * 3) {

        for (VAR_5 = 0; VAR_5 < VAR_0->width; VAR_5 += 4, dst += 4) {

            int opcode, k = 0;



            if (VAR_6 > opcode_size)

                return AVERROR_INVALIDDATA;

            if (VAR_5 & 4) {

                opcode = opcodes[VAR_6] & 15;

                VAR_6++;

            } else {

                opcode = opcodes[VAR_6] >> 4;

            }



            while (block_sequences[opcode][k]) {



                offset = VAR_0->width * 2;

                VAR_1   = block_sequences[opcode][k++];



                switch (VAR_1) {

                case 2:

                    offset = 0;

                case 3:

                    color  = bytestream2_get_byte(&c->gb);

                case 4:

                    mask   = bytestream2_get_byte(&c->gb);

                    copy_color_mask(VAR_0, mask, dst + offset, color);

                    break;

                case 5:

                    offset = 0;

                case 6:

                    a    = bytestream2_get_byte(&c->gb);

                    b    = bytestream2_get_byte(&c->gb);

                    p    = (a & 0xC0) >> 6;

                    VAR_3  = c->frame[p] + get_video_page_offset(VAR_0, a, b);

                    send = c->frame[p] + c->frame_size;

                case 7:

                    if (VAR_3 + offset + VAR_0->width + 4 > send)

                        return AVERROR_INVALIDDATA;

                    mask = bytestream2_get_byte(&c->gb);

                    copy_src_mask(VAR_0, mask, dst + offset, VAR_3 + offset);

                    break;

                }

            }

        }

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, uint8_t VAR_1, uint8_t *VAR_2)
{ PAFVideoDecContext *c = VAR_0->priv_data; uint32_t opcode_size, offset; uint8_t *dst, *dend, mask = 0, color = 0, a, b, p; const uint8_t *VAR_3, *send, *opcodes; int  VAR_4, VAR_5, VAR_6 = 0; VAR_4 = bytestream2_get_byte(&c->gb); if (VAR_4) { if (VAR_1 & 0x10) { int VAR_7; VAR_7 = bytestream2_tell(&c->gb) & 3; if (VAR_7)
bytestream2_skip(&c->gb, 4 - VAR_7); } do { a      = bytestream2_get_byte(&c->gb); b      = bytestream2_get_byte(&c->gb); p      = (a & 0xC0) >> 6; dst    = c->frame[p] + get_video_page_offset(VAR_0, a, b); dend   = c->frame[p] + c->frame_size; offset = (b & 0x7F) * 2; VAR_5      = bytestream2_get_le16(&c->gb) + offset; do { offset++; if (dst + 3 * VAR_0->width + 4 > dend)
return AVERROR_INVALIDDATA; copy4h(VAR_0, dst); if ((offset & 0x3F) == 0)
dst += VAR_0->width * 3; dst += 4; } while (offset < VAR_5); } while (--VAR_4); } dst = c->frame[c->current_frame]; do { a    = bytestream2_get_byte(&c->gb); b    = bytestream2_get_byte(&c->gb); p    = (a & 0xC0) >> 6; VAR_3  = c->frame[p] + get_video_page_offset(VAR_0, a, b); send = c->frame[p] + c->frame_size; if (VAR_3 + 3 * VAR_0->width + 4 > send)
return AVERROR_INVALIDDATA; copy_block4(dst, VAR_3, VAR_0->width, VAR_0->width, 4); VAR_4++; if ((VAR_4 & 0x3F) == 0)
dst += VAR_0->width * 3; dst += 4; } while (VAR_4 < c->video_size / 16); opcode_size = bytestream2_get_le16(&c->gb); bytestream2_skip(&c->gb, 2); if (bytestream2_get_bytes_left(&c->gb) < opcode_size)
return AVERROR_INVALIDDATA; opcodes = VAR_2 + bytestream2_tell(&c->gb); bytestream2_skipu(&c->gb, opcode_size); dst = c->frame[c->current_frame]; for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4 += 4, dst += VAR_0->width * 3) { for (VAR_5 = 0; VAR_5 < VAR_0->width; VAR_5 += 4, dst += 4) { int opcode, k = 0; if (VAR_6 > opcode_size)
return AVERROR_INVALIDDATA; if (VAR_5 & 4) { opcode = opcodes[VAR_6] & 15; VAR_6++; } else { opcode = opcodes[VAR_6] >> 4; } while (block_sequences[opcode][k]) { offset = VAR_0->width * 2; VAR_1   = block_sequences[opcode][k++]; switch (VAR_1) { case 2:
offset = 0; case 3:
color  = bytestream2_get_byte(&c->gb); case 4:
mask   = bytestream2_get_byte(&c->gb); copy_color_mask(VAR_0, mask, dst + offset, color); break; case 5:
offset = 0; case 6:
a    = bytestream2_get_byte(&c->gb); b    = bytestream2_get_byte(&c->gb); p    = (a & 0xC0) >> 6; VAR_3  = c->frame[p] + get_video_page_offset(VAR_0, a, b); send = c->frame[p] + c->frame_size; case 7:
if (VAR_3 + offset + VAR_0->width + 4 > send)
return AVERROR_INVALIDDATA; mask = bytestream2_get_byte(&c->gb); copy_src_mask(VAR_0, mask, dst + offset, VAR_3 + offset); break; } } } } return 0; }