const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
    int i;
    assert(p<=end);
    if(p>=end)
        return end;
    for(i=0; i<3; i++){
        uint32_t tmp= *state << 8;
        *state= tmp + *(p++);
        if(tmp == 0x100 || p==end)
            return p;
    }
    while(p<end){
        if     (p[-1] > 1      ) p+= 3;
        else if(p[-2]          ) p+= 2;
        else if(p[-3]|(p[-1]-1)) p++;
        else{
            p++;
            break;
        }
    }
    p= FFMIN(p, end)-4;
    *state= AV_RB32(p);
    return p+4;
}
['static void mpegvideo_extract_headers(AVCodecParserContext *s,\n                                      AVCodecContext *avctx,\n                                      const uint8_t *buf, int buf_size)\n{\n    ParseContext1 *pc = s->priv_data;\n    const uint8_t *buf_end;\n    uint32_t start_code;\n    int frame_rate_index, ext_type, bytes_left;\n    int frame_rate_ext_n, frame_rate_ext_d;\n    int picture_structure, top_field_first, repeat_first_field, progressive_frame;\n    int horiz_size_ext, vert_size_ext, bit_rate_ext;\n    s->repeat_pict = 0;\n    buf_end = buf + buf_size;\n    while (buf < buf_end) {\n        start_code= -1;\n        buf= ff_find_start_code(buf, buf_end, &start_code);\n        bytes_left = buf_end - buf;\n        switch(start_code) {\n        case PICTURE_START_CODE:\n            if (bytes_left >= 2) {\n                s->pict_type = (buf[1] >> 3) & 7;\n            }\n            break;\n        case SEQ_START_CODE:\n            if (bytes_left >= 7) {\n                pc->width  = (buf[0] << 4) | (buf[1] >> 4);\n                pc->height = ((buf[1] & 0x0f) << 8) | buf[2];\n                avcodec_set_dimensions(avctx, pc->width, pc->height);\n                frame_rate_index = buf[3] & 0xf;\n                pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num;\n                pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den;\n                avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;\n                avctx->codec_id = CODEC_ID_MPEG1VIDEO;\n                avctx->sub_id = 1;\n            }\n            break;\n        case EXT_START_CODE:\n            if (bytes_left >= 1) {\n                ext_type = (buf[0] >> 4);\n                switch(ext_type) {\n                case 0x1:\n                    if (bytes_left >= 6) {\n                        horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);\n                        vert_size_ext = (buf[2] >> 5) & 3;\n                        bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1);\n                        frame_rate_ext_n = (buf[5] >> 5) & 3;\n                        frame_rate_ext_d = (buf[5] & 0x1f);\n                        pc->progressive_sequence = buf[1] & (1 << 3);\n                        avctx->has_b_frames= !(buf[5] >> 7);\n                        pc->width  |=(horiz_size_ext << 12);\n                        pc->height |=( vert_size_ext << 12);\n                        avctx->bit_rate += (bit_rate_ext << 18) * 400;\n                        avcodec_set_dimensions(avctx, pc->width, pc->height);\n                        avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1);\n                        avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1);\n                        avctx->codec_id = CODEC_ID_MPEG2VIDEO;\n                        avctx->sub_id = 2;\n                    }\n                    break;\n                case 0x8:\n                    if (bytes_left >= 5) {\n                        picture_structure = buf[2]&3;\n                        top_field_first = buf[3] & (1 << 7);\n                        repeat_first_field = buf[3] & (1 << 1);\n                        progressive_frame = buf[4] & (1 << 7);\n                        if (repeat_first_field) {\n                            if (pc->progressive_sequence) {\n                                if (top_field_first)\n                                    s->repeat_pict = 4;\n                                else\n                                    s->repeat_pict = 2;\n                            } else if (progressive_frame) {\n                                s->repeat_pict = 1;\n                            }\n                        }\n                    }\n                    break;\n                }\n            }\n            break;\n        case -1:\n            goto the_end;\n        default:\n            if (start_code >= SLICE_MIN_START_CODE &&\n                start_code <= SLICE_MAX_START_CODE)\n                goto the_end;\n            break;\n        }\n    }\n the_end: ;\n}', 'const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){\n    int i;\n    assert(p<=end);\n    if(p>=end)\n        return end;\n    for(i=0; i<3; i++){\n        uint32_t tmp= *state << 8;\n        *state= tmp + *(p++);\n        if(tmp == 0x100 || p==end)\n            return p;\n    }\n    while(p<end){\n        if     (p[-1] > 1      ) p+= 3;\n        else if(p[-2]          ) p+= 2;\n        else if(p[-3]|(p[-1]-1)) p++;\n        else{\n            p++;\n            break;\n        }\n    }\n    p= FFMIN(p, end)-4;\n    *state= AV_RB32(p);\n    return p+4;\n}']