static int decode_tilehdr(WmallDecodeCtx *s)

{

    uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */

    uint8_t  contains_subframe[WMALL_MAX_CHANNELS];   /* flag indicating if a channel contains the current subframe */

    int channels_for_cur_subframe = s->num_channels;  /* number of channels that contain the current subframe */

    int fixed_channel_layout = 0;                     /* flag indicating that all channels use the same subfra2me offsets and sizes */

    int min_channel_len = 0;                          /* smallest sum of samples (channels with this length will be processed first) */

    int c, tile_aligned;



    /* reset tiling information */

    for (c = 0; c < s->num_channels; c++)

        s->channel[c].num_subframes = 0;



    tile_aligned = get_bits1(&s->gb);

    if (s->max_num_subframes == 1 || tile_aligned)

        fixed_channel_layout = 1;



    /* loop until the frame data is split between the subframes */

    do {

        int subframe_len, in_use = 0;



        /* check which channels contain the subframe */

        for (c = 0; c < s->num_channels; c++) {

            if (num_samples[c] == min_channel_len) {

                if (fixed_channel_layout || channels_for_cur_subframe == 1 ||

                   (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {

                    contains_subframe[c] = in_use = 1;

                } else {

                    if (get_bits1(&s->gb))

                        contains_subframe[c] = in_use = 1;

                }

            } else

                contains_subframe[c] = 0;

        }



        if (!in_use) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Found empty subframe\n");

            return AVERROR_INVALIDDATA;

        }



        /* get subframe length, subframe_len == 0 is not allowed */

        if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)

            return AVERROR_INVALIDDATA;

        /* add subframes to the individual channels and find new min_channel_len */

        min_channel_len += subframe_len;

        for (c = 0; c < s->num_channels; c++) {

            WmallChannelCtx *chan = &s->channel[c];



            if (contains_subframe[c]) {

                if (chan->num_subframes >= MAX_SUBFRAMES) {

                    av_log(s->avctx, AV_LOG_ERROR,

                           "broken frame: num subframes > 31\n");

                    return AVERROR_INVALIDDATA;

                }

                chan->subframe_len[chan->num_subframes] = subframe_len;

                num_samples[c] += subframe_len;

                ++chan->num_subframes;

                if (num_samples[c] > s->samples_per_frame) {

                    av_log(s->avctx, AV_LOG_ERROR, "broken frame: "

                           "channel len(%d) > samples_per_frame(%d)\n",

                           num_samples[c], s->samples_per_frame);

                    return AVERROR_INVALIDDATA;

                }

            } else if (num_samples[c] <= min_channel_len) {

                if (num_samples[c] < min_channel_len) {

                    channels_for_cur_subframe = 0;

                    min_channel_len = num_samples[c];

                }

                ++channels_for_cur_subframe;

            }

        }

    } while (min_channel_len < s->samples_per_frame);



    for (c = 0; c < s->num_channels; c++) {

        int i, offset = 0;

        for (i = 0; i < s->channel[c].num_subframes; i++) {

            s->channel[c].subframe_offsets[i] = offset;

            offset += s->channel[c].subframe_len[i];

        }

    }



    return 0;

}

static int decode_tilehdr(WmallDecodeCtx *s)

{

    uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; 

    uint8_t  contains_subframe[WMALL_MAX_CHANNELS];   

    int channels_for_cur_subframe = s->num_channels;  

    int fixed_channel_layout = 0;                     

    int min_channel_len = 0;                          

    int c, tile_aligned;



    

    for (c = 0; c < s->num_channels; c++)

        s->channel[c].num_subframes = 0;



    tile_aligned = get_bits1(&s->gb);

    if (s->max_num_subframes == 1 || tile_aligned)

        fixed_channel_layout = 1;



    

    do {

        int subframe_len, in_use = 0;



        

        for (c = 0; c < s->num_channels; c++) {

            if (num_samples[c] == min_channel_len) {

                if (fixed_channel_layout || channels_for_cur_subframe == 1 ||

                   (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {

                    contains_subframe[c] = in_use = 1;

                } else {

                    if (get_bits1(&s->gb))

                        contains_subframe[c] = in_use = 1;

                }

            } else

                contains_subframe[c] = 0;

        }



        if (!in_use) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Found empty subframe\n");

            return AVERROR_INVALIDDATA;

        }



        

        if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)

            return AVERROR_INVALIDDATA;

        

        min_channel_len += subframe_len;

        for (c = 0; c < s->num_channels; c++) {

            WmallChannelCtx *chan = &s->channel[c];



            if (contains_subframe[c]) {

                if (chan->num_subframes >= MAX_SUBFRAMES) {

                    av_log(s->avctx, AV_LOG_ERROR,

                           "broken frame: num subframes > 31\n");

                    return AVERROR_INVALIDDATA;

                }

                chan->subframe_len[chan->num_subframes] = subframe_len;

                num_samples[c] += subframe_len;

                ++chan->num_subframes;

                if (num_samples[c] > s->samples_per_frame) {

                    av_log(s->avctx, AV_LOG_ERROR, "broken frame: "

                           "channel len(%d) > samples_per_frame(%d)\n",

                           num_samples[c], s->samples_per_frame);

                    return AVERROR_INVALIDDATA;

                }

            } else if (num_samples[c] <= min_channel_len) {

                if (num_samples[c] < min_channel_len) {

                    channels_for_cur_subframe = 0;

                    min_channel_len = num_samples[c];

                }

                ++channels_for_cur_subframe;

            }

        }

    } while (min_channel_len < s->samples_per_frame);



    for (c = 0; c < s->num_channels; c++) {

        int i, offset = 0;

        for (i = 0; i < s->channel[c].num_subframes; i++) {

            s->channel[c].subframe_offsets[i] = offset;

            offset += s->channel[c].subframe_len[i];

        }

    }



    return 0;

}

                    contains_subframe[c] = in_use = 1;                     if (get_bits1(&s->gb))                         contains_subframe[c] = in_use = 1;
