static void xan_wc3_decode_frame(XanContext *s) {



    int width = s->avctx->width;

    int height = s->avctx->height;

    int total_pixels = width * height;

    unsigned char opcode;

    unsigned char flag = 0;

    int size = 0;

    int motion_x, motion_y;

    int x, y;



    unsigned char *opcode_buffer = s->buffer1;

    int opcode_buffer_size = s->buffer1_size;

    const unsigned char *imagedata_buffer = s->buffer2;



    /* pointers to segments inside the compressed chunk */

    const unsigned char *huffman_segment;

    const unsigned char *size_segment;

    const unsigned char *vector_segment;

    const unsigned char *imagedata_segment;



    huffman_segment =   s->buf + AV_RL16(&s->buf[0]);

    size_segment =      s->buf + AV_RL16(&s->buf[2]);

    vector_segment =    s->buf + AV_RL16(&s->buf[4]);

    imagedata_segment = s->buf + AV_RL16(&s->buf[6]);



    xan_huffman_decode(opcode_buffer, opcode_buffer_size,

                       huffman_segment, s->size - (huffman_segment - s->buf) );



    if (imagedata_segment[0] == 2)

        xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size);

    else

        imagedata_buffer = &imagedata_segment[1];



    /* use the decoded data segments to build the frame */

    x = y = 0;

    while (total_pixels) {



        opcode = *opcode_buffer++;

        size = 0;



        switch (opcode) {



        case 0:

            flag ^= 1;

            continue;



        case 1:

        case 2:

        case 3:

        case 4:

        case 5:

        case 6:

        case 7:

        case 8:

            size = opcode;

            break;



        case 12:

        case 13:

        case 14:

        case 15:

        case 16:

        case 17:

        case 18:

            size += (opcode - 10);

            break;



        case 9:

        case 19:

            size = *size_segment++;

            break;



        case 10:

        case 20:

            size = AV_RB16(&size_segment[0]);

            size_segment += 2;

            break;



        case 11:

        case 21:

            size = AV_RB24(size_segment);

            size_segment += 3;

            break;

        }



        if (opcode < 12) {

            flag ^= 1;

            if (flag) {

                /* run of (size) pixels is unchanged from last frame */

                xan_wc3_copy_pixel_run(s, x, y, size, 0, 0);

            } else {

                /* output a run of pixels from imagedata_buffer */

                xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size);

                imagedata_buffer += size;

            }

        } else {

            /* run-based motion compensation from last frame */

            motion_x = sign_extend(*vector_segment >> 4,  4);

            motion_y = sign_extend(*vector_segment & 0xF, 4);

            vector_segment++;



            /* copy a run of pixels from the previous frame */

            xan_wc3_copy_pixel_run(s, x, y, size, motion_x, motion_y);



            flag = 0;

        }



        /* coordinate accounting */

        total_pixels -= size;

        y += (x + size) / width;

        x  = (x + size) % width;

    }

}

