static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
    bc->bits >>= n;
#else
    uint64_t ret = bc->bits >> (64 - n);
    bc->bits <<= n;
#endif
    bc->bits_left -= n;
    return ret;
}
['static int decode_subframe_lpc(ShortenContext *s, int command, int channel,\n                               int residual_size, int32_t coffset)\n{\n    int pred_order, sum, qshift, init_sum, i, j;\n    const int *coeffs;\n    if (command == FN_QLPC) {\n        pred_order = get_ur_golomb_shorten(&s->bc, LPCQSIZE);\n        if (pred_order > s->nwrap) {\n            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\\n",\n                   pred_order);\n            return AVERROR(EINVAL);\n        }\n        for (i = 0; i < pred_order; i++)\n            s->coeffs[i] = get_sr_golomb_shorten(&s->bc, LPCQUANT);\n        coeffs = s->coeffs;\n        qshift = LPCQUANT;\n    } else {\n        pred_order = command;\n        if (pred_order >= FF_ARRAY_ELEMS(fixed_coeffs)) {\n            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\\n",\n                   pred_order);\n            return AVERROR_INVALIDDATA;\n        }\n        coeffs     = fixed_coeffs[pred_order];\n        qshift     = 0;\n    }\n    if (command == FN_QLPC && coffset)\n        for (i = -pred_order; i < 0; i++)\n            s->decoded[channel][i] -= coffset;\n    init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;\n    for (i = 0; i < s->blocksize; i++) {\n        sum = init_sum;\n        for (j = 0; j < pred_order; j++)\n            sum += coeffs[j] * s->decoded[channel][i - j - 1];\n        s->decoded[channel][i] = get_sr_golomb_shorten(&s->bc, residual_size) +\n                                 (sum >> qshift);\n    }\n    if (command == FN_QLPC && coffset)\n        for (i = 0; i < s->blocksize; i++)\n            s->decoded[channel][i] += coffset;\n    return 0;\n}', 'static inline unsigned int get_ur_golomb_shorten(BitstreamContext *bc, int k)\n{\n    return get_ur_golomb_jpegls(bc, k, INT_MAX, 0);\n}', 'static inline int get_ur_golomb_jpegls(BitstreamContext *bc, int k, int limit,\n                                       int esc_len)\n{\n    unsigned int buf;\n    int log;\n    buf = bitstream_peek(bc, 32);\n    log = av_log2(buf);\n    if (log - k >= 1 && 32 - log < limit) {\n        buf >>= log - k;\n        buf  += (30 - log) << k;\n        bitstream_skip(bc, 32 + k - log);\n        return buf;\n    } else {\n        int i;\n        for (i = 0;\n             i < limit && bitstream_read_bit(bc) == 0 && bitstream_bits_left(bc) > 0;\n             i++);\n        if (i < limit - 1) {\n            buf = bitstream_read(bc, k);\n            return buf + (i << k);\n        } else if (i == limit - 1) {\n            buf = bitstream_read(bc, esc_len);\n            return buf + 1;\n        } else\n            return -1;\n    }\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 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}']