static int decode_codestream(J2kDecoderContext *s)

{

    J2kCodingStyle *codsty = s->codsty;

    J2kQuantStyle  *qntsty = s->qntsty;

    uint8_t *properties = s->properties;



    for (;;){

        int marker, len, ret = 0;

        const uint8_t *oldbuf;

        if (s->buf_end - s->buf < 2){

            av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n");

            break;

        }



        marker = bytestream_get_be16(&s->buf);

        if(s->avctx->debug & FF_DEBUG_STARTCODE)

            av_log(s->avctx, AV_LOG_DEBUG, "marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);

        oldbuf = s->buf;



        if (marker == J2K_SOD){

            J2kTile *tile = s->tile + s->curtileno;

            if (ret = init_tile(s, s->curtileno))

                return ret;

            if (ret = decode_packets(s, tile))

                return ret;

            continue;

        }

        if (marker == J2K_EOC)

            break;



        if (s->buf_end - s->buf < 2)

            return AVERROR(EINVAL);

        len = bytestream_get_be16(&s->buf);

        switch(marker){

            case J2K_SIZ:

                ret = get_siz(s); break;

            case J2K_COC:

                ret = get_coc(s, codsty, properties); break;

            case J2K_COD:

                ret = get_cod(s, codsty, properties); break;

            case J2K_QCC:

                ret = get_qcc(s, len, qntsty, properties); break;

            case J2K_QCD:

                ret = get_qcd(s, len, qntsty, properties); break;

            case J2K_SOT:

                if (!(ret = get_sot(s))){

                    codsty = s->tile[s->curtileno].codsty;

                    qntsty = s->tile[s->curtileno].qntsty;

                    properties = s->tile[s->curtileno].properties;

                }

                break;

            case J2K_COM:

                // the comment is ignored

                s->buf += len - 2; break;

            default:

                av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);

                s->buf += len - 2; break;

        }

        if (s->buf - oldbuf != len || ret){

            av_log(s->avctx, AV_LOG_ERROR, "error during processing marker segment %.4x\n", marker);

            return ret ? ret : -1;

        }

    }

    return 0;

}

static int decode_codestream(J2kDecoderContext *s)

{

    J2kCodingStyle *codsty = s->codsty;

    J2kQuantStyle  *qntsty = s->qntsty;

    uint8_t *properties = s->properties;



    for (;;){

        int marker, len, ret = 0;

        const uint8_t *oldbuf;

        if (s->buf_end - s->buf < 2){

            av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n");

            break;

        }



        marker = bytestream_get_be16(&s->buf);

        if(s->avctx->debug & FF_DEBUG_STARTCODE)

            av_log(s->avctx, AV_LOG_DEBUG, "marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);

        oldbuf = s->buf;



        if (marker == J2K_SOD){

            J2kTile *tile = s->tile + s->curtileno;

            if (ret = init_tile(s, s->curtileno))

                return ret;

            if (ret = decode_packets(s, tile))

                return ret;

            continue;

        }

        if (marker == J2K_EOC)

            break;



        if (s->buf_end - s->buf < 2)

            return AVERROR(EINVAL);

        len = bytestream_get_be16(&s->buf);

        switch(marker){

            case J2K_SIZ:

                ret = get_siz(s); break;

            case J2K_COC:

                ret = get_coc(s, codsty, properties); break;

            case J2K_COD:

                ret = get_cod(s, codsty, properties); break;

            case J2K_QCC:

                ret = get_qcc(s, len, qntsty, properties); break;

            case J2K_QCD:

                ret = get_qcd(s, len, qntsty, properties); break;

            case J2K_SOT:

                if (!(ret = get_sot(s))){

                    codsty = s->tile[s->curtileno].codsty;

                    qntsty = s->tile[s->curtileno].qntsty;

                    properties = s->tile[s->curtileno].properties;

                }

                break;

            case J2K_COM:

                

                s->buf += len - 2; break;

            default:

                av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);

                s->buf += len - 2; break;

        }

        if (s->buf - oldbuf != len || ret){

            av_log(s->avctx, AV_LOG_ERROR, "error during processing marker segment %.4x\n", marker);

            return ret ? ret : -1;

        }

    }

    return 0;

}

                break;                 break;         if (s->buf_end - s->buf < 2)         int marker, len, ret = 0;         const uint8_t *oldbuf;         if (s->buf_end - s->buf < 2){         marker = bytestream_get_be16(&s->buf);         if(s->avctx->debug & FF_DEBUG_STARTCODE)             av_log(s->avctx, AV_LOG_DEBUG, "marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);         oldbuf = s->buf;             if (ret = init_tile(s, s->curtileno))             if (ret = decode_packets(s, tile))         if (s->buf_end - s->buf < 2)         len = bytestream_get_be16(&s->buf);         switch(marker){             case J2K_SIZ:                 ret = get_siz(s); break;             case J2K_COC:                 ret = get_coc(s, codsty, properties); break;             case J2K_COD:                 ret = get_cod(s, codsty, properties); break;             case J2K_QCC:                 ret = get_qcc(s, len, qntsty, properties); break;             case J2K_QCD:                 ret = get_qcd(s, len, qntsty, properties); break;             case J2K_SOT:                 if (!(ret = get_sot(s))){                     codsty = s->tile[s->curtileno].codsty;                     qntsty = s->tile[s->curtileno].qntsty;                     properties = s->tile[s->curtileno].properties;                 break;             case J2K_COM:                 s->buf += len - 2; break;             default:                 av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);                 s->buf += len - 2; break;         if (s->buf - oldbuf != len || ret){
static int FUNC_0(J2kDecoderContext *VAR_0)

{

    J2kCodingStyle *codsty = VAR_0->codsty;

    J2kQuantStyle  *qntsty = VAR_0->qntsty;

    uint8_t *properties = VAR_0->properties;



    for (;;){

        int VAR_1, VAR_2, VAR_3 = 0;

        const uint8_t *VAR_4;

        if (VAR_0->buf_end - VAR_0->buf < 2){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Missing EOC\n");

            break;

        }



        VAR_1 = bytestream_get_be16(&VAR_0->buf);

        if(VAR_0->avctx->debug & FF_DEBUG_STARTCODE)

            av_log(VAR_0->avctx, AV_LOG_DEBUG, "VAR_1 0x%.4X at pos 0x%tx\n", VAR_1, VAR_0->buf - VAR_0->buf_start - 4);

        VAR_4 = VAR_0->buf;



        if (VAR_1 == J2K_SOD){

            J2kTile *tile = VAR_0->tile + VAR_0->curtileno;

            if (VAR_3 = init_tile(VAR_0, VAR_0->curtileno))

                return VAR_3;

            if (VAR_3 = decode_packets(VAR_0, tile))

                return VAR_3;

            continue;

        }

        if (VAR_1 == J2K_EOC)

            break;



        if (VAR_0->buf_end - VAR_0->buf < 2)

            return AVERROR(EINVAL);

        VAR_2 = bytestream_get_be16(&VAR_0->buf);

        switch(VAR_1){

            case J2K_SIZ:

                VAR_3 = get_siz(VAR_0); break;

            case J2K_COC:

                VAR_3 = get_coc(VAR_0, codsty, properties); break;

            case J2K_COD:

                VAR_3 = get_cod(VAR_0, codsty, properties); break;

            case J2K_QCC:

                VAR_3 = get_qcc(VAR_0, VAR_2, qntsty, properties); break;

            case J2K_QCD:

                VAR_3 = get_qcd(VAR_0, VAR_2, qntsty, properties); break;

            case J2K_SOT:

                if (!(VAR_3 = get_sot(VAR_0))){

                    codsty = VAR_0->tile[VAR_0->curtileno].codsty;

                    qntsty = VAR_0->tile[VAR_0->curtileno].qntsty;

                    properties = VAR_0->tile[VAR_0->curtileno].properties;

                }

                break;

            case J2K_COM:

                

                VAR_0->buf += VAR_2 - 2; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "unsupported VAR_1 0x%.4X at pos 0x%tx\n", VAR_1, VAR_0->buf - VAR_0->buf_start - 4);

                VAR_0->buf += VAR_2 - 2; break;

        }

        if (VAR_0->buf - VAR_4 != VAR_2 || VAR_3){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "error during processing VAR_1 segment %.4x\n", VAR_1);

            return VAR_3 ? VAR_3 : -1;

        }

    }

    return 0;

}

