static int dnxhd_find_frame_end(DNXHDParserContext *dctx,

                                const uint8_t *buf, int buf_size)

{

    ParseContext *pc = &dctx->pc;

    uint64_t state = pc->state64;

    int pic_found = pc->frame_start_found;

    int i = 0;



    if (!pic_found) {

        for (i = 0; i < buf_size; i++) {

            state = (state << 8) | buf[i];

            if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) {

                i++;

                pic_found = 1;

                dctx->cur_byte = 0;

                dctx->remaining = 0;

                break;

            }

        }

    }



    if (pic_found && !dctx->remaining) {

        if (!buf_size) /* EOF considered as end of frame */

            return 0;

        for (; i < buf_size; i++) {

            dctx->cur_byte++;

            state = (state << 8) | buf[i];



            if (dctx->cur_byte == 24) {

                dctx->h = (state >> 32) & 0xFFFF;

            } else if (dctx->cur_byte == 26) {

                dctx->w = (state >> 32) & 0xFFFF;

            } else if (dctx->cur_byte == 42) {

                int cid = (state >> 32) & 0xFFFFFFFF;



                if (cid <= 0)

                    continue;



                dctx->remaining = avpriv_dnxhd_get_frame_size(cid);

                if (dctx->remaining <= 0) {

                    dctx->remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h);

                    if (dctx->remaining <= 0)

                        return dctx->remaining;

                }

                if (buf_size - i + 47 >= dctx->remaining) {

                    int remaining = dctx->remaining;



                    pc->frame_start_found = 0;

                    pc->state64 = -1;

                    dctx->cur_byte = 0;

                    dctx->remaining = 0;

                    return remaining;

                } else {

                    dctx->remaining -= buf_size;

                }

            }

        }

    } else if (pic_found) {

        if (dctx->remaining > buf_size) {

            dctx->remaining -= buf_size;

        } else {

            int remaining = dctx->remaining;



            pc->frame_start_found = 0;

            pc->state64 = -1;

            dctx->cur_byte = 0;

            dctx->remaining = 0;

            return remaining;

        }

    }

    pc->frame_start_found = pic_found;

    pc->state64 = state;

    return END_NOT_FOUND;

}

static int dnxhd_find_frame_end(DNXHDParserContext *dctx,

                                const uint8_t *buf, int buf_size)

{

    ParseContext *pc = &dctx->pc;

    uint64_t state = pc->state64;

    int pic_found = pc->frame_start_found;

    int i = 0;



    if (!pic_found) {

        for (i = 0; i < buf_size; i++) {

            state = (state << 8) | buf[i];

            if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) {

                i++;

                pic_found = 1;

                dctx->cur_byte = 0;

                dctx->remaining = 0;

                break;

            }

        }

    }



    if (pic_found && !dctx->remaining) {

        if (!buf_size) 

            return 0;

        for (; i < buf_size; i++) {

            dctx->cur_byte++;

            state = (state << 8) | buf[i];



            if (dctx->cur_byte == 24) {

                dctx->h = (state >> 32) & 0xFFFF;

            } else if (dctx->cur_byte == 26) {

                dctx->w = (state >> 32) & 0xFFFF;

            } else if (dctx->cur_byte == 42) {

                int cid = (state >> 32) & 0xFFFFFFFF;



                if (cid <= 0)

                    continue;



                dctx->remaining = avpriv_dnxhd_get_frame_size(cid);

                if (dctx->remaining <= 0) {

                    dctx->remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h);

                    if (dctx->remaining <= 0)

                        return dctx->remaining;

                }

                if (buf_size - i + 47 >= dctx->remaining) {

                    int remaining = dctx->remaining;



                    pc->frame_start_found = 0;

                    pc->state64 = -1;

                    dctx->cur_byte = 0;

                    dctx->remaining = 0;

                    return remaining;

                } else {

                    dctx->remaining -= buf_size;

                }

            }

        }

    } else if (pic_found) {

        if (dctx->remaining > buf_size) {

            dctx->remaining -= buf_size;

        } else {

            int remaining = dctx->remaining;



            pc->frame_start_found = 0;

            pc->state64 = -1;

            dctx->cur_byte = 0;

            dctx->remaining = 0;

            return remaining;

        }

    }

    pc->frame_start_found = pic_found;

    pc->state64 = state;

    return END_NOT_FOUND;

}

                dctx->remaining = avpriv_dnxhd_get_frame_size(cid);                 if (dctx->remaining <= 0) {                     dctx->remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h);                     if (dctx->remaining <= 0)                         return dctx->remaining;
static int FUNC_0(DNXHDParserContext *VAR_0,

                                const uint8_t *VAR_1, int VAR_2)

