static int alac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
                             int buf_size, void *data)
{
    AlacEncodeContext *s = avctx->priv_data;
    PutBitContext *pb = &s->pbctx;
    int i, out_bytes, verbatim_flag = 0;
    if (buf_size < 2 * s->max_coded_frame_size) {
        av_log(avctx, AV_LOG_ERROR, "buffer size is too small\n");
        return -1;
    }
verbatim:
    init_put_bits(pb, frame, buf_size);
    if (s->compression_level == 0 || verbatim_flag) {
        const int16_t *samples = data;
        write_frame_header(s, 1);
        for (i = 0; i < avctx->frame_size * avctx->channels; i++) {
            put_sbits(pb, 16, *samples++);
        }
    } else {
        init_sample_buffers(s, data);
        write_frame_header(s, 0);
        write_compressed_frame(s);
    }
    put_bits(pb, 3, 7);
    flush_put_bits(pb);
    out_bytes = put_bits_count(pb) >> 3;
    if (out_bytes > s->max_coded_frame_size) {
        if (verbatim_flag || s->compression_level == 0) {
            av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
            return -1;
        }
        verbatim_flag = 1;
        goto verbatim;
    }
    return out_bytes;
}
['static int alac_encode_frame(AVCodecContext *avctx, uint8_t *frame,\n                             int buf_size, void *data)\n{\n    AlacEncodeContext *s = avctx->priv_data;\n    PutBitContext *pb = &s->pbctx;\n    int i, out_bytes, verbatim_flag = 0;\n    if (buf_size < 2 * s->max_coded_frame_size) {\n        av_log(avctx, AV_LOG_ERROR, "buffer size is too small\\n");\n        return -1;\n    }\nverbatim:\n    init_put_bits(pb, frame, buf_size);\n    if (s->compression_level == 0 || verbatim_flag) {\n        const int16_t *samples = data;\n        write_frame_header(s, 1);\n        for (i = 0; i < avctx->frame_size * avctx->channels; i++) {\n            put_sbits(pb, 16, *samples++);\n        }\n    } else {\n        init_sample_buffers(s, data);\n        write_frame_header(s, 0);\n        write_compressed_frame(s);\n    }\n    put_bits(pb, 3, 7);\n    flush_put_bits(pb);\n    out_bytes = put_bits_count(pb) >> 3;\n    if (out_bytes > s->max_coded_frame_size) {\n        if (verbatim_flag || s->compression_level == 0) {\n            av_log(avctx, AV_LOG_ERROR, "error encoding frame\\n");\n            return -1;\n        }\n        verbatim_flag = 1;\n        goto verbatim;\n    }\n    return out_bytes;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)\n{\n    if(buffer_size < 0) {\n        buffer_size = 0;\n        buffer = NULL;\n    }\n    s->size_in_bits= 8*buffer_size;\n    s->buf = buffer;\n    s->buf_end = s->buf + buffer_size;\n    s->buf_ptr = s->buf;\n    s->bit_left=32;\n    s->bit_buf=0;\n}', 'static void write_frame_header(AlacEncodeContext *s, int is_verbatim)\n{\n    put_bits(&s->pbctx, 3,  s->avctx->channels-1);\n    put_bits(&s->pbctx, 16, 0);\n    put_bits(&s->pbctx, 1,  1);\n    put_bits(&s->pbctx, 2,  0);\n    put_bits(&s->pbctx, 1,  is_verbatim);\n    put_bits32(&s->pbctx, s->avctx->frame_size);\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n{\n    unsigned int bit_buf;\n    int bit_left;\n    assert(n <= 31 && value < (1U << n));\n    bit_buf = s->bit_buf;\n    bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n    bit_buf |= value << (32 - bit_left);\n    if (n >= bit_left) {\n        AV_WL32(s->buf_ptr, bit_buf);\n        s->buf_ptr+=4;\n        bit_buf = (bit_left==32)?0:value >> bit_left;\n        bit_left+=32;\n    }\n    bit_left-=n;\n#else\n    if (n < bit_left) {\n        bit_buf = (bit_buf<<n) | value;\n        bit_left-=n;\n    } else {\n        bit_buf<<=bit_left;\n        bit_buf |= value >> (n - bit_left);\n        AV_WB32(s->buf_ptr, bit_buf);\n        s->buf_ptr+=4;\n        bit_left+=32 - n;\n        bit_buf = value;\n    }\n#endif\n    s->bit_buf = bit_buf;\n    s->bit_left = bit_left;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    return AV_BSWAP32C(x);\n}', 'static void av_unused put_bits32(PutBitContext *s, uint32_t value)\n{\n    int lo = value & 0xffff;\n    int hi = value >> 16;\n#ifdef BITSTREAM_WRITER_LE\n    put_bits(s, 16, lo);\n    put_bits(s, 16, hi);\n#else\n    put_bits(s, 16, hi);\n    put_bits(s, 16, lo);\n#endif\n}']