static int FUNC_0(J2kDecoderContext *VAR_0)
{ J2kCodingStyle *codsty = VAR_0->codsty; J2kQuantStyle  *qntsty = VAR_0->qntsty; uint8_t *properties = VAR_0->properties; for (;;){ int VAR_1, VAR_2, VAR_3 = 0; const uint8_t *VAR_4; if (VAR_0->buf_end - VAR_0->buf < 2){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Missing EOC\n"); break; } VAR_1 = bytestream_get_be16(&VAR_0->buf); if(VAR_0->avctx->debug & FF_DEBUG_STARTCODE)
av_log(VAR_0->avctx, AV_LOG_DEBUG, "VAR_1 0x%.4X at pos 0x%tx\n", VAR_1, VAR_0->buf - VAR_0->buf_start - 4); VAR_4 = VAR_0->buf; if (VAR_1 == J2K_SOD){ J2kTile *tile = VAR_0->tile + VAR_0->curtileno; if (VAR_3 = init_tile(VAR_0, VAR_0->curtileno))
return VAR_3; if (VAR_3 = decode_packets(VAR_0, tile))
return VAR_3; continue; } if (VAR_1 == J2K_EOC)
break; if (VAR_0->buf_end - VAR_0->buf < 2)
return AVERROR(EINVAL); VAR_2 = bytestream_get_be16(&VAR_0->buf); switch(VAR_1){ case J2K_SIZ:
VAR_3 = get_siz(VAR_0); break; case J2K_COC:
VAR_3 = get_coc(VAR_0, codsty, properties); break; case J2K_COD:
VAR_3 = get_cod(VAR_0, codsty, properties); break; case J2K_QCC:
VAR_3 = get_qcc(VAR_0, VAR_2, qntsty, properties); break; case J2K_QCD:
VAR_3 = get_qcd(VAR_0, VAR_2, qntsty, properties); break; case J2K_SOT:
if (!(VAR_3 = get_sot(VAR_0))){ codsty = VAR_0->tile[VAR_0->curtileno].codsty; qntsty = VAR_0->tile[VAR_0->curtileno].qntsty; properties = VAR_0->tile[VAR_0->curtileno].properties; } break; case J2K_COM:
VAR_0->buf += VAR_2 - 2; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "unsupported VAR_1 0x%.4X at pos 0x%tx\n", VAR_1, VAR_0->buf - VAR_0->buf_start - 4); VAR_0->buf += VAR_2 - 2; break; } if (VAR_0->buf - VAR_4 != VAR_2 || VAR_3){ av_log(VAR_0->avctx, AV_LOG_ERROR, "error during processing VAR_1 segment %.4x\n", VAR_1); return VAR_3 ? VAR_3 : -1; } } return 0; }