static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf,

                              int buf_size)

{

    int start_found, i;

    uint32_t state;

    ParseContext *pc = &pc1->pc;



    start_found = pc->frame_start_found;

    state       = pc->state;



    i = 0;

    if (!start_found) {

        for (i = 0; i < buf_size; i++) {

            state = (state << 8) | buf[i];

            if (IS_MARKER(state, i, buf, buf_size)) {

                if (!pc1->lastmarker || state == pc1->lastmarker || pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM) {

                    start_found     = 1;

                    pc1->lastmarker = state;

                    i++;

                    break;

                }

            }

        }

    }

    if (start_found) {

        for (; i < buf_size; i++) {

            pc1->size++;

            state = (state << 8) | buf[i];

            if (state == DCA_SYNCWORD_SUBSTREAM && !pc1->hd_pos)

                pc1->hd_pos = pc1->size;

            if (IS_MARKER(state, i, buf, buf_size) && (state == pc1->lastmarker || pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {

                if (pc1->framesize > pc1->size)

                    continue;

                pc->frame_start_found = 0;

                pc->state             = -1;

                pc1->size             = 0;

                return i - 3;

            }

        }

    }

    pc->frame_start_found = start_found;

    pc->state             = state;

    return END_NOT_FOUND;

}

static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf,

                              int buf_size)

{

    int start_found, i;

    uint32_t state;

    ParseContext *pc = &pc1->pc;



    start_found = pc->frame_start_found;

    state       = pc->state;



    i = 0;

    if (!start_found) {

        for (i = 0; i < buf_size; i++) {

            state = (state << 8) | buf[i];

            if (IS_MARKER(state, i, buf, buf_size)) {

                if (!pc1->lastmarker || state == pc1->lastmarker || pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM) {

                    start_found     = 1;

                    pc1->lastmarker = state;

                    i++;

                    break;

                }

            }

        }

    }

    if (start_found) {

        for (; i < buf_size; i++) {

            pc1->size++;

            state = (state << 8) | buf[i];

            if (state == DCA_SYNCWORD_SUBSTREAM && !pc1->hd_pos)

                pc1->hd_pos = pc1->size;

            if (IS_MARKER(state, i, buf, buf_size) && (state == pc1->lastmarker || pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {

                if (pc1->framesize > pc1->size)

                    continue;

                pc->frame_start_found = 0;

                pc->state             = -1;

                pc1->size             = 0;

                return i - 3;

            }

        }

    }

    pc->frame_start_found = start_found;

    pc->state             = state;

    return END_NOT_FOUND;

}

static int FUNC_0(DCAParseContext *VAR_0, const uint8_t *VAR_1,

                              int VAR_2)

{

    int VAR_3, VAR_4;

    uint32_t state;

    ParseContext *pc = &VAR_0->pc;



    VAR_3 = pc->frame_start_found;

    state       = pc->state;



    VAR_4 = 0;

    if (!VAR_3) {

        for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

            state = (state << 8) | VAR_1[VAR_4];

            if (IS_MARKER(state, VAR_4, VAR_1, VAR_2)) {

                if (!VAR_0->lastmarker || state == VAR_0->lastmarker || VAR_0->lastmarker == DCA_SYNCWORD_SUBSTREAM) {

                    VAR_3     = 1;

                    VAR_0->lastmarker = state;

                    VAR_4++;

                    break;

                }

            }

        }

    }

    if (VAR_3) {

        for (; VAR_4 < VAR_2; VAR_4++) {

            VAR_0->size++;

            state = (state << 8) | VAR_1[VAR_4];

            if (state == DCA_SYNCWORD_SUBSTREAM && !VAR_0->hd_pos)

                VAR_0->hd_pos = VAR_0->size;

            if (IS_MARKER(state, VAR_4, VAR_1, VAR_2) && (state == VAR_0->lastmarker || VAR_0->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {

                if (VAR_0->framesize > VAR_0->size)

                    continue;

                pc->frame_start_found = 0;

                pc->state             = -1;

                VAR_0->size             = 0;

                return VAR_4 - 3;

            }

        }

    }

    pc->frame_start_found = VAR_3;

    pc->state             = state;

    return END_NOT_FOUND;

}

static int FUNC_0(DCAParseContext *VAR_0, const uint8_t *VAR_1,
int VAR_2)
{ int VAR_3, VAR_4; uint32_t state; ParseContext *pc = &VAR_0->pc; VAR_3 = pc->frame_start_found; state       = pc->state; VAR_4 = 0; if (!VAR_3) { for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { state = (state << 8) | VAR_1[VAR_4]; if (IS_MARKER(state, VAR_4, VAR_1, VAR_2)) { if (!VAR_0->lastmarker || state == VAR_0->lastmarker || VAR_0->lastmarker == DCA_SYNCWORD_SUBSTREAM) { VAR_3     = 1; VAR_0->lastmarker = state; VAR_4++; break; } } } } if (VAR_3) { for (; VAR_4 < VAR_2; VAR_4++) { VAR_0->size++; state = (state << 8) | VAR_1[VAR_4]; if (state == DCA_SYNCWORD_SUBSTREAM && !VAR_0->hd_pos)
VAR_0->hd_pos = VAR_0->size; if (IS_MARKER(state, VAR_4, VAR_1, VAR_2) && (state == VAR_0->lastmarker || VAR_0->lastmarker == DCA_SYNCWORD_SUBSTREAM)) { if (VAR_0->framesize > VAR_0->size)
continue; pc->frame_start_found = 0; pc->state             = -1; VAR_0->size             = 0; return VAR_4 - 3; } } } pc->frame_start_found = VAR_3; pc->state             = state; return END_NOT_FOUND; }