static int check_bits_for_superframe(GetBitContext *orig_gb,

                                     WMAVoiceContext *s)

{

    GetBitContext s_gb, *gb = &s_gb;

    int n, need_bits, bd_idx;

    const struct frame_type_desc *frame_desc;



    /* initialize a copy */

    init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits);

    skip_bits_long(gb, get_bits_count(orig_gb));

    av_assert1(get_bits_left(gb) == get_bits_left(orig_gb));



    /* superframe header */

    if (get_bits_left(gb) < 14)

        return 1;

    if (!get_bits1(gb))

        return AVERROR(ENOSYS);           // WMAPro-in-WMAVoice superframe

    if (get_bits1(gb)) skip_bits(gb, 12); // number of  samples in superframe

    if (s->has_residual_lsps) {           // residual LSPs (for all frames)

        if (get_bits_left(gb) < s->sframe_lsp_bitsize)

            return 1;

        skip_bits_long(gb, s->sframe_lsp_bitsize);

    }



    /* frames */

    for (n = 0; n < MAX_FRAMES; n++) {

        int aw_idx_is_ext = 0;



        if (!s->has_residual_lsps) {     // independent LSPs (per-frame)

           if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1;

           skip_bits_long(gb, s->frame_lsp_bitsize);

        }

        bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];

        if (bd_idx < 0)

            return AVERROR_INVALIDDATA; // invalid frame type VLC code

        frame_desc = &frame_descs[bd_idx];

        if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {

            if (get_bits_left(gb) < s->pitch_nbits)

                return 1;

            skip_bits_long(gb, s->pitch_nbits);

        }

        if (frame_desc->fcb_type == FCB_TYPE_SILENCE) {

            skip_bits(gb, 8);

        } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {

            int tmp = get_bits(gb, 6);

            if (tmp >= 0x36) {

                skip_bits(gb, 2);

                aw_idx_is_ext = 1;

            }

        }



        /* blocks */

        if (frame_desc->acb_type == ACB_TYPE_HAMMING) {

            need_bits = s->block_pitch_nbits +

                (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits;

        } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {

            need_bits = 2 * !aw_idx_is_ext;

        } else

            need_bits = 0;

        need_bits += frame_desc->frame_size;

        if (get_bits_left(gb) < need_bits)

            return 1;

        skip_bits_long(gb, need_bits);

    }



    return 0;

}

static int check_bits_for_superframe(GetBitContext *orig_gb,

                                     WMAVoiceContext *s)

{

    GetBitContext s_gb, *gb = &s_gb;

    int n, need_bits, bd_idx;

    const struct frame_type_desc *frame_desc;



    

    init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits);

    skip_bits_long(gb, get_bits_count(orig_gb));

    av_assert1(get_bits_left(gb) == get_bits_left(orig_gb));



    

    if (get_bits_left(gb) < 14)

        return 1;

    if (!get_bits1(gb))

        return AVERROR(ENOSYS);           

    if (get_bits1(gb)) skip_bits(gb, 12); 

    if (s->has_residual_lsps) {           

        if (get_bits_left(gb) < s->sframe_lsp_bitsize)

            return 1;

        skip_bits_long(gb, s->sframe_lsp_bitsize);

    }



    

    for (n = 0; n < MAX_FRAMES; n++) {

        int aw_idx_is_ext = 0;



        if (!s->has_residual_lsps) {     

           if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1;

           skip_bits_long(gb, s->frame_lsp_bitsize);

        }

        bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];

        if (bd_idx < 0)

            return AVERROR_INVALIDDATA; 

        frame_desc = &frame_descs[bd_idx];

        if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {

            if (get_bits_left(gb) < s->pitch_nbits)

                return 1;

            skip_bits_long(gb, s->pitch_nbits);

        }

        if (frame_desc->fcb_type == FCB_TYPE_SILENCE) {

            skip_bits(gb, 8);

        } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {

            int tmp = get_bits(gb, 6);

            if (tmp >= 0x36) {

                skip_bits(gb, 2);

                aw_idx_is_ext = 1;

            }

        }



        

        if (frame_desc->acb_type == ACB_TYPE_HAMMING) {

            need_bits = s->block_pitch_nbits +

                (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits;

        } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {

            need_bits = 2 * !aw_idx_is_ext;

        } else

            need_bits = 0;

        need_bits += frame_desc->frame_size;

        if (get_bits_left(gb) < need_bits)

            return 1;

        skip_bits_long(gb, need_bits);

    }



    return 0;

}

static int FUNC_0(GetBitContext *VAR_0,

                                     WMAVoiceContext *VAR_1)

