static int decode_cell_data(Cell *cell, uint8_t *block, uint8_t *ref_block,
                            int pitch, int h_zoom, int v_zoom, int mode,
                            const vqEntry *delta[2], int swap_quads[2],
                            const uint8_t **data_ptr, const uint8_t *last_ptr)
{
    int           x, y, line, num_lines;
    int           rle_blocks = 0;
    uint8_t       code, *dst, *ref;
    const vqEntry *delta_tab;
    unsigned int  dyad1, dyad2;
    uint64_t      pix64;
    int           skip_flag = 0, is_top_of_cell, is_first_row = 1;
    int           row_offset, blk_row_offset, line_offset;
    row_offset     =  pitch;
    blk_row_offset = (row_offset << (2 + v_zoom)) - (cell->width << 2);
    line_offset    = v_zoom ? row_offset : 0;
    for (y = 0; y < cell->height; is_first_row = 0, y += 1 + v_zoom) {
        for (x = 0; x < cell->width; x += 1 + h_zoom) {
            ref = ref_block;
            dst = block;
            if (rle_blocks > 0) {
                if (mode <= 4) {
                    RLE_BLOCK_COPY;
                } else if (mode == 10 && !cell->mv_ptr) {
                    RLE_BLOCK_COPY_8;
                }
                rle_blocks--;
            } else {
                for (line = 0; line < 4;) {
                    num_lines = 1;
                    is_top_of_cell = is_first_row && !line;
                    /* select primary VQ table for odd, secondary for even lines */
                    if (mode <= 4)
                        delta_tab = delta[line & 1];
                    else
                        delta_tab = delta[1];
                    BUFFER_PRECHECK;
                    code = bytestream_get_byte(data_ptr);
                    if (code < 248) {
                        if (code < delta_tab->num_dyads) {
                            BUFFER_PRECHECK;
                            dyad1 = bytestream_get_byte(data_ptr);
                            dyad2 = code;
                            if (dyad1 >= delta_tab->num_dyads || dyad1 >= 248)
                        } else {
                            /* process QUADS */
                            code -= delta_tab->num_dyads;
                            dyad1 = code / delta_tab->quad_exp;
                            dyad2 = code % delta_tab->quad_exp;
                            if (swap_quads[line & 1])
                                FFSWAP(unsigned int, dyad1, dyad2);
                        }
                        if (mode <= 4) {
                            APPLY_DELTA_4;
                        } else if (mode == 10 && !cell->mv_ptr) {
                            APPLY_DELTA_8;
                        } else {
                            APPLY_DELTA_1011_INTER;
                        }
                    } else {
                        /* process RLE codes */
                        switch (code) {
                        case RLE_ESC_FC:
                            skip_flag  = 0;
                            rle_blocks = 1;
                            code       = 253;
                            /* FALLTHROUGH */
                        case RLE_ESC_FF:
                        case RLE_ESC_FE:
                        case RLE_ESC_FD:
                            num_lines = 257 - code - line;
                            if (num_lines <= 0)
                                return IV3_BAD_RLE;
                            if (mode <= 4) {
                                RLE_LINES_COPY;
                            } else if (mode == 10 && !cell->mv_ptr) {
                                RLE_LINES_COPY_M10;
                            }
                            break;
                        case RLE_ESC_FB:
                            BUFFER_PRECHECK;
                            code = bytestream_get_byte(data_ptr);
                            rle_blocks = (code & 0x1F) - 1; /* set block counter */
                            if (code >= 64 || rle_blocks < 0)
                                return IV3_BAD_COUNTER;
                            skip_flag = code & 0x20;
                            num_lines = 4 - line; /* enforce next block processing */
                            if (mode >= 10 || (cell->mv_ptr || !skip_flag)) {
                                if (mode <= 4) {
                                    RLE_LINES_COPY;
                                } else if (mode == 10 && !cell->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        case RLE_ESC_F9:
                            skip_flag  = 1;
                            rle_blocks = 1;
                            /* FALLTHROUGH */
                        case RLE_ESC_FA:
                            if (line)
                                return IV3_BAD_RLE;
                            num_lines = 4; /* enforce next block processing */
                            if (cell->mv_ptr) {
                                if (mode <= 4) {
                                    RLE_LINES_COPY;
                                } else if (mode == 10 && !cell->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        default:
                            return IV3_UNSUPPORTED;
                        }
                    }
                    line += num_lines;
                    ref  += row_offset * (num_lines << v_zoom);
                    dst  += row_offset * (num_lines << v_zoom);
                }
            }
            /* move to next horizontal block */
            block     += 4 << h_zoom;
            ref_block += 4 << h_zoom;
        }
        /* move to next line of blocks */
        ref_block += blk_row_offset;
        block     += blk_row_offset;
    }
    return IV3_NOERR;
}
static int decode_cell_data(Cell *cell, uint8_t *block, uint8_t *ref_block,
                            int pitch, int h_zoom, int v_zoom, int mode,
                            const vqEntry *delta[2], int swap_quads[2],
                            const uint8_t **data_ptr, const uint8_t *last_ptr)
{
    int           x, y, line, num_lines;
    int           rle_blocks = 0;
    uint8_t       code, *dst, *ref;
    const vqEntry *delta_tab;
    unsigned int  dyad1, dyad2;
    uint64_t      pix64;
    int           skip_flag = 0, is_top_of_cell, is_first_row = 1;
    int           row_offset, blk_row_offset, line_offset;
    row_offset     =  pitch;
    blk_row_offset = (row_offset << (2 + v_zoom)) - (cell->width << 2);
    line_offset    = v_zoom ? row_offset : 0;
    for (y = 0; y < cell->height; is_first_row = 0, y += 1 + v_zoom) {
        for (x = 0; x < cell->width; x += 1 + h_zoom) {
            ref = ref_block;
            dst = block;
            if (rle_blocks > 0) {
                if (mode <= 4) {
                    RLE_BLOCK_COPY;
                } else if (mode == 10 && !cell->mv_ptr) {
                    RLE_BLOCK_COPY_8;
                }
                rle_blocks--;
            } else {
                for (line = 0; line < 4;) {
                    num_lines = 1;
                    is_top_of_cell = is_first_row && !line;
                    
                    if (mode <= 4)
                        delta_tab = delta[line & 1];
                    else
                        delta_tab = delta[1];
                    BUFFER_PRECHECK;
                    code = bytestream_get_byte(data_ptr);
                    if (code < 248) {
                        if (code < delta_tab->num_dyads) {
                            BUFFER_PRECHECK;
                            dyad1 = bytestream_get_byte(data_ptr);
                            dyad2 = code;
                            if (dyad1 >= delta_tab->num_dyads || dyad1 >= 248)
                        } else {
                            
                            code -= delta_tab->num_dyads;
                            dyad1 = code / delta_tab->quad_exp;
                            dyad2 = code % delta_tab->quad_exp;
                            if (swap_quads[line & 1])
                                FFSWAP(unsigned int, dyad1, dyad2);
                        }
                        if (mode <= 4) {
                            APPLY_DELTA_4;
                        } else if (mode == 10 && !cell->mv_ptr) {
                            APPLY_DELTA_8;
                        } else {
                            APPLY_DELTA_1011_INTER;
                        }
                    } else {
                        
                        switch (code) {
                        case RLE_ESC_FC:
                            skip_flag  = 0;
                            rle_blocks = 1;
                            code       = 253;
                            
                        case RLE_ESC_FF:
                        case RLE_ESC_FE:
                        case RLE_ESC_FD:
                            num_lines = 257 - code - line;
                            if (num_lines <= 0)
                                return IV3_BAD_RLE;
                            if (mode <= 4) {
                                RLE_LINES_COPY;
                            } else if (mode == 10 && !cell->mv_ptr) {
                                RLE_LINES_COPY_M10;
                            }
                            break;
                        case RLE_ESC_FB:
                            BUFFER_PRECHECK;
                            code = bytestream_get_byte(data_ptr);
                            rle_blocks = (code & 0x1F) - 1; 
                            if (code >= 64 || rle_blocks < 0)
                                return IV3_BAD_COUNTER;
                            skip_flag = code & 0x20;
                            num_lines = 4 - line; 
                            if (mode >= 10 || (cell->mv_ptr || !skip_flag)) {
                                if (mode <= 4) {
                                    RLE_LINES_COPY;
                                } else if (mode == 10 && !cell->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        case RLE_ESC_F9:
                            skip_flag  = 1;
                            rle_blocks = 1;
                            
                        case RLE_ESC_FA:
                            if (line)
                                return IV3_BAD_RLE;
                            num_lines = 4; 
                            if (cell->mv_ptr) {
                                if (mode <= 4) {
                                    RLE_LINES_COPY;
                                } else if (mode == 10 && !cell->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        default:
                            return IV3_UNSUPPORTED;
                        }
                    }
                    line += num_lines;
                    ref  += row_offset * (num_lines << v_zoom);
                    dst  += row_offset * (num_lines << v_zoom);
                }
            }
            
            block     += 4 << h_zoom;
            ref_block += 4 << h_zoom;
        }
        
        ref_block += blk_row_offset;
        block     += blk_row_offset;
    }
    return IV3_NOERR;
}
static int FUNC_0(Cell *VAR_0, uint8_t *VAR_1, uint8_t *VAR_2,
                            int VAR_3, int VAR_4, int VAR_5, int VAR_6,
                            const vqEntry *VAR_7[2], int VAR_8[2],
                            const uint8_t **VAR_9, const uint8_t *VAR_10)
{
    int           VAR_11, VAR_12, VAR_13, VAR_14;
    int           VAR_15 = 0;
    uint8_t       code, *dst, *ref;
    const vqEntry *VAR_16;
    unsigned int  VAR_17, VAR_18;
    uint64_t      pix64;
    int           VAR_19 = 0, VAR_20, VAR_21 = 1;
    int           VAR_22, VAR_23, VAR_24;
    VAR_22     =  VAR_3;
    VAR_23 = (VAR_22 << (2 + VAR_5)) - (VAR_0->width << 2);
    VAR_24    = VAR_5 ? VAR_22 : 0;
    for (VAR_12 = 0; VAR_12 < VAR_0->height; VAR_21 = 0, VAR_12 += 1 + VAR_5) {
        for (VAR_11 = 0; VAR_11 < VAR_0->width; VAR_11 += 1 + VAR_4) {
            ref = VAR_2;
            dst = VAR_1;
            if (VAR_15 > 0) {
                if (VAR_6 <= 4) {
                    RLE_BLOCK_COPY;
                } else if (VAR_6 == 10 && !VAR_0->mv_ptr) {
                    RLE_BLOCK_COPY_8;
                }
                VAR_15--;
            } else {
                for (VAR_13 = 0; VAR_13 < 4;) {
                    VAR_14 = 1;
                    VAR_20 = VAR_21 && !VAR_13;
                    
                    if (VAR_6 <= 4)
                        VAR_16 = VAR_7[VAR_13 & 1];
                    else
                        VAR_16 = VAR_7[1];
                    BUFFER_PRECHECK;
                    code = bytestream_get_byte(VAR_9);
                    if (code < 248) {
                        if (code < VAR_16->num_dyads) {
                            BUFFER_PRECHECK;
                            VAR_17 = bytestream_get_byte(VAR_9);
                            VAR_18 = code;
                            if (VAR_17 >= VAR_16->num_dyads || VAR_17 >= 248)
                        } else {
                            
                            code -= VAR_16->num_dyads;
                            VAR_17 = code / VAR_16->quad_exp;
                            VAR_18 = code % VAR_16->quad_exp;
                            if (VAR_8[VAR_13 & 1])
                                FFSWAP(unsigned int, VAR_17, VAR_18);
                        }
                        if (VAR_6 <= 4) {
                            APPLY_DELTA_4;
                        } else if (VAR_6 == 10 && !VAR_0->mv_ptr) {
                            APPLY_DELTA_8;
                        } else {
                            APPLY_DELTA_1011_INTER;
                        }
                    } else {
                        
                        switch (code) {
                        case RLE_ESC_FC:
                            VAR_19  = 0;
                            VAR_15 = 1;
                            code       = 253;
                            
                        case RLE_ESC_FF:
                        case RLE_ESC_FE:
                        case RLE_ESC_FD:
                            VAR_14 = 257 - code - VAR_13;
                            if (VAR_14 <= 0)
                                return IV3_BAD_RLE;
                            if (VAR_6 <= 4) {
                                RLE_LINES_COPY;
                            } else if (VAR_6 == 10 && !VAR_0->mv_ptr) {
                                RLE_LINES_COPY_M10;
                            }
                            break;
                        case RLE_ESC_FB:
                            BUFFER_PRECHECK;
                            code = bytestream_get_byte(VAR_9);
                            VAR_15 = (code & 0x1F) - 1; 
                            if (code >= 64 || VAR_15 < 0)
                                return IV3_BAD_COUNTER;
                            VAR_19 = code & 0x20;
                            VAR_14 = 4 - VAR_13; 
                            if (VAR_6 >= 10 || (VAR_0->mv_ptr || !VAR_19)) {
                                if (VAR_6 <= 4) {
                                    RLE_LINES_COPY;
                                } else if (VAR_6 == 10 && !VAR_0->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        case RLE_ESC_F9:
                            VAR_19  = 1;
                            VAR_15 = 1;
                            
                        case RLE_ESC_FA:
                            if (VAR_13)
                                return IV3_BAD_RLE;
                            VAR_14 = 4; 
                            if (VAR_0->mv_ptr) {
                                if (VAR_6 <= 4) {
                                    RLE_LINES_COPY;
                                } else if (VAR_6 == 10 && !VAR_0->mv_ptr) {
                                    RLE_LINES_COPY_M10;
                                }
                            }
                            break;
                        default:
                            return IV3_UNSUPPORTED;
                        }
                    }
                    VAR_13 += VAR_14;
                    ref  += VAR_22 * (VAR_14 << VAR_5);
                    dst  += VAR_22 * (VAR_14 << VAR_5);
                }
            }
            
            VAR_1     += 4 << VAR_4;
            VAR_2 += 4 << VAR_4;
        }
        
        VAR_2 += VAR_23;
        VAR_1     += VAR_23;
    }
    return IV3_NOERR;
}
static int FUNC_0(Cell *VAR_0, uint8_t *VAR_1, uint8_t *VAR_2,
int VAR_3, int VAR_4, int VAR_5, int VAR_6,
const vqEntry *VAR_7[2], int VAR_8[2],
const uint8_t **VAR_9, const uint8_t *VAR_10)
{ int           VAR_11, VAR_12, VAR_13, VAR_14; int           VAR_15 = 0; uint8_t       code, *dst, *ref; const vqEntry *VAR_16; unsigned int  VAR_17, VAR_18; uint64_t      pix64; int           VAR_19 = 0, VAR_20, VAR_21 = 1; int           VAR_22, VAR_23, VAR_24; VAR_22     =  VAR_3; VAR_23 = (VAR_22 << (2 + VAR_5)) - (VAR_0->width << 2); VAR_24    = VAR_5 ? VAR_22 : 0; for (VAR_12 = 0; VAR_12 < VAR_0->height; VAR_21 = 0, VAR_12 += 1 + VAR_5) { for (VAR_11 = 0; VAR_11 < VAR_0->width; VAR_11 += 1 + VAR_4) { ref = VAR_2; dst = VAR_1; if (VAR_15 > 0) { if (VAR_6 <= 4) { RLE_BLOCK_COPY; } else if (VAR_6 == 10 && !VAR_0->mv_ptr) { RLE_BLOCK_COPY_8; } VAR_15--; } else { for (VAR_13 = 0; VAR_13 < 4;) { VAR_14 = 1; VAR_20 = VAR_21 && !VAR_13; if (VAR_6 <= 4)
VAR_16 = VAR_7[VAR_13 & 1]; else
VAR_16 = VAR_7[1]; BUFFER_PRECHECK; code = bytestream_get_byte(VAR_9); if (code < 248) { if (code < VAR_16->num_dyads) { BUFFER_PRECHECK; VAR_17 = bytestream_get_byte(VAR_9); VAR_18 = code; if (VAR_17 >= VAR_16->num_dyads || VAR_17 >= 248)
} else { code -= VAR_16->num_dyads; VAR_17 = code / VAR_16->quad_exp; VAR_18 = code % VAR_16->quad_exp; if (VAR_8[VAR_13 & 1])
FFSWAP(unsigned int, VAR_17, VAR_18); } if (VAR_6 <= 4) { APPLY_DELTA_4; } else if (VAR_6 == 10 && !VAR_0->mv_ptr) { APPLY_DELTA_8; } else { APPLY_DELTA_1011_INTER; } } else { switch (code) { case RLE_ESC_FC:
VAR_19  = 0; VAR_15 = 1; code       = 253; case RLE_ESC_FF:
case RLE_ESC_FE:
case RLE_ESC_FD:
VAR_14 = 257 - code - VAR_13; if (VAR_14 <= 0)
return IV3_BAD_RLE; if (VAR_6 <= 4) { RLE_LINES_COPY; } else if (VAR_6 == 10 && !VAR_0->mv_ptr) { RLE_LINES_COPY_M10; } break; case RLE_ESC_FB:
BUFFER_PRECHECK; code = bytestream_get_byte(VAR_9); VAR_15 = (code & 0x1F) - 1; if (code >= 64 || VAR_15 < 0)
return IV3_BAD_COUNTER; VAR_19 = code & 0x20; VAR_14 = 4 - VAR_13; if (VAR_6 >= 10 || (VAR_0->mv_ptr || !VAR_19)) { if (VAR_6 <= 4) { RLE_LINES_COPY; } else if (VAR_6 == 10 && !VAR_0->mv_ptr) { RLE_LINES_COPY_M10; } } break; case RLE_ESC_F9:
VAR_19  = 1; VAR_15 = 1; case RLE_ESC_FA:
if (VAR_13)
return IV3_BAD_RLE; VAR_14 = 4; if (VAR_0->mv_ptr) { if (VAR_6 <= 4) { RLE_LINES_COPY; } else if (VAR_6 == 10 && !VAR_0->mv_ptr) { RLE_LINES_COPY_M10; } } break; default:
return IV3_UNSUPPORTED; } } VAR_13 += VAR_14; ref  += VAR_22 * (VAR_14 << VAR_5); dst  += VAR_22 * (VAR_14 << VAR_5); } } VAR_1     += 4 << VAR_4; VAR_2 += 4 << VAR_4; } VAR_2 += VAR_23; VAR_1     += VAR_23; } return IV3_NOERR; }