static void xan_wc3_decode_frame(XanContext *s) {



    int width = s->avctx->width;

    int height = s->avctx->height;

    int total_pixels = width * height;

    unsigned char opcode;

    unsigned char flag = 0;

    int size = 0;

    int motion_x, motion_y;

    int x, y;



    unsigned char *opcode_buffer = s->buffer1;

    int opcode_buffer_size = s->buffer1_size;

    const unsigned char *imagedata_buffer = s->buffer2;



    

    const unsigned char *huffman_segment;

    const unsigned char *size_segment;

    const unsigned char *vector_segment;

    const unsigned char *imagedata_segment;



    huffman_segment =   s->buf + AV_RL16(&s->buf[0]);

    size_segment =      s->buf + AV_RL16(&s->buf[2]);

    vector_segment =    s->buf + AV_RL16(&s->buf[4]);

    imagedata_segment = s->buf + AV_RL16(&s->buf[6]);



    xan_huffman_decode(opcode_buffer, opcode_buffer_size,

                       huffman_segment, s->size - (huffman_segment - s->buf) );



    if (imagedata_segment[0] == 2)

        xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size);

    else

        imagedata_buffer = &imagedata_segment[1];



    

    x = y = 0;

    while (total_pixels) {



        opcode = *opcode_buffer++;

        size = 0;



        switch (opcode) {



        case 0:

            flag ^= 1;

            continue;



        case 1:

        case 2:

        case 3:

        case 4:

        case 5:

        case 6:

        case 7:

        case 8:

            size = opcode;

            break;



        case 12:

        case 13:

        case 14:

        case 15:

        case 16:

        case 17:

        case 18:

            size += (opcode - 10);

            break;



        case 9:

        case 19:

            size = *size_segment++;

            break;



        case 10:

        case 20:

            size = AV_RB16(&size_segment[0]);

            size_segment += 2;

            break;



        case 11:

        case 21:

            size = AV_RB24(size_segment);

            size_segment += 3;

            break;

        }



        if (opcode < 12) {

            flag ^= 1;

            if (flag) {

                

                xan_wc3_copy_pixel_run(s, x, y, size, 0, 0);

            } else {

                

                xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size);

                imagedata_buffer += size;

            }

        } else {

            

            motion_x = sign_extend(*vector_segment >> 4,  4);

            motion_y = sign_extend(*vector_segment & 0xF, 4);

            vector_segment++;



            

            xan_wc3_copy_pixel_run(s, x, y, size, motion_x, motion_y);



            flag = 0;

        }



        

        total_pixels -= size;

        y += (x + size) / width;

        x  = (x + size) % width;

    }

}

static void FUNC_0(XanContext *VAR_0) {



    int VAR_1 = VAR_0->avctx->VAR_1;

    int VAR_2 = VAR_0->avctx->VAR_2;

    int VAR_3 = VAR_1 * VAR_2;

    unsigned char VAR_4;

    unsigned char VAR_5 = 0;

    int VAR_6 = 0;

    int VAR_7, VAR_8;

    int VAR_9, VAR_10;



    unsigned char *VAR_11 = VAR_0->buffer1;

    int VAR_12 = VAR_0->buffer1_size;

    const unsigned char *VAR_13 = VAR_0->buffer2;



    

    const unsigned char *VAR_14;

    const unsigned char *VAR_15;

    const unsigned char *VAR_16;

    const unsigned char *VAR_17;



    VAR_14 =   VAR_0->buf + AV_RL16(&VAR_0->buf[0]);

    VAR_15 =      VAR_0->buf + AV_RL16(&VAR_0->buf[2]);

    VAR_16 =    VAR_0->buf + AV_RL16(&VAR_0->buf[4]);

    VAR_17 = VAR_0->buf + AV_RL16(&VAR_0->buf[6]);



    xan_huffman_decode(VAR_11, VAR_12,

                       VAR_14, VAR_0->VAR_6 - (VAR_14 - VAR_0->buf) );



    if (VAR_17[0] == 2)

        xan_unpack(VAR_0->buffer2, &VAR_17[1], VAR_0->buffer2_size);

    else

        VAR_13 = &VAR_17[1];



    

    VAR_9 = VAR_10 = 0;

    while (VAR_3) {



        VAR_4 = *VAR_11++;

        VAR_6 = 0;



        switch (VAR_4) {



        case 0:

            VAR_5 ^= 1;

            continue;



        case 1:

        case 2:

        case 3:

        case 4:

        case 5:

        case 6:

        case 7:

        case 8:

            VAR_6 = VAR_4;

            break;



        case 12:

        case 13:

        case 14:

        case 15:

        case 16:

        case 17:

        case 18:

            VAR_6 += (VAR_4 - 10);

            break;



        case 9:

        case 19:

            VAR_6 = *VAR_15++;

            break;



        case 10:

        case 20:

            VAR_6 = AV_RB16(&VAR_15[0]);

            VAR_15 += 2;

            break;



        case 11:

        case 21:

            VAR_6 = AV_RB24(VAR_15);

            VAR_15 += 3;

            break;

        }



        if (VAR_4 < 12) {

            VAR_5 ^= 1;

            if (VAR_5) {

                

                xan_wc3_copy_pixel_run(VAR_0, VAR_9, VAR_10, VAR_6, 0, 0);

            } else {

                

                xan_wc3_output_pixel_run(VAR_0, VAR_13, VAR_9, VAR_10, VAR_6);

                VAR_13 += VAR_6;

            }

        } else {

            

            VAR_7 = sign_extend(*VAR_16 >> 4,  4);

            VAR_8 = sign_extend(*VAR_16 & 0xF, 4);

            VAR_16++;



            

            xan_wc3_copy_pixel_run(VAR_0, VAR_9, VAR_10, VAR_6, VAR_7, VAR_8);



            VAR_5 = 0;

        }



        

        VAR_3 -= VAR_6;

        VAR_10 += (VAR_9 + VAR_6) / VAR_1;

        VAR_9  = (VAR_9 + VAR_6) % VAR_1;

    }

}

