static int decode_main_header(NUTContext *nut){

    AVFormatContext *s= nut->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp, end;

    unsigned int stream_count;

    int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res;



    end= get_packetheader(nut, bc, 1);

    end += url_ftell(bc) - 4;



    GET_V(tmp              , tmp >=2 && tmp <= 3)

    GET_V(stream_count     , tmp > 0 && tmp <=MAX_STREAMS)



    nut->max_distance = get_v(bc);

    if(nut->max_distance > 65536){

        av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);

        nut->max_distance= 65536;

    }



    GET_V(nut->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))

    nut->time_base= av_malloc(nut->time_base_count * sizeof(AVRational));



    for(i=0; i<nut->time_base_count; i++){

        GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))

        GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))

        if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){

            av_log(s, AV_LOG_ERROR, "time base invalid\n");

            return -1;

        }

    }

    tmp_pts=0;

    tmp_mul=1;

    tmp_stream=0;

    for(i=0; i<256;){

        int tmp_flags = get_v(bc);

        int tmp_fields= get_v(bc);

        if(tmp_fields>0) tmp_pts   = get_s(bc);

        if(tmp_fields>1) tmp_mul   = get_v(bc);

        if(tmp_fields>2) tmp_stream= get_v(bc);

        if(tmp_fields>3) tmp_size  = get_v(bc);

        else             tmp_size  = 0;

        if(tmp_fields>4) tmp_res   = get_v(bc);

        else             tmp_res   = 0;

        if(tmp_fields>5) count     = get_v(bc);

        else             count     = tmp_mul - tmp_size;



        while(tmp_fields-- > 6)

           get_v(bc);



        if(count == 0 || i+count > 256){

            av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);

            return -1;

        }

        if(tmp_stream >= stream_count){

            av_log(s, AV_LOG_ERROR, "illegal stream number\n");

            return -1;

        }



        for(j=0; j<count; j++,i++){

            if (i == 'N') {

                nut->frame_code[i].flags= FLAG_INVALID;

                j--;

                continue;

            }

            nut->frame_code[i].flags           = tmp_flags ;

            nut->frame_code[i].pts_delta       = tmp_pts   ;

            nut->frame_code[i].stream_id       = tmp_stream;

            nut->frame_code[i].size_mul        = tmp_mul   ;

            nut->frame_code[i].size_lsb        = tmp_size+j;

            nut->frame_code[i].reserved_count  = tmp_res   ;

        }

    }

    assert(nut->frame_code['N'].flags == FLAG_INVALID);



    if(skip_reserved(bc, end) || check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n");

        return -1;

    }



    nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);

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

        av_new_stream(s, i);

    }



    return 0;

}