{

    ParseContext *pc = &VAR_0->pc;

    uint64_t state = pc->state64;

    int VAR_3 = pc->frame_start_found;

    int VAR_4 = 0;



    if (!VAR_3) {

        for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

            state = (state << 8) | VAR_1[VAR_4];

            if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) {

                VAR_4++;

                VAR_3 = 1;

                VAR_0->cur_byte = 0;

                VAR_0->VAR_7 = 0;

                break;

            }

        }

    }



    if (VAR_3 && !VAR_0->VAR_7) {

        if (!VAR_2) 

            return 0;

        for (; VAR_4 < VAR_2; VAR_4++) {

            VAR_0->cur_byte++;

            state = (state << 8) | VAR_1[VAR_4];



            if (VAR_0->cur_byte == 24) {

                VAR_0->h = (state >> 32) & 0xFFFF;

            } else if (VAR_0->cur_byte == 26) {

                VAR_0->w = (state >> 32) & 0xFFFF;

            } else if (VAR_0->cur_byte == 42) {

                int VAR_5 = (state >> 32) & 0xFFFFFFFF;



                if (VAR_5 <= 0)

                    continue;



                VAR_0->VAR_7 = avpriv_dnxhd_get_frame_size(VAR_5);

                if (VAR_0->VAR_7 <= 0) {

                    VAR_0->VAR_7 = ff_dnxhd_get_hr_frame_size(VAR_5, VAR_0->w, VAR_0->h);

                    if (VAR_0->VAR_7 <= 0)

                        return VAR_0->VAR_7;

                }

                if (VAR_2 - VAR_4 + 47 >= VAR_0->VAR_7) {

                    int VAR_7 = VAR_0->VAR_7;



                    pc->frame_start_found = 0;

                    pc->state64 = -1;

                    VAR_0->cur_byte = 0;

                    VAR_0->VAR_7 = 0;

                    return VAR_7;

                } else {

                    VAR_0->VAR_7 -= VAR_2;

                }

            }

        }

    } else if (VAR_3) {

        if (VAR_0->VAR_7 > VAR_2) {

            VAR_0->VAR_7 -= VAR_2;

        } else {

            int VAR_7 = VAR_0->VAR_7;



            pc->frame_start_found = 0;

            pc->state64 = -1;

            VAR_0->cur_byte = 0;

            VAR_0->VAR_7 = 0;

            return VAR_7;

        }

    }

    pc->frame_start_found = VAR_3;

    pc->state64 = state;

    return END_NOT_FOUND;

}

static int FUNC_0(DNXHDParserContext *VAR_0,
const uint8_t *VAR_1, int VAR_2)
{ ParseContext *pc = &VAR_0->pc; uint64_t state = pc->state64; int VAR_3 = pc->frame_start_found; int VAR_4 = 0; if (!VAR_3) { for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { state = (state << 8) | VAR_1[VAR_4]; if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) { VAR_4++; VAR_3 = 1; VAR_0->cur_byte = 0; VAR_0->VAR_7 = 0; break; } } } if (VAR_3 && !VAR_0->VAR_7) { if (!VAR_2)
return 0; for (; VAR_4 < VAR_2; VAR_4++) { VAR_0->cur_byte++; state = (state << 8) | VAR_1[VAR_4]; if (VAR_0->cur_byte == 24) { VAR_0->h = (state >> 32) & 0xFFFF; } else if (VAR_0->cur_byte == 26) { VAR_0->w = (state >> 32) & 0xFFFF; } else if (VAR_0->cur_byte == 42) { int VAR_5 = (state >> 32) & 0xFFFFFFFF; if (VAR_5 <= 0)
continue; VAR_0->VAR_7 = avpriv_dnxhd_get_frame_size(VAR_5); if (VAR_0->VAR_7 <= 0) { VAR_0->VAR_7 = ff_dnxhd_get_hr_frame_size(VAR_5, VAR_0->w, VAR_0->h); if (VAR_0->VAR_7 <= 0)
return VAR_0->VAR_7; } if (VAR_2 - VAR_4 + 47 >= VAR_0->VAR_7) { int VAR_7 = VAR_0->VAR_7; pc->frame_start_found = 0; pc->state64 = -1; VAR_0->cur_byte = 0; VAR_0->VAR_7 = 0; return VAR_7; } else { VAR_0->VAR_7 -= VAR_2; } } } } else if (VAR_3) { if (VAR_0->VAR_7 > VAR_2) { VAR_0->VAR_7 -= VAR_2; } else { int VAR_7 = VAR_0->VAR_7; pc->frame_start_found = 0; pc->state64 = -1; VAR_0->cur_byte = 0; VAR_0->VAR_7 = 0; return VAR_7; } } pc->frame_start_found = VAR_3; pc->state64 = state; return END_NOT_FOUND; }