static void FUNC_0(XanContext *VAR_0) { int VAR_1 = VAR_0->avctx->VAR_1; int VAR_2 = VAR_0->avctx->VAR_2; int VAR_3 = VAR_1 * VAR_2; unsigned char VAR_4; unsigned char VAR_5 = 0; int VAR_6 = 0; int VAR_7, VAR_8; int VAR_9, VAR_10; unsigned char *VAR_11 = VAR_0->buffer1; int VAR_12 = VAR_0->buffer1_size; const unsigned char *VAR_13 = VAR_0->buffer2; const unsigned char *VAR_14; const unsigned char *VAR_15; const unsigned char *VAR_16; const unsigned char *VAR_17; VAR_14 =   VAR_0->buf + AV_RL16(&VAR_0->buf[0]); VAR_15 =      VAR_0->buf + AV_RL16(&VAR_0->buf[2]); VAR_16 =    VAR_0->buf + AV_RL16(&VAR_0->buf[4]); VAR_17 = VAR_0->buf + AV_RL16(&VAR_0->buf[6]); xan_huffman_decode(VAR_11, VAR_12,
VAR_14, VAR_0->VAR_6 - (VAR_14 - VAR_0->buf) ); if (VAR_17[0] == 2)
xan_unpack(VAR_0->buffer2, &VAR_17[1], VAR_0->buffer2_size); else
VAR_13 = &VAR_17[1]; VAR_9 = VAR_10 = 0; while (VAR_3) { VAR_4 = *VAR_11++; VAR_6 = 0; switch (VAR_4) { case 0:
VAR_5 ^= 1; continue; case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
VAR_6 = VAR_4; break; case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
VAR_6 += (VAR_4 - 10); break; case 9:
case 19:
VAR_6 = *VAR_15++; break; case 10:
case 20:
VAR_6 = AV_RB16(&VAR_15[0]); VAR_15 += 2; break; case 11:
case 21:
VAR_6 = AV_RB24(VAR_15); VAR_15 += 3; break; } if (VAR_4 < 12) { VAR_5 ^= 1; if (VAR_5) { xan_wc3_copy_pixel_run(VAR_0, VAR_9, VAR_10, VAR_6, 0, 0); } else { xan_wc3_output_pixel_run(VAR_0, VAR_13, VAR_9, VAR_10, VAR_6); VAR_13 += VAR_6; } } else { VAR_7 = sign_extend(*VAR_16 >> 4,  4); VAR_8 = sign_extend(*VAR_16 & 0xF, 4); VAR_16++; xan_wc3_copy_pixel_run(VAR_0, VAR_9, VAR_10, VAR_6, VAR_7, VAR_8); VAR_5 = 0; } VAR_3 -= VAR_6; VAR_10 += (VAR_9 + VAR_6) / VAR_1; VAR_9  = (VAR_9 + VAR_6) % VAR_1; } }