int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

    const uint64_t fuzz_tag = FUZZ_TAG;

    FuzzDataBuffer buffer;

    const uint8_t *last = data;

    const uint8_t *end = data + size;

    uint32_t it = 0;



    if (!c)

        c = AVCodecInitialize(FFMPEG_CODEC);  // Done once.



    AVCodecContext* ctx = avcodec_alloc_context3(NULL);

    if (!ctx)

        error("Failed memory allocation");



    ctx->max_pixels = 4096 * 4096; //To reduce false positive OOM and hangs



    int res = avcodec_open2(ctx, c, NULL);

    if (res < 0)

        return res;



    FDBCreate(&buffer);

    int got_frame;

    AVFrame *frame = av_frame_alloc();

    if (!frame)

        error("Failed memory allocation");



    // Read very simple container

    AVPacket avpkt;

    while (data < end && it < maxiteration) {

        // Search for the TAG

        while (data + sizeof(fuzz_tag) < end) {

            if (data[0] == (fuzz_tag & 0xFF) && *(const uint64_t *)(data) == fuzz_tag)

                break;

            data++;

        }

        if (data + sizeof(fuzz_tag) > end)

            data = end;



        FDBPrepare(&buffer, &avpkt, last, data - last);

        data += sizeof(fuzz_tag);

        last = data;



        // Iterate through all data

        while (avpkt.size > 0 && it++ < maxiteration) {

            av_frame_unref(frame);

            int ret = decode_handler(ctx, frame, &got_frame, &avpkt);



            if (it > 20)

                ctx->error_concealment = 0;



            if (ret <= 0 || ret > avpkt.size)

               break;



            avpkt.data += ret;

            avpkt.size -= ret;

        }

    }



    av_init_packet(&avpkt);

    avpkt.data = NULL;

    avpkt.size = 0;



    do {

        got_frame = 0;

        decode_handler(ctx, frame, &got_frame, &avpkt);

    } while (got_frame == 1 && it++ < maxiteration);



    av_frame_free(&frame);

    avcodec_free_context(&ctx);

    av_freep(&ctx);

    FDBDesroy(&buffer);

    return 0;

}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

    const uint64_t fuzz_tag = FUZZ_TAG;

    FuzzDataBuffer buffer;

    const uint8_t *last = data;

    const uint8_t *end = data + size;

    uint32_t it = 0;



    if (!c)

        c = AVCodecInitialize(FFMPEG_CODEC);  



    AVCodecContext* ctx = avcodec_alloc_context3(NULL);

    if (!ctx)

        error("Failed memory allocation");



    ctx->max_pixels = 4096 * 4096; 



    int res = avcodec_open2(ctx, c, NULL);

    if (res < 0)

        return res;



    FDBCreate(&buffer);

    int got_frame;

    AVFrame *frame = av_frame_alloc();

    if (!frame)

        error("Failed memory allocation");



    

    AVPacket avpkt;

    while (data < end && it < maxiteration) {

        

        while (data + sizeof(fuzz_tag) < end) {

            if (data[0] == (fuzz_tag & 0xFF) && *(const uint64_t *)(data) == fuzz_tag)

                break;

            data++;

        }

        if (data + sizeof(fuzz_tag) > end)

            data = end;



        FDBPrepare(&buffer, &avpkt, last, data - last);

        data += sizeof(fuzz_tag);

        last = data;



        

        while (avpkt.size > 0 && it++ < maxiteration) {

            av_frame_unref(frame);

            int ret = decode_handler(ctx, frame, &got_frame, &avpkt);



            if (it > 20)

                ctx->error_concealment = 0;



            if (ret <= 0 || ret > avpkt.size)

               break;



            avpkt.data += ret;

            avpkt.size -= ret;

        }

    }



    av_init_packet(&avpkt);

    avpkt.data = NULL;

    avpkt.size = 0;



    do {

        got_frame = 0;

        decode_handler(ctx, frame, &got_frame, &avpkt);

    } while (got_frame == 1 && it++ < maxiteration);



    av_frame_free(&frame);

    avcodec_free_context(&ctx);

    av_freep(&ctx);

    FDBDesroy(&buffer);

    return 0;

}
int FUNC_0(const uint8_t *VAR_0, size_t VAR_1) {

    const uint64_t VAR_2 = FUZZ_TAG;

    FuzzDataBuffer buffer;

    const uint8_t *VAR_3 = VAR_0;

    const uint8_t *VAR_4 = VAR_0 + VAR_1;

    uint32_t it = 0;



    if (!c)

        c = AVCodecInitialize(FFMPEG_CODEC);  



    AVCodecContext* ctx = avcodec_alloc_context3(NULL);

    if (!ctx)

        error("Failed memory allocation");



    ctx->max_pixels = 4096 * 4096; 



    int VAR_5 = avcodec_open2(ctx, c, NULL);

    if (VAR_5 < 0)

        return VAR_5;



    FDBCreate(&buffer);

    int VAR_6;

    AVFrame *frame = av_frame_alloc();

    if (!frame)

        error("Failed memory allocation");



    

    AVPacket avpkt;

    while (VAR_0 < VAR_4 && it < maxiteration) {

        

        while (VAR_0 + sizeof(VAR_2) < VAR_4) {

            if (VAR_0[0] == (VAR_2 & 0xFF) && *(const uint64_t *)(VAR_0) == VAR_2)

                break;

            VAR_0++;

        }

        if (VAR_0 + sizeof(VAR_2) > VAR_4)

            VAR_0 = VAR_4;



        FDBPrepare(&buffer, &avpkt, VAR_3, VAR_0 - VAR_3);

        VAR_0 += sizeof(VAR_2);

        VAR_3 = VAR_0;



        

        while (avpkt.VAR_1 > 0 && it++ < maxiteration) {

            av_frame_unref(frame);

            int VAR_7 = decode_handler(ctx, frame, &VAR_6, &avpkt);



            if (it > 20)

                ctx->error_concealment = 0;



            if (VAR_7 <= 0 || VAR_7 > avpkt.VAR_1)

               break;



            avpkt.VAR_0 += VAR_7;

            avpkt.VAR_1 -= VAR_7;

        }

    }



    av_init_packet(&avpkt);

    avpkt.VAR_0 = NULL;

    avpkt.VAR_1 = 0;



    do {

        VAR_6 = 0;

        decode_handler(ctx, frame, &VAR_6, &avpkt);

    } while (VAR_6 == 1 && it++ < maxiteration);



    av_frame_free(&frame);

    avcodec_free_context(&ctx);

    av_freep(&ctx);

    FDBDesroy(&buffer);

    return 0;

}
int FUNC_0(const uint8_t *VAR_0, size_t VAR_1) { const uint64_t VAR_2 = FUZZ_TAG; FuzzDataBuffer buffer; const uint8_t *VAR_3 = VAR_0; const uint8_t *VAR_4 = VAR_0 + VAR_1; uint32_t it = 0; if (!c)
c = AVCodecInitialize(FFMPEG_CODEC); AVCodecContext* ctx = avcodec_alloc_context3(NULL); if (!ctx)
error("Failed memory allocation"); ctx->max_pixels = 4096 * 4096; int VAR_5 = avcodec_open2(ctx, c, NULL); if (VAR_5 < 0)
return VAR_5; FDBCreate(&buffer); int VAR_6; AVFrame *frame = av_frame_alloc(); if (!frame)
error("Failed memory allocation"); AVPacket avpkt; while (VAR_0 < VAR_4 && it < maxiteration) { while (VAR_0 + sizeof(VAR_2) < VAR_4) { if (VAR_0[0] == (VAR_2 & 0xFF) && *(const uint64_t *)(VAR_0) == VAR_2)
break; VAR_0++; } if (VAR_0 + sizeof(VAR_2) > VAR_4)
VAR_0 = VAR_4; FDBPrepare(&buffer, &avpkt, VAR_3, VAR_0 - VAR_3); VAR_0 += sizeof(VAR_2); VAR_3 = VAR_0; while (avpkt.VAR_1 > 0 && it++ < maxiteration) { av_frame_unref(frame); int VAR_7 = decode_handler(ctx, frame, &VAR_6, &avpkt); if (it > 20)
ctx->error_concealment = 0; if (VAR_7 <= 0 || VAR_7 > avpkt.VAR_1)
break; avpkt.VAR_0 += VAR_7; avpkt.VAR_1 -= VAR_7; } } av_init_packet(&avpkt); avpkt.VAR_0 = NULL; avpkt.VAR_1 = 0; do { VAR_6 = 0; decode_handler(ctx, frame, &VAR_6, &avpkt); } while (VAR_6 == 1 && it++ < maxiteration); av_frame_free(&frame); avcodec_free_context(&ctx); av_freep(&ctx); FDBDesroy(&buffer); return 0; }