static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, mkv_track *tracks, int num_tracks)

{

    ebml_master cues_element;

    int64_t currentpos;

    int i, j;



    currentpos = avio_tell(pb);

    cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0);



    for (i = 0; i < cues->num_entries; i++) {

        ebml_master cuepoint, track_positions;

        mkv_cuepoint *entry = &cues->entries[i];

        uint64_t pts = entry->pts;



        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks));

        put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);



        // put all the entries from different tracks that have the exact same

        // timestamp into the same CuePoint

        for (j = 0; j < num_tracks; j++)

            tracks[j].has_cue = 0;

        for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {

            if (tracks[entry[j].tracknum].has_cue)

                continue;

            tracks[entry[j].tracknum].has_cue = 1;

            track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);

            put_ebml_uint(pb, MATROSKA_ID_CUETRACK          , entry[j].tracknum   );

            put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION, entry[j].cluster_pos);

            end_ebml_master(pb, track_positions);

        }

        i += j - 1;

        end_ebml_master(pb, cuepoint);

    }

    end_ebml_master(pb, cues_element);



    return currentpos;

}

static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, mkv_track *tracks, int num_tracks)

{

    ebml_master cues_element;

    int64_t currentpos;

    int i, j;



    currentpos = avio_tell(pb);

    cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0);



    for (i = 0; i < cues->num_entries; i++) {

        ebml_master cuepoint, track_positions;

        mkv_cuepoint *entry = &cues->entries[i];

        uint64_t pts = entry->pts;



        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks));

        put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);



        

        

        for (j = 0; j < num_tracks; j++)

            tracks[j].has_cue = 0;

        for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {

            if (tracks[entry[j].tracknum].has_cue)

                continue;

            tracks[entry[j].tracknum].has_cue = 1;

            track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);

            put_ebml_uint(pb, MATROSKA_ID_CUETRACK          , entry[j].tracknum   );

            put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION, entry[j].cluster_pos);

            end_ebml_master(pb, track_positions);

        }

        i += j - 1;

        end_ebml_master(pb, cuepoint);

    }

    end_ebml_master(pb, cues_element);



    return currentpos;

}

static int64_t FUNC_0(AVIOContext *pb, mkv_cues *cues, mkv_track *tracks, int num_tracks)

{

    ebml_master cues_element;

    int64_t currentpos;

    int VAR_0, VAR_1;



    currentpos = avio_tell(pb);

    cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0);



    for (VAR_0 = 0; VAR_0 < cues->num_entries; VAR_0++) {

        ebml_master cuepoint, track_positions;

        mkv_cuepoint *entry = &cues->entries[VAR_0];

        uint64_t pts = entry->pts;



        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks));

        put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);



        

        

        for (VAR_1 = 0; VAR_1 < num_tracks; VAR_1++)

            tracks[VAR_1].has_cue = 0;

        for (VAR_1 = 0; VAR_1 < cues->num_entries - VAR_0 && entry[VAR_1].pts == pts; VAR_1++) {

            if (tracks[entry[VAR_1].tracknum].has_cue)

                continue;

            tracks[entry[VAR_1].tracknum].has_cue = 1;

            track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);

            put_ebml_uint(pb, MATROSKA_ID_CUETRACK          , entry[VAR_1].tracknum   );

            put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION, entry[VAR_1].cluster_pos);

            end_ebml_master(pb, track_positions);

        }

        VAR_0 += VAR_1 - 1;

        end_ebml_master(pb, cuepoint);

    }

    end_ebml_master(pb, cues_element);



    return currentpos;

}

static int64_t FUNC_0(AVIOContext *pb, mkv_cues *cues, mkv_track *tracks, int num_tracks)
{ ebml_master cues_element; int64_t currentpos; int VAR_0, VAR_1; currentpos = avio_tell(pb); cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0); for (VAR_0 = 0; VAR_0 < cues->num_entries; VAR_0++) { ebml_master cuepoint, track_positions; mkv_cuepoint *entry = &cues->entries[VAR_0]; uint64_t pts = entry->pts; cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks)); put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts); for (VAR_1 = 0; VAR_1 < num_tracks; VAR_1++) tracks[VAR_1].has_cue = 0; for (VAR_1 = 0; VAR_1 < cues->num_entries - VAR_0 && entry[VAR_1].pts == pts; VAR_1++) { if (tracks[entry[VAR_1].tracknum].has_cue)
continue; tracks[entry[VAR_1].tracknum].has_cue = 1; track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE); put_ebml_uint(pb, MATROSKA_ID_CUETRACK          , entry[VAR_1].tracknum   ); put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION, entry[VAR_1].cluster_pos); end_ebml_master(pb, track_positions); } VAR_0 += VAR_1 - 1; end_ebml_master(pb, cuepoint); } end_ebml_master(pb, cues_element); return currentpos; }