static inline void refill_32(BitstreamContext *bc)
{
    if (bc->ptr >= bc->buffer_end)
        return;
#ifdef BITSTREAM_READER_LE
    bc->bits       = (uint64_t)AV_RL32(bc->ptr) << bc->bits_left | bc->bits;
#else
    bc->bits       = bc->bits | (uint64_t)AV_RB32(bc->ptr) << (32 - bc->bits_left);
#endif
    bc->ptr       += 4;
    bc->bits_left += 32;
}
['static av_cold int mpc7_decode_init(AVCodecContext * avctx)\n{\n    int i, j;\n    MPCContext *c = avctx->priv_data;\n    BitstreamContext bc;\n    LOCAL_ALIGNED_16(uint8_t, buf, [16]);\n    static int vlc_initialized = 0;\n    static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2];\n    static VLC_TYPE dscf_table[1 << MPC7_DSCF_BITS][2];\n    static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2];\n    static VLC_TYPE quant_tables[7224][2];\n    if (avctx->channels != 2) {\n        avpriv_request_sample(avctx, "%d channels", avctx->channels);\n        return AVERROR_PATCHWELCOME;\n    }\n    if(avctx->extradata_size < 16){\n        av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\\n", avctx->extradata_size);\n        return -1;\n    }\n    memset(c->oldDSCF, 0, sizeof(c->oldDSCF));\n    av_lfg_init(&c->rnd, 0xDEADBEEF);\n    ff_bswapdsp_init(&c->bdsp);\n    ff_mpadsp_init(&c->mpadsp);\n    c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4);\n    ff_mpc_init();\n    bitstream_init(&bc, buf, 128);\n    c->IS       = bitstream_read_bit(&bc);\n    c->MSS      = bitstream_read_bit(&bc);\n    c->maxbands = bitstream_read(&bc, 6);\n    if(c->maxbands >= BANDS){\n        av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\\n", c->maxbands);\n        return -1;\n    }\n    bitstream_skip(&bc, 88);\n    c->gapless      = bitstream_read_bit(&bc);\n    c->lastframelen = bitstream_read(&bc, 11);\n    av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\\n",\n            c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);\n    c->frames_to_skip = 0;\n    avctx->sample_fmt = AV_SAMPLE_FMT_S16P;\n    avctx->channel_layout = AV_CH_LAYOUT_STEREO;\n    if(vlc_initialized) return 0;\n    av_log(avctx, AV_LOG_DEBUG, "Initing VLC\\n");\n    scfi_vlc.table = scfi_table;\n    scfi_vlc.table_allocated = 1 << MPC7_SCFI_BITS;\n    if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,\n                &mpc7_scfi[1], 2, 1,\n                &mpc7_scfi[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n        av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\\n");\n        return -1;\n    }\n    dscf_vlc.table = dscf_table;\n    dscf_vlc.table_allocated = 1 << MPC7_DSCF_BITS;\n    if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,\n                &mpc7_dscf[1], 2, 1,\n                &mpc7_dscf[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n        av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\\n");\n        return -1;\n    }\n    hdr_vlc.table = hdr_table;\n    hdr_vlc.table_allocated = 1 << MPC7_HDR_BITS;\n    if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,\n                &mpc7_hdr[1], 2, 1,\n                &mpc7_hdr[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n        av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\\n");\n        return -1;\n    }\n    for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){\n        for(j = 0; j < 2; j++){\n            quant_vlc[i][j].table = &quant_tables[quant_offsets[i*2 + j]];\n            quant_vlc[i][j].table_allocated = quant_offsets[i*2 + j + 1] - quant_offsets[i*2 + j];\n            if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],\n                        &mpc7_quant_vlc[i][j][1], 4, 2,\n                        &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_NEW_STATIC)){\n                av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\\n",i,j);\n                return -1;\n            }\n        }\n    }\n    vlc_initialized = 1;\n    return 0;\n}', 'static inline int bitstream_init(BitstreamContext *bc, const uint8_t *buffer,\n                                 unsigned bit_size)\n{\n    unsigned buffer_size;\n    if (bit_size > INT_MAX - 7 || !buffer) {\n        buffer        =\n        bc->buffer    =\n        bc->ptr       = NULL;\n        bc->bits_left = 0;\n        return AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    bc->buffer       = buffer;\n    bc->buffer_end   = buffer + buffer_size;\n    bc->ptr          = bc->buffer;\n    bc->size_in_bits = bit_size;\n    bc->bits_left    = 0;\n    bc->bits         = 0;\n    refill_64(bc);\n    return 0;\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n    if (!bc->bits_left)\n        refill_64(bc);\n    return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n    bc->bits >>= n;\n#else\n    uint64_t ret = bc->bits >> (64 - n);\n    bc->bits <<= n;\n#endif\n    bc->bits_left -= n;\n    return ret;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n    if (!n)\n        return 0;\n    if (n > bc->bits_left) {\n        refill_32(bc);\n        if (bc->bits_left < 32)\n            bc->bits_left = n;\n    }\n    return get_val(bc, n);\n}', 'static inline void refill_32(BitstreamContext *bc)\n{\n    if (bc->ptr >= bc->buffer_end)\n        return;\n#ifdef BITSTREAM_READER_LE\n    bc->bits       = (uint64_t)AV_RL32(bc->ptr) << bc->bits_left | bc->bits;\n#else\n    bc->bits       = bc->bits | (uint64_t)AV_RB32(bc->ptr) << (32 - bc->bits_left);\n#endif\n    bc->ptr       += 4;\n    bc->bits_left += 32;\n}']