{

    GetBitContext s_gb, *gb = &s_gb;

    int VAR_2, VAR_3, VAR_4;

    const struct frame_type_desc *VAR_5;



    

    init_get_bits(gb, VAR_0->buffer, VAR_0->size_in_bits);

    skip_bits_long(gb, get_bits_count(VAR_0));

    av_assert1(get_bits_left(gb) == get_bits_left(VAR_0));



    

    if (get_bits_left(gb) < 14)

        return 1;

    if (!get_bits1(gb))

        return AVERROR(ENOSYS);           

    if (get_bits1(gb)) skip_bits(gb, 12); 

    if (VAR_1->has_residual_lsps) {           

        if (get_bits_left(gb) < VAR_1->sframe_lsp_bitsize)

            return 1;

        skip_bits_long(gb, VAR_1->sframe_lsp_bitsize);

    }



    

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

        int aw_idx_is_ext = 0;



        if (!VAR_1->has_residual_lsps) {     

           if (get_bits_left(gb) < VAR_1->frame_lsp_bitsize) return 1;

           skip_bits_long(gb, VAR_1->frame_lsp_bitsize);

        }

        VAR_4 = VAR_1->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];

        if (VAR_4 < 0)

            return AVERROR_INVALIDDATA; 

        VAR_5 = &frame_descs[VAR_4];

        if (VAR_5->acb_type == ACB_TYPE_ASYMMETRIC) {

            if (get_bits_left(gb) < VAR_1->pitch_nbits)

                return 1;

            skip_bits_long(gb, VAR_1->pitch_nbits);

        }

        if (VAR_5->fcb_type == FCB_TYPE_SILENCE) {

            skip_bits(gb, 8);

        } else if (VAR_5->fcb_type == FCB_TYPE_AW_PULSES) {

            int tmp = get_bits(gb, 6);

            if (tmp >= 0x36) {

                skip_bits(gb, 2);

                aw_idx_is_ext = 1;

            }

        }



        

        if (VAR_5->acb_type == ACB_TYPE_HAMMING) {

            VAR_3 = VAR_1->block_pitch_nbits +

                (VAR_5->n_blocks - 1) * VAR_1->block_delta_pitch_nbits;

        } else if (VAR_5->fcb_type == FCB_TYPE_AW_PULSES) {

            VAR_3 = 2 * !aw_idx_is_ext;

        } else

            VAR_3 = 0;

        VAR_3 += VAR_5->frame_size;

        if (get_bits_left(gb) < VAR_3)

            return 1;

        skip_bits_long(gb, VAR_3);

    }



    return 0;

}

static int FUNC_0(GetBitContext *VAR_0,
WMAVoiceContext *VAR_1)
{ GetBitContext s_gb, *gb = &s_gb; int VAR_2, VAR_3, VAR_4; const struct frame_type_desc *VAR_5; init_get_bits(gb, VAR_0->buffer, VAR_0->size_in_bits); skip_bits_long(gb, get_bits_count(VAR_0)); av_assert1(get_bits_left(gb) == get_bits_left(VAR_0)); if (get_bits_left(gb) < 14)
return 1; if (!get_bits1(gb))
return AVERROR(ENOSYS); if (get_bits1(gb)) skip_bits(gb, 12); if (VAR_1->has_residual_lsps) { if (get_bits_left(gb) < VAR_1->sframe_lsp_bitsize)
return 1; skip_bits_long(gb, VAR_1->sframe_lsp_bitsize); } for (VAR_2 = 0; VAR_2 < MAX_FRAMES; VAR_2++) { int aw_idx_is_ext = 0; if (!VAR_1->has_residual_lsps) { if (get_bits_left(gb) < VAR_1->frame_lsp_bitsize) return 1; skip_bits_long(gb, VAR_1->frame_lsp_bitsize); } VAR_4 = VAR_1->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)]; if (VAR_4 < 0)
return AVERROR_INVALIDDATA; VAR_5 = &frame_descs[VAR_4]; if (VAR_5->acb_type == ACB_TYPE_ASYMMETRIC) { if (get_bits_left(gb) < VAR_1->pitch_nbits)
return 1; skip_bits_long(gb, VAR_1->pitch_nbits); } if (VAR_5->fcb_type == FCB_TYPE_SILENCE) { skip_bits(gb, 8); } else if (VAR_5->fcb_type == FCB_TYPE_AW_PULSES) { int tmp = get_bits(gb, 6); if (tmp >= 0x36) { skip_bits(gb, 2); aw_idx_is_ext = 1; } } if (VAR_5->acb_type == ACB_TYPE_HAMMING) { VAR_3 = VAR_1->block_pitch_nbits +
(VAR_5->n_blocks - 1) * VAR_1->block_delta_pitch_nbits; } else if (VAR_5->fcb_type == FCB_TYPE_AW_PULSES) { VAR_3 = 2 * !aw_idx_is_ext; } else VAR_3 = 0; VAR_3 += VAR_5->frame_size; if (get_bits_left(gb) < VAR_3)
return 1; skip_bits_long(gb, VAR_3); } return 0; }