static int fourxm_read_header(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    unsigned int fourcc_tag;
    unsigned int size;
    int header_size;
    FourxmDemuxContext *fourxm = s->priv_data;
    unsigned char *header;
    int i, ret;
    fourxm->track_count = 0;
    fourxm->tracks      = NULL;
    fourxm->fps         = 1.0;
    avio_skip(pb, 12);
    GET_LIST_HEADER();
    header_size = size - 4;
    if (fourcc_tag != HEAD_TAG || header_size < 0)
        return AVERROR_INVALIDDATA;
    header = av_malloc(header_size);
    if (!header)
        return AVERROR(ENOMEM);
    if (avio_read(pb, header, header_size) != header_size) {
        av_free(header);
        return AVERROR(EIO);
    }
    for (i = 0; i < header_size - 8; i++) {
        fourcc_tag = AV_RL32(&header[i]);
        size       = AV_RL32(&header[i + 4]);
        if (fourcc_tag == std__TAG) {
            if (header_size - i < 16) {
                ret = AVERROR_INVALIDDATA;
                goto fail;
            }
            fourxm->fps = av_int2float(AV_RL32(&header[i + 12]));
        } else if (fourcc_tag == vtrk_TAG) {
            if ((ret = parse_vtrk(s, fourxm, header + i, size,
                                  header_size - i)) < 0)
                goto fail;
            i += 8 + size;
        } else if (fourcc_tag == strk_TAG) {
            if ((ret = parse_strk(s, fourxm, header + i, size,
                                  header_size - i)) < 0)
                goto fail;
            i += 8 + size;
        }
    }
    GET_LIST_HEADER();
    if (fourcc_tag != MOVI_TAG) {
        ret = AVERROR_INVALIDDATA;
        goto fail;
    }
    av_free(header);
    fourxm->video_pts = -1;
    return 0;
fail:
    av_freep(&fourxm->tracks);
    av_free(header);
    return ret;
}
['static int fourxm_read_header(AVFormatContext *s)\n{\n    AVIOContext *pb = s->pb;\n    unsigned int fourcc_tag;\n    unsigned int size;\n    int header_size;\n    FourxmDemuxContext *fourxm = s->priv_data;\n    unsigned char *header;\n    int i, ret;\n    fourxm->track_count = 0;\n    fourxm->tracks      = NULL;\n    fourxm->fps         = 1.0;\n    avio_skip(pb, 12);\n    GET_LIST_HEADER();\n    header_size = size - 4;\n    if (fourcc_tag != HEAD_TAG || header_size < 0)\n        return AVERROR_INVALIDDATA;\n    header = av_malloc(header_size);\n    if (!header)\n        return AVERROR(ENOMEM);\n    if (avio_read(pb, header, header_size) != header_size) {\n        av_free(header);\n        return AVERROR(EIO);\n    }\n    for (i = 0; i < header_size - 8; i++) {\n        fourcc_tag = AV_RL32(&header[i]);\n        size       = AV_RL32(&header[i + 4]);\n        if (fourcc_tag == std__TAG) {\n            if (header_size - i < 16) {\n                ret = AVERROR_INVALIDDATA;\n                goto fail;\n            }\n            fourxm->fps = av_int2float(AV_RL32(&header[i + 12]));\n        } else if (fourcc_tag == vtrk_TAG) {\n            if ((ret = parse_vtrk(s, fourxm, header + i, size,\n                                  header_size - i)) < 0)\n                goto fail;\n            i += 8 + size;\n        } else if (fourcc_tag == strk_TAG) {\n            if ((ret = parse_strk(s, fourxm, header + i, size,\n                                  header_size - i)) < 0)\n                goto fail;\n            i += 8 + size;\n        }\n    }\n    GET_LIST_HEADER();\n    if (fourcc_tag != MOVI_TAG) {\n        ret = AVERROR_INVALIDDATA;\n        goto fail;\n    }\n    av_free(header);\n    fourxm->video_pts = -1;\n    return 0;\nfail:\n    av_freep(&fourxm->tracks);\n    av_free(header);\n    return ret;\n}', 'static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)\n{\n    return avio_seek(s, offset, SEEK_CUR);\n}', 'unsigned int avio_rl32(AVIOContext *s)\n{\n    unsigned int val;\n    val = avio_rl16(s);\n    val |= avio_rl16(s) << 16;\n    return val;\n}', 'unsigned int avio_rl16(AVIOContext *s)\n{\n    unsigned int val;\n    val = avio_r8(s);\n    val |= avio_r8(s) << 8;\n    return val;\n}', 'int avio_r8(AVIOContext *s)\n{\n    if (s->buf_ptr >= s->buf_end)\n        fill_buffer(s);\n    if (s->buf_ptr < s->buf_end)\n        return *s->buf_ptr++;\n    return 0;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if (size > (INT_MAX - 32) || !size)\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size + 32);\n    if (!ptr)\n        return ptr;\n    diff              = ((-(long)ptr - 1) & 31) + 1;\n    ptr               = (char *)ptr + diff;\n    ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr, 32, size))\n        ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n    ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n    ptr = memalign(32, size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'static int parse_strk(AVFormatContext *s,\n                      FourxmDemuxContext *fourxm, uint8_t *buf, int size,\n                      int left)\n{\n    AVStream *st;\n    int track;\n    if (size != strk_SIZE || left < size + 8)\n        return AVERROR_INVALIDDATA;\n    track = AV_RL32(buf + 8);\n    if (track < 0)\n        return AVERROR_INVALIDDATA;\n    if (track + 1 > fourxm->track_count) {\n        if (av_reallocp_array(&fourxm->tracks, track + 1, sizeof(AudioTrack)))\n            return AVERROR(ENOMEM);\n        memset(&fourxm->tracks[fourxm->track_count], 0,\n               sizeof(AudioTrack) * (track + 1 - fourxm->track_count));\n        fourxm->track_count = track + 1;\n    }\n    fourxm->tracks[track].adpcm       = AV_RL32(buf + 12);\n    fourxm->tracks[track].channels    = AV_RL32(buf + 36);\n    fourxm->tracks[track].sample_rate = AV_RL32(buf + 40);\n    fourxm->tracks[track].bits        = AV_RL32(buf + 44);\n    fourxm->tracks[track].audio_pts   = 0;\n    if (fourxm->tracks[track].channels    <= 0 ||\n        fourxm->tracks[track].sample_rate <= 0 ||\n        fourxm->tracks[track].bits        <= 0) {\n        av_log(s, AV_LOG_ERROR, "audio header invalid\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    st = avformat_new_stream(s, NULL);\n    if (!st)\n        return AVERROR(ENOMEM);\n    st->id = track;\n    avpriv_set_pts_info(st, 60, 1, fourxm->tracks[track].sample_rate);\n    fourxm->tracks[track].stream_index = st->index;\n    st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;\n    st->codecpar->codec_tag             = 0;\n    st->codecpar->channels              = fourxm->tracks[track].channels;\n    st->codecpar->sample_rate           = fourxm->tracks[track].sample_rate;\n    st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;\n    st->codecpar->bit_rate              = st->codecpar->channels *\n                                          st->codecpar->sample_rate *\n                                          st->codecpar->bits_per_coded_sample;\n    st->codecpar->block_align           = st->codecpar->channels *\n                                          st->codecpar->bits_per_coded_sample;\n    if (fourxm->tracks[track].adpcm){\n        st->codecpar->codec_id = AV_CODEC_ID_ADPCM_4XM;\n    } else if (st->codecpar->bits_per_coded_sample == 8) {\n        st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;\n    } else\n        st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;\n    return 0;\n}']