static int FUNC_0(WmallDecodeCtx *VAR_0)

{

    uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; 

    uint8_t  contains_subframe[WMALL_MAX_CHANNELS];   

    int VAR_1 = VAR_0->num_channels;  

    int VAR_2 = 0;                     

    int VAR_3 = 0;                          

    int VAR_4, VAR_5;



    

    for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++)

        VAR_0->channel[VAR_4].num_subframes = 0;



    VAR_5 = get_bits1(&VAR_0->gb);

    if (VAR_0->max_num_subframes == 1 || VAR_5)

        VAR_2 = 1;



    

    do {

        int VAR_6, VAR_7 = 0;



        

        for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) {

            if (num_samples[VAR_4] == VAR_3) {

                if (VAR_2 || VAR_1 == 1 ||

                   (VAR_3 == VAR_0->samples_per_frame - VAR_0->min_samples_per_subframe)) {

                    contains_subframe[VAR_4] = VAR_7 = 1;

                } else {

                    if (get_bits1(&VAR_0->gb))

                        contains_subframe[VAR_4] = VAR_7 = 1;

                }

            } else

                contains_subframe[VAR_4] = 0;

        }



        if (!VAR_7) {

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "Found empty subframe\n");

            return AVERROR_INVALIDDATA;

        }



        

        if ((VAR_6 = decode_subframe_length(VAR_0, VAR_3)) <= 0)

            return AVERROR_INVALIDDATA;

        

        VAR_3 += VAR_6;

        for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) {

            WmallChannelCtx *chan = &VAR_0->channel[VAR_4];



            if (contains_subframe[VAR_4]) {

                if (chan->num_subframes >= MAX_SUBFRAMES) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR,

                           "broken frame: num subframes > 31\n");

                    return AVERROR_INVALIDDATA;

                }

                chan->VAR_6[chan->num_subframes] = VAR_6;

                num_samples[VAR_4] += VAR_6;

                ++chan->num_subframes;

                if (num_samples[VAR_4] > VAR_0->samples_per_frame) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "broken frame: "

                           "channel len(%d) > samples_per_frame(%d)\n",

                           num_samples[VAR_4], VAR_0->samples_per_frame);

                    return AVERROR_INVALIDDATA;

                }

            } else if (num_samples[VAR_4] <= VAR_3) {

                if (num_samples[VAR_4] < VAR_3) {

                    VAR_1 = 0;

                    VAR_3 = num_samples[VAR_4];

                }

                ++VAR_1;

            }

        }

    } while (VAR_3 < VAR_0->samples_per_frame);



    for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) {

        int i, offset = 0;

        for (i = 0; i < VAR_0->channel[VAR_4].num_subframes; i++) {

            VAR_0->channel[VAR_4].subframe_offsets[i] = offset;

            offset += VAR_0->channel[VAR_4].VAR_6[i];

        }

    }



    return 0;

}

static int FUNC_0(WmallDecodeCtx *VAR_0)
{ uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; uint8_t  contains_subframe[WMALL_MAX_CHANNELS]; int VAR_1 = VAR_0->num_channels; int VAR_2 = 0; int VAR_3 = 0; int VAR_4, VAR_5; for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) VAR_0->channel[VAR_4].num_subframes = 0; VAR_5 = get_bits1(&VAR_0->gb); if (VAR_0->max_num_subframes == 1 || VAR_5)
VAR_2 = 1; do { int VAR_6, VAR_7 = 0; for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) { if (num_samples[VAR_4] == VAR_3) { if (VAR_2 || VAR_1 == 1 ||
(VAR_3 == VAR_0->samples_per_frame - VAR_0->min_samples_per_subframe)) { contains_subframe[VAR_4] = VAR_7 = 1; } else { if (get_bits1(&VAR_0->gb))
contains_subframe[VAR_4] = VAR_7 = 1; } } else contains_subframe[VAR_4] = 0; } if (!VAR_7) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Found empty subframe\n"); return AVERROR_INVALIDDATA; } if ((VAR_6 = decode_subframe_length(VAR_0, VAR_3)) <= 0)
return AVERROR_INVALIDDATA; VAR_3 += VAR_6; for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) { WmallChannelCtx *chan = &VAR_0->channel[VAR_4]; if (contains_subframe[VAR_4]) { if (chan->num_subframes >= MAX_SUBFRAMES) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"broken frame: num subframes > 31\n"); return AVERROR_INVALIDDATA; } chan->VAR_6[chan->num_subframes] = VAR_6; num_samples[VAR_4] += VAR_6; ++chan->num_subframes; if (num_samples[VAR_4] > VAR_0->samples_per_frame) { av_log(VAR_0->avctx, AV_LOG_ERROR, "broken frame: "
"channel len(%d) > samples_per_frame(%d)\n",
num_samples[VAR_4], VAR_0->samples_per_frame); return AVERROR_INVALIDDATA; } } else if (num_samples[VAR_4] <= VAR_3) { if (num_samples[VAR_4] < VAR_3) { VAR_1 = 0; VAR_3 = num_samples[VAR_4]; } ++VAR_1; } } } while (VAR_3 < VAR_0->samples_per_frame); for (VAR_4 = 0; VAR_4 < VAR_0->num_channels; VAR_4++) { int i, offset = 0; for (i = 0; i < VAR_0->channel[VAR_4].num_subframes; i++) { VAR_0->channel[VAR_4].subframe_offsets[i] = offset; offset += VAR_0->channel[VAR_4].VAR_6[i]; } } return 0; }