static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_table, int64_t edit_unit, int64_t *edit_unit_out, int64_t *offset_out, int nag)

{

    int i;

    int offset_temp = 0;



    for (i = 0; i < index_table->nb_segments; i++) {

        MXFIndexTableSegment *s = index_table->segments[i];



        edit_unit = FFMAX(edit_unit, s->index_start_position);  /* clamp if trying to seek before start */



        if (edit_unit < s->index_start_position + s->index_duration) {

            int64_t index = edit_unit - s->index_start_position;



            if (s->edit_unit_byte_count)

                offset_temp += s->edit_unit_byte_count * index;

            else if (s->nb_index_entries) {

                if (s->nb_index_entries == 2 * s->index_duration + 1)

                    index *= 2;     /* Avid index */



                if (index < 0 || index > s->nb_index_entries) {

                    av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" IndexEntryArray too small\n",

                           index_table->index_sid, s->index_start_position);

                    return AVERROR_INVALIDDATA;

                }



                offset_temp = s->stream_offset_entries[index];

            } else {

                av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" missing EditUnitByteCount and IndexEntryArray\n",

                       index_table->index_sid, s->index_start_position);

                return AVERROR_INVALIDDATA;

            }



            if (edit_unit_out)

                *edit_unit_out = edit_unit;



            return mxf_absolute_bodysid_offset(mxf, index_table->body_sid, offset_temp, offset_out);

        } else {

            /* EditUnitByteCount == 0 for VBR indexes, which is fine since they use explicit StreamOffsets */

            offset_temp += s->edit_unit_byte_count * s->index_duration;

        }

    }



    if (nag)

        av_log(mxf->fc, AV_LOG_ERROR, "failed to map EditUnit %"PRId64" in IndexSID %i to an offset\n", edit_unit, index_table->index_sid);



    return AVERROR_INVALIDDATA;

}

static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_table, int64_t edit_unit, int64_t *edit_unit_out, int64_t *offset_out, int nag)

{

    int i;

    int offset_temp = 0;



    for (i = 0; i < index_table->nb_segments; i++) {

        MXFIndexTableSegment *s = index_table->segments[i];



        edit_unit = FFMAX(edit_unit, s->index_start_position);  



        if (edit_unit < s->index_start_position + s->index_duration) {

            int64_t index = edit_unit - s->index_start_position;



            if (s->edit_unit_byte_count)

                offset_temp += s->edit_unit_byte_count * index;

            else if (s->nb_index_entries) {

                if (s->nb_index_entries == 2 * s->index_duration + 1)

                    index *= 2;     



                if (index < 0 || index > s->nb_index_entries) {

                    av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" IndexEntryArray too small\n",

                           index_table->index_sid, s->index_start_position);

                    return AVERROR_INVALIDDATA;

                }



                offset_temp = s->stream_offset_entries[index];

            } else {

                av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" missing EditUnitByteCount and IndexEntryArray\n",

                       index_table->index_sid, s->index_start_position);

                return AVERROR_INVALIDDATA;

            }



            if (edit_unit_out)

                *edit_unit_out = edit_unit;



            return mxf_absolute_bodysid_offset(mxf, index_table->body_sid, offset_temp, offset_out);

        } else {

            

            offset_temp += s->edit_unit_byte_count * s->index_duration;

        }

    }



    if (nag)

        av_log(mxf->fc, AV_LOG_ERROR, "failed to map EditUnit %"PRId64" in IndexSID %i to an offset\n", edit_unit, index_table->index_sid);



    return AVERROR_INVALIDDATA;

}

    int offset_temp = 0;
static int FUNC_0(MXFContext *VAR_0, MXFIndexTable *VAR_1, int64_t VAR_2, int64_t *VAR_3, int64_t *VAR_4, int VAR_5)

{

    int VAR_6;

    int VAR_7 = 0;



    for (VAR_6 = 0; VAR_6 < VAR_1->nb_segments; VAR_6++) {

        MXFIndexTableSegment *s = VAR_1->segments[VAR_6];



        VAR_2 = FFMAX(VAR_2, s->index_start_position);  



        if (VAR_2 < s->index_start_position + s->index_duration) {

            int64_t index = VAR_2 - s->index_start_position;



            if (s->edit_unit_byte_count)

                VAR_7 += s->edit_unit_byte_count * index;

            else if (s->nb_index_entries) {

                if (s->nb_index_entries == 2 * s->index_duration + 1)

                    index *= 2;     



                if (index < 0 || index > s->nb_index_entries) {

                    av_log(VAR_0->fc, AV_LOG_ERROR, "IndexSID %VAR_6 segment at %"PRId64" IndexEntryArray too small\n",

                           VAR_1->index_sid, s->index_start_position);

                    return AVERROR_INVALIDDATA;

                }



                VAR_7 = s->stream_offset_entries[index];

            } else {

                av_log(VAR_0->fc, AV_LOG_ERROR, "IndexSID %VAR_6 segment at %"PRId64" missing EditUnitByteCount and IndexEntryArray\n",

                       VAR_1->index_sid, s->index_start_position);

                return AVERROR_INVALIDDATA;

            }



            if (VAR_3)

                *VAR_3 = VAR_2;



            return mxf_absolute_bodysid_offset(VAR_0, VAR_1->body_sid, VAR_7, VAR_4);

        } else {

            

            VAR_7 += s->edit_unit_byte_count * s->index_duration;

        }

    }



    if (VAR_5)

        av_log(VAR_0->fc, AV_LOG_ERROR, "failed to map EditUnit %"PRId64" in IndexSID %VAR_6 to an offset\n", VAR_2, VAR_1->index_sid);



    return AVERROR_INVALIDDATA;

}

static int FUNC_0(MXFContext *VAR_0, MXFIndexTable *VAR_1, int64_t VAR_2, int64_t *VAR_3, int64_t *VAR_4, int VAR_5)
{ int VAR_6; int VAR_7 = 0; for (VAR_6 = 0; VAR_6 < VAR_1->nb_segments; VAR_6++) { MXFIndexTableSegment *s = VAR_1->segments[VAR_6]; VAR_2 = FFMAX(VAR_2, s->index_start_position); if (VAR_2 < s->index_start_position + s->index_duration) { int64_t index = VAR_2 - s->index_start_position; if (s->edit_unit_byte_count)
VAR_7 += s->edit_unit_byte_count * index; else if (s->nb_index_entries) { if (s->nb_index_entries == 2 * s->index_duration + 1)
index *= 2; if (index < 0 || index > s->nb_index_entries) { av_log(VAR_0->fc, AV_LOG_ERROR, "IndexSID %VAR_6 segment at %"PRId64" IndexEntryArray too small\n",
VAR_1->index_sid, s->index_start_position); return AVERROR_INVALIDDATA; } VAR_7 = s->stream_offset_entries[index]; } else { av_log(VAR_0->fc, AV_LOG_ERROR, "IndexSID %VAR_6 segment at %"PRId64" missing EditUnitByteCount and IndexEntryArray\n",
VAR_1->index_sid, s->index_start_position); return AVERROR_INVALIDDATA; } if (VAR_3)
*VAR_3 = VAR_2; return mxf_absolute_bodysid_offset(VAR_0, VAR_1->body_sid, VAR_7, VAR_4); } else { VAR_7 += s->edit_unit_byte_count * s->index_duration; } } if (VAR_5)
av_log(VAR_0->fc, AV_LOG_ERROR, "failed to map EditUnit %"PRId64" in IndexSID %VAR_6 to an offset\n", VAR_2, VAR_1->index_sid); return AVERROR_INVALIDDATA; }