int ff_lzw_decode_init(LZWState *p, int csize, uint8_t *buf, int buf_size, int mode)

{

    struct LZWState *s = (struct LZWState *)p;



    if(csize < 1 || csize > LZW_MAXBITS)

        return -1;

    /* read buffer */

    s->eob_reached = 0;

    s->pbuf = buf;

    s->ebuf = s->pbuf + buf_size;

    s->bbuf = 0;

    s->bbits = 0;

    s->bs = 0;



    /* decoder */

    s->codesize = csize;

    s->cursize = s->codesize + 1;

    s->curmask = mask[s->cursize];

    s->top_slot = 1 << s->cursize;

    s->clear_code = 1 << s->codesize;

    s->end_code = s->clear_code + 1;

    s->slot = s->newcodes = s->clear_code + 2;

    s->oc = s->fc = 0;

    s->sp = s->stack;



    s->mode = mode;

    switch(s->mode){

    case FF_LZW_GIF:

        s->extra_slot= 0;

        break;

    case FF_LZW_TIFF:

        s->extra_slot= 1;

        break;

    default:

        return -1;

    }

    return 0;

}

int ff_lzw_decode_init(LZWState *p, int csize, uint8_t *buf, int buf_size, int mode)

{

    struct LZWState *s = (struct LZWState *)p;



    if(csize < 1 || csize > LZW_MAXBITS)

        return -1;

    

    s->eob_reached = 0;

    s->pbuf = buf;

    s->ebuf = s->pbuf + buf_size;

    s->bbuf = 0;

    s->bbits = 0;

    s->bs = 0;



    

    s->codesize = csize;

    s->cursize = s->codesize + 1;

    s->curmask = mask[s->cursize];

    s->top_slot = 1 << s->cursize;

    s->clear_code = 1 << s->codesize;

    s->end_code = s->clear_code + 1;

    s->slot = s->newcodes = s->clear_code + 2;

    s->oc = s->fc = 0;

    s->sp = s->stack;



    s->mode = mode;

    switch(s->mode){

    case FF_LZW_GIF:

        s->extra_slot= 0;

        break;

    case FF_LZW_TIFF:

        s->extra_slot= 1;

        break;

    default:

        return -1;

    }

    return 0;

}

    s->eob_reached = 0;
int FUNC_0(LZWState *VAR_0, int VAR_1, uint8_t *VAR_2, int VAR_3, int VAR_4)

{

    struct LZWState *VAR_5 = (struct LZWState *)VAR_0;



    if(VAR_1 < 1 || VAR_1 > LZW_MAXBITS)

        return -1;

    

    VAR_5->eob_reached = 0;

    VAR_5->pbuf = VAR_2;

    VAR_5->ebuf = VAR_5->pbuf + VAR_3;

    VAR_5->bbuf = 0;

    VAR_5->bbits = 0;

    VAR_5->bs = 0;



    

    VAR_5->codesize = VAR_1;

    VAR_5->cursize = VAR_5->codesize + 1;

    VAR_5->curmask = mask[VAR_5->cursize];

    VAR_5->top_slot = 1 << VAR_5->cursize;

    VAR_5->clear_code = 1 << VAR_5->codesize;

    VAR_5->end_code = VAR_5->clear_code + 1;

    VAR_5->slot = VAR_5->newcodes = VAR_5->clear_code + 2;

    VAR_5->oc = VAR_5->fc = 0;

    VAR_5->sp = VAR_5->stack;



    VAR_5->VAR_4 = VAR_4;

    switch(VAR_5->VAR_4){

    case FF_LZW_GIF:

        VAR_5->extra_slot= 0;

        break;

    case FF_LZW_TIFF:

        VAR_5->extra_slot= 1;

        break;

    default:

        return -1;

    }

    return 0;

}

int FUNC_0(LZWState *VAR_0, int VAR_1, uint8_t *VAR_2, int VAR_3, int VAR_4)
{ struct LZWState *VAR_5 = (struct LZWState *)VAR_0; if(VAR_1 < 1 || VAR_1 > LZW_MAXBITS)
return -1; VAR_5->eob_reached = 0; VAR_5->pbuf = VAR_2; VAR_5->ebuf = VAR_5->pbuf + VAR_3; VAR_5->bbuf = 0; VAR_5->bbits = 0; VAR_5->bs = 0; VAR_5->codesize = VAR_1; VAR_5->cursize = VAR_5->codesize + 1; VAR_5->curmask = mask[VAR_5->cursize]; VAR_5->top_slot = 1 << VAR_5->cursize; VAR_5->clear_code = 1 << VAR_5->codesize; VAR_5->end_code = VAR_5->clear_code + 1; VAR_5->slot = VAR_5->newcodes = VAR_5->clear_code + 2; VAR_5->oc = VAR_5->fc = 0; VAR_5->sp = VAR_5->stack; VAR_5->VAR_4 = VAR_4; switch(VAR_5->VAR_4){ case FF_LZW_GIF:
VAR_5->extra_slot= 0; break; case FF_LZW_TIFF:
VAR_5->extra_slot= 1; break; default:
return -1; } return 0; }