int ff_ape_write_tag(AVFormatContext *s)

{

    AVDictionaryEntry *e = NULL;

    int64_t start, end;

    int size, count = 0;



    if (!s->pb->seekable)

        return 0;



    start = avio_tell(s->pb);



    // header

    avio_write(s->pb, "APETAGEX", 8);   // id

    avio_wl32 (s->pb, APE_TAG_VERSION); // version

    avio_wl32(s->pb, 0);                // reserve space for size

    avio_wl32(s->pb, 0);                // reserve space for tag count



    // flags

    avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER |

                     APE_TAG_FLAG_IS_HEADER);

    ffio_fill(s->pb, 0, 8);             // reserved



    while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {

        int val_len = strlen(e->value);



        avio_wl32(s->pb, val_len);            // value length

        avio_wl32(s->pb, 0);                  // item flags

        avio_put_str(s->pb, e->key);          // key

        avio_write(s->pb, e->value, val_len); // value

        count++;

    }



    size = avio_tell(s->pb) - start;



    // footer

    avio_write(s->pb, "APETAGEX", 8);   // id

    avio_wl32 (s->pb, APE_TAG_VERSION); // version

    avio_wl32(s->pb, size);             // size

    avio_wl32(s->pb, count);            // tag count



    // flags

    avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER);

    ffio_fill(s->pb, 0, 8);             // reserved



    // update values in the header

    end = avio_tell(s->pb);

    avio_seek(s->pb, start + 12, SEEK_SET);

    avio_wl32(s->pb, size);

    avio_wl32(s->pb, count);

    avio_seek(s->pb, end, SEEK_SET);



    return 0;

}

int ff_ape_write_tag(AVFormatContext *s)

{

    AVDictionaryEntry *e = NULL;

    int64_t start, end;

    int size, count = 0;



    if (!s->pb->seekable)

        return 0;



    start = avio_tell(s->pb);



    

    avio_write(s->pb, "APETAGEX", 8);   

    avio_wl32 (s->pb, APE_TAG_VERSION); 

    avio_wl32(s->pb, 0);                

    avio_wl32(s->pb, 0);                



    

    avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER |

                     APE_TAG_FLAG_IS_HEADER);

    ffio_fill(s->pb, 0, 8);             



    while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {

        int val_len = strlen(e->value);



        avio_wl32(s->pb, val_len);            

        avio_wl32(s->pb, 0);                  

        avio_put_str(s->pb, e->key);          

        avio_write(s->pb, e->value, val_len); 

        count++;

    }



    size = avio_tell(s->pb) - start;



    

    avio_write(s->pb, "APETAGEX", 8);   

    avio_wl32 (s->pb, APE_TAG_VERSION); 

    avio_wl32(s->pb, size);             

    avio_wl32(s->pb, count);            



    

    avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER);

    ffio_fill(s->pb, 0, 8);             



    

    end = avio_tell(s->pb);

    avio_seek(s->pb, start + 12, SEEK_SET);

    avio_wl32(s->pb, size);

    avio_wl32(s->pb, count);

    avio_seek(s->pb, end, SEEK_SET);



    return 0;

}

int FUNC_0(AVFormatContext *VAR_0)

{

    AVDictionaryEntry *e = NULL;

    int64_t start, end;

    int VAR_1, VAR_2 = 0;



    if (!VAR_0->pb->seekable)

        return 0;



    start = avio_tell(VAR_0->pb);



    

    avio_write(VAR_0->pb, "APETAGEX", 8);   

    avio_wl32 (VAR_0->pb, APE_TAG_VERSION); 

    avio_wl32(VAR_0->pb, 0);                

    avio_wl32(VAR_0->pb, 0);                



    

    avio_wl32(VAR_0->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER |

                     APE_TAG_FLAG_IS_HEADER);

    ffio_fill(VAR_0->pb, 0, 8);             



    while ((e = av_dict_get(VAR_0->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {

        int VAR_3 = strlen(e->value);



        avio_wl32(VAR_0->pb, VAR_3);            

        avio_wl32(VAR_0->pb, 0);                  

        avio_put_str(VAR_0->pb, e->key);          

        avio_write(VAR_0->pb, e->value, VAR_3); 

        VAR_2++;

    }



    VAR_1 = avio_tell(VAR_0->pb) - start;



    

    avio_write(VAR_0->pb, "APETAGEX", 8);   

    avio_wl32 (VAR_0->pb, APE_TAG_VERSION); 

    avio_wl32(VAR_0->pb, VAR_1);             

    avio_wl32(VAR_0->pb, VAR_2);            



    

    avio_wl32(VAR_0->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER);

    ffio_fill(VAR_0->pb, 0, 8);             



    

    end = avio_tell(VAR_0->pb);

    avio_seek(VAR_0->pb, start + 12, SEEK_SET);

    avio_wl32(VAR_0->pb, VAR_1);

    avio_wl32(VAR_0->pb, VAR_2);

    avio_seek(VAR_0->pb, end, SEEK_SET);



    return 0;

}

int FUNC_0(AVFormatContext *VAR_0)
{ AVDictionaryEntry *e = NULL; int64_t start, end; int VAR_1, VAR_2 = 0; if (!VAR_0->pb->seekable)
return 0; start = avio_tell(VAR_0->pb); avio_write(VAR_0->pb, "APETAGEX", 8); avio_wl32 (VAR_0->pb, APE_TAG_VERSION); avio_wl32(VAR_0->pb, 0); avio_wl32(VAR_0->pb, 0); avio_wl32(VAR_0->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER |
APE_TAG_FLAG_IS_HEADER); ffio_fill(VAR_0->pb, 0, 8); while ((e = av_dict_get(VAR_0->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) { int VAR_3 = strlen(e->value); avio_wl32(VAR_0->pb, VAR_3); avio_wl32(VAR_0->pb, 0); avio_put_str(VAR_0->pb, e->key); avio_write(VAR_0->pb, e->value, VAR_3); VAR_2++; } VAR_1 = avio_tell(VAR_0->pb) - start; avio_write(VAR_0->pb, "APETAGEX", 8); avio_wl32 (VAR_0->pb, APE_TAG_VERSION); avio_wl32(VAR_0->pb, VAR_1); avio_wl32(VAR_0->pb, VAR_2); avio_wl32(VAR_0->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER); ffio_fill(VAR_0->pb, 0, 8); end = avio_tell(VAR_0->pb); avio_seek(VAR_0->pb, start + 12, SEEK_SET); avio_wl32(VAR_0->pb, VAR_1); avio_wl32(VAR_0->pb, VAR_2); avio_seek(VAR_0->pb, end, SEEK_SET); return 0; }