static int save_avio_options(AVFormatContext *s)
{
    HLSContext *c = s->priv_data;
    const char *opts[] = { "headers", "user_agent", NULL }, **opt = opts;
    uint8_t *buf;
    int ret = 0;
    while (*opt) {
        if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
            ret = av_dict_set(&c->avio_opts, *opt, buf,
                              AV_DICT_DONT_STRDUP_VAL);
            if (ret < 0)
                return ret;
        }
        opt++;
    }
    return ret;
}
['static int save_avio_options(AVFormatContext *s)\n{\n    HLSContext *c = s->priv_data;\n    const char *opts[] = { "headers", "user_agent", NULL }, **opt = opts;\n    uint8_t *buf;\n    int ret = 0;\n    while (*opt) {\n        if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {\n            ret = av_dict_set(&c->avio_opts, *opt, buf,\n                              AV_DICT_DONT_STRDUP_VAL);\n            if (ret < 0)\n                return ret;\n        }\n        opt++;\n    }\n    return ret;\n}', 'int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)\n{\n    void *dst, *target_obj;\n    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);\n    uint8_t *bin, buf[128];\n    int len, i, ret;\n    if (!o || !target_obj)\n        return AVERROR_OPTION_NOT_FOUND;\n    dst = (uint8_t*)target_obj + o->offset;\n    buf[0] = 0;\n    switch (o->type) {\n    case AV_OPT_TYPE_FLAGS:     ret = snprintf(buf, sizeof(buf), "0x%08X",  *(int    *)dst);break;\n    case AV_OPT_TYPE_INT:       ret = snprintf(buf, sizeof(buf), "%d" ,     *(int    *)dst);break;\n    case AV_OPT_TYPE_INT64:     ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;\n    case AV_OPT_TYPE_FLOAT:     ret = snprintf(buf, sizeof(buf), "%f" ,     *(float  *)dst);break;\n    case AV_OPT_TYPE_DOUBLE:    ret = snprintf(buf, sizeof(buf), "%f" ,     *(double *)dst);break;\n    case AV_OPT_TYPE_RATIONAL:  ret = snprintf(buf, sizeof(buf), "%d/%d",   ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;\n    case AV_OPT_TYPE_STRING:\n        if (*(uint8_t**)dst)\n            *out_val = av_strdup(*(uint8_t**)dst);\n        else\n            *out_val = av_strdup("");\n        return *out_val ? 0 : AVERROR(ENOMEM);\n    case AV_OPT_TYPE_BINARY:\n        len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));\n        if ((uint64_t)len*2 + 1 > INT_MAX)\n            return AVERROR(EINVAL);\n        if (!(*out_val = av_malloc(len*2 + 1)))\n            return AVERROR(ENOMEM);\n        bin = *(uint8_t**)dst;\n        for (i = 0; i < len; i++)\n            snprintf(*out_val + i*2, 3, "%02X", bin[i]);\n        return 0;\n    default:\n        return AVERROR(EINVAL);\n    }\n    if (ret >= sizeof(buf))\n        return AVERROR(EINVAL);\n    *out_val = av_strdup(buf);\n    return *out_val ? 0 : AVERROR(ENOMEM);\n}', 'char *av_strdup(const char *s)\n{\n    char *ptr = NULL;\n    if (s) {\n        int len = strlen(s) + 1;\n        ptr = av_realloc(NULL, len);\n        if (ptr)\n            memcpy(ptr, s, len);\n    }\n    return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if (size > (INT_MAX - 16))\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    if (!ptr)\n        return av_malloc(size);\n    diff = ((char *)ptr)[-1];\n    return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n    return _aligned_realloc(ptr, size, 32);\n#else\n    return realloc(ptr, size);\n#endif\n}', 'int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n                int flags)\n{\n    AVDictionary *m = *pm;\n    AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n    char *oldval = NULL;\n    int allocated = !!m;\n    if (!m)\n        m = *pm = av_mallocz(sizeof(*m));\n    if (!m)\n        return AVERROR(ENOMEM);\n    if (tag) {\n        if (flags & AV_DICT_DONT_OVERWRITE) {\n            if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);\n            if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);\n            return 0;\n        }\n        if (flags & AV_DICT_APPEND)\n            oldval = tag->value;\n        else\n            av_free(tag->value);\n        av_free(tag->key);\n        *tag = m->elems[--m->count];\n    } else {\n        int ret = av_reallocp_array(&m->elems,\n                                    m->count + 1, sizeof(*m->elems));\n        if (ret < 0) {\n            if (allocated)\n                av_freep(pm);\n            return ret;\n        }\n    }\n    if (value) {\n        if (flags & AV_DICT_DONT_STRDUP_KEY)\n            m->elems[m->count].key = key;\n        else\n            m->elems[m->count].key = av_strdup(key);\n        if (flags & AV_DICT_DONT_STRDUP_VAL) {\n            m->elems[m->count].value = value;\n        } else if (oldval && flags & AV_DICT_APPEND) {\n            int len = strlen(oldval) + strlen(value) + 1;\n            if (!(oldval = av_realloc(oldval, len)))\n                return AVERROR(ENOMEM);\n            av_strlcat(oldval, value, len);\n            m->elems[m->count].value = oldval;\n        } else\n            m->elems[m->count].value = av_strdup(value);\n        m->count++;\n    }\n    if (!m->count) {\n        av_free(m->elems);\n        av_freep(pm);\n    }\n    return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n    void *val;\n    if (!size || nmemb >= INT_MAX / size)\n        return AVERROR(ENOMEM);\n    if (!nmemb) {\n        av_freep(ptr);\n        return 0;\n    }\n    memcpy(&val, ptr, sizeof(val));\n    val = av_realloc(val, nmemb * size);\n    if (!val) {\n        av_freep(ptr);\n        return AVERROR(ENOMEM);\n    }\n    memcpy(ptr, &val, sizeof(val));\n    return 0;\n}']