static int decode_main_header(NUTContext *nut){

    AVFormatContext *s= nut->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp, end;

    unsigned int stream_count;

    int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res;



    end= get_packetheader(nut, bc, 1);

    end += url_ftell(bc) - 4;



    GET_V(tmp              , tmp >=2 && tmp <= 3)

    GET_V(stream_count     , tmp > 0 && tmp <=MAX_STREAMS)



    nut->max_distance = get_v(bc);

    if(nut->max_distance > 65536){

        av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);

        nut->max_distance= 65536;

    }



    GET_V(nut->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))

    nut->time_base= av_malloc(nut->time_base_count * sizeof(AVRational));



    for(i=0; i<nut->time_base_count; i++){

        GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))

        GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))

        if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){

            av_log(s, AV_LOG_ERROR, "time base invalid\n");

            return -1;

        }

    }

    tmp_pts=0;

    tmp_mul=1;

    tmp_stream=0;

    for(i=0; i<256;){

        int tmp_flags = get_v(bc);

        int tmp_fields= get_v(bc);

        if(tmp_fields>0) tmp_pts   = get_s(bc);

        if(tmp_fields>1) tmp_mul   = get_v(bc);

        if(tmp_fields>2) tmp_stream= get_v(bc);

        if(tmp_fields>3) tmp_size  = get_v(bc);

        else             tmp_size  = 0;

        if(tmp_fields>4) tmp_res   = get_v(bc);

        else             tmp_res   = 0;

        if(tmp_fields>5) count     = get_v(bc);

        else             count     = tmp_mul - tmp_size;



        while(tmp_fields-- > 6)

           get_v(bc);



        if(count == 0 || i+count > 256){

            av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);

            return -1;

        }

        if(tmp_stream >= stream_count){

            av_log(s, AV_LOG_ERROR, "illegal stream number\n");

            return -1;

        }



        for(j=0; j<count; j++,i++){

            if (i == 'N') {

                nut->frame_code[i].flags= FLAG_INVALID;

                j--;

                continue;

            }

            nut->frame_code[i].flags           = tmp_flags ;

            nut->frame_code[i].pts_delta       = tmp_pts   ;

            nut->frame_code[i].stream_id       = tmp_stream;

            nut->frame_code[i].size_mul        = tmp_mul   ;

            nut->frame_code[i].size_lsb        = tmp_size+j;

            nut->frame_code[i].reserved_count  = tmp_res   ;

        }

    }

    assert(nut->frame_code['N'].flags == FLAG_INVALID);



    if(skip_reserved(bc, end) || check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n");

        return -1;

    }



    nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);

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

        av_new_stream(s, i);

    }



    return 0;

}

    return 0;     end += url_ftell(bc) - 4;     if(skip_reserved(bc, end) || check_checksum(bc)){     end += url_ftell(bc) - 4;     if(skip_reserved(bc, end) || check_checksum(bc)){     end += url_ftell(bc) - 4;     if(skip_reserved(bc, end) || check_checksum(bc)){     end += url_ftell(bc) - 4;     if(skip_reserved(bc, end) || check_checksum(bc)){     end += url_ftell(bc) - 4;     if(skip_reserved(bc, end) || check_checksum(bc)){
static int FUNC_0(NUTContext *VAR_0){

    AVFormatContext *s= VAR_0->avf;

    ByteIOContext *bc = &s->pb;

    uint64_t tmp, end;

    unsigned int VAR_1;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;



    end= get_packetheader(VAR_0, bc, 1);

    end += url_ftell(bc) - 4;



    GET_V(tmp              , tmp >=2 && tmp <= 3)

    GET_V(VAR_1     , tmp > 0 && tmp <=MAX_STREAMS)



    VAR_0->max_distance = get_v(bc);

    if(VAR_0->max_distance > 65536){

        av_log(s, AV_LOG_DEBUG, "max_distance %d\n", VAR_0->max_distance);

        VAR_0->max_distance= 65536;

    }



    GET_V(VAR_0->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))

    VAR_0->time_base= av_malloc(VAR_0->time_base_count * sizeof(AVRational));



    for(VAR_2=0; VAR_2<VAR_0->time_base_count; VAR_2++){

        GET_V(VAR_0->time_base[VAR_2].num, tmp>0 && tmp<(1ULL<<31))

        GET_V(VAR_0->time_base[VAR_2].den, tmp>0 && tmp<(1ULL<<31))

        if(ff_gcd(VAR_0->time_base[VAR_2].num, VAR_0->time_base[VAR_2].den) != 1){

            av_log(s, AV_LOG_ERROR, "time base invalid\n");

            return -1;

        }

    }

    VAR_6=0;

    VAR_5=1;

    VAR_4=0;

    for(VAR_2=0; VAR_2<256;){

        int VAR_10 = get_v(bc);

        int VAR_11= get_v(bc);

        if(VAR_11>0) VAR_6   = get_s(bc);

        if(VAR_11>1) VAR_5   = get_v(bc);

        if(VAR_11>2) VAR_4= get_v(bc);

        if(VAR_11>3) VAR_7  = get_v(bc);

        else             VAR_7  = 0;

        if(VAR_11>4) VAR_9   = get_v(bc);

        else             VAR_9   = 0;

        if(VAR_11>5) VAR_8     = get_v(bc);

        else             VAR_8     = VAR_5 - VAR_7;



        while(VAR_11-- > 6)

           get_v(bc);



        if(VAR_8 == 0 || VAR_2+VAR_8 > 256){

            av_log(s, AV_LOG_ERROR, "illegal VAR_8 %d at %d\n", VAR_8, VAR_2);

            return -1;

        }

        if(VAR_4 >= VAR_1){

            av_log(s, AV_LOG_ERROR, "illegal stream number\n");

            return -1;

        }



        for(VAR_3=0; VAR_3<VAR_8; VAR_3++,VAR_2++){

            if (VAR_2 == 'N') {

                VAR_0->frame_code[VAR_2].flags= FLAG_INVALID;

                VAR_3--;

                continue;

            }

            VAR_0->frame_code[VAR_2].flags           = VAR_10 ;

            VAR_0->frame_code[VAR_2].pts_delta       = VAR_6   ;

            VAR_0->frame_code[VAR_2].stream_id       = VAR_4;

            VAR_0->frame_code[VAR_2].size_mul        = VAR_5   ;

            VAR_0->frame_code[VAR_2].size_lsb        = VAR_7+VAR_3;

            VAR_0->frame_code[VAR_2].reserved_count  = VAR_9   ;

        }

    }

    assert(VAR_0->frame_code['N'].flags == FLAG_INVALID);



    if(skip_reserved(bc, end) || check_checksum(bc)){

        av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n");

        return -1;

    }



    VAR_0->stream = av_mallocz(sizeof(StreamContext)*VAR_1);

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

        av_new_stream(s, VAR_2);

    }



    return 0;

}

static int FUNC_0(NUTContext *VAR_0){ AVFormatContext *s= VAR_0->avf; ByteIOContext *bc = &s->pb; uint64_t tmp, end; unsigned int VAR_1; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; end= get_packetheader(VAR_0, bc, 1); end += url_ftell(bc) - 4; GET_V(tmp              , tmp >=2 && tmp <= 3)
GET_V(VAR_1     , tmp > 0 && tmp <=MAX_STREAMS)
VAR_0->max_distance = get_v(bc); if(VAR_0->max_distance > 65536){ av_log(s, AV_LOG_DEBUG, "max_distance %d\n", VAR_0->max_distance); VAR_0->max_distance= 65536; } GET_V(VAR_0->time_base_count, tmp>0 && tmp<INT_MAX / sizeof(AVRational))
VAR_0->time_base= av_malloc(VAR_0->time_base_count * sizeof(AVRational)); for(VAR_2=0; VAR_2<VAR_0->time_base_count; VAR_2++){ GET_V(VAR_0->time_base[VAR_2].num, tmp>0 && tmp<(1ULL<<31))
GET_V(VAR_0->time_base[VAR_2].den, tmp>0 && tmp<(1ULL<<31))
if(ff_gcd(VAR_0->time_base[VAR_2].num, VAR_0->time_base[VAR_2].den) != 1){ av_log(s, AV_LOG_ERROR, "time base invalid\n"); return -1; } } VAR_6=0; VAR_5=1; VAR_4=0; for(VAR_2=0; VAR_2<256;){ int VAR_10 = get_v(bc); int VAR_11= get_v(bc); if(VAR_11>0) VAR_6   = get_s(bc); if(VAR_11>1) VAR_5   = get_v(bc); if(VAR_11>2) VAR_4= get_v(bc); if(VAR_11>3) VAR_7  = get_v(bc); else             VAR_7  = 0; if(VAR_11>4) VAR_9   = get_v(bc); else             VAR_9   = 0; if(VAR_11>5) VAR_8     = get_v(bc); else             VAR_8     = VAR_5 - VAR_7; while(VAR_11-- > 6)
get_v(bc); if(VAR_8 == 0 || VAR_2+VAR_8 > 256){ av_log(s, AV_LOG_ERROR, "illegal VAR_8 %d at %d\n", VAR_8, VAR_2); return -1; } if(VAR_4 >= VAR_1){ av_log(s, AV_LOG_ERROR, "illegal stream number\n"); return -1; } for(VAR_3=0; VAR_3<VAR_8; VAR_3++,VAR_2++){ if (VAR_2 == 'N') { VAR_0->frame_code[VAR_2].flags= FLAG_INVALID; VAR_3--; continue; } VAR_0->frame_code[VAR_2].flags           = VAR_10 ; VAR_0->frame_code[VAR_2].pts_delta       = VAR_6   ; VAR_0->frame_code[VAR_2].stream_id       = VAR_4; VAR_0->frame_code[VAR_2].size_mul        = VAR_5   ; VAR_0->frame_code[VAR_2].size_lsb        = VAR_7+VAR_3; VAR_0->frame_code[VAR_2].reserved_count  = VAR_9   ; } } assert(VAR_0->frame_code['N'].flags == FLAG_INVALID); if(skip_reserved(bc, end) || check_checksum(bc)){ av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n"); return -1; } VAR_0->stream = av_mallocz(sizeof(StreamContext)*VAR_1); for(VAR_2=0; VAR_2<VAR_1; VAR_2++){ av_new_stream(s, VAR_2); } return 0; }