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_segment(BitstreamContext *bc, int mode, int32_t *decoded,\n                          int len)\n{\n    struct CParam code;\n    int i;\n    if (!mode) {\n        memset(decoded, 0, len * sizeof(*decoded));\n        return 0;\n    }\n    if (mode > FF_ARRAY_ELEMS(xcodes))\n        return AVERROR_INVALIDDATA;\n    code = xcodes[mode - 1];\n    for (i = 0; i < len; i++) {\n        int x = bitstream_read(bc, code.init);\n        if (x >= code.escape && bitstream_read_bit(bc)) {\n            x |= 1 << code.init;\n            if (x >= code.aescape) {\n                int scale = get_unary(bc, 1, 9);\n                if (scale == 9) {\n                    int scale_bits = bitstream_read(bc, 3);\n                    if (scale_bits > 0) {\n                        if (scale_bits == 7) {\n                            scale_bits += bitstream_read(bc, 5);\n                            if (scale_bits > 29)\n                                return AVERROR_INVALIDDATA;\n                        }\n                        scale = bitstream_read(bc, scale_bits) + 1;\n                        x    += code.scale * scale;\n                    }\n                    x += code.bias;\n                } else\n                    x += code.scale * scale - code.escape;\n            } else\n                x -= code.escape;\n        }\n        decoded[i] = (x >> 1) ^ -(x & 1);\n    }\n    return 0;\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 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}']