static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) {

    int num_pos_channels = 0;

    int first_cpe = 0;

    int sce_parity = 0;

    int i;

    for (i = *current; i < tags; i++) {

        if (layout_map[i][2] != pos)

            break;

        if (layout_map[i][0] == TYPE_CPE) {

            if (sce_parity) {

                if (pos == AAC_CHANNEL_FRONT || !first_cpe) {

                    sce_parity = 0;

                } else {

                    return -1;

                }

            }

            num_pos_channels += 2;

            first_cpe = 1;

        } else {

            num_pos_channels++;

            sce_parity ^= 1;

        }

    }

    if (sce_parity &&

        ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE))

            return -1;

    *current = i;

    return num_pos_channels;

}

static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) {

    int num_pos_channels = 0;

    int first_cpe = 0;

    int sce_parity = 0;

    int i;

    for (i = *current; i < tags; i++) {

        if (layout_map[i][2] != pos)

            break;

        if (layout_map[i][0] == TYPE_CPE) {

            if (sce_parity) {

                if (pos == AAC_CHANNEL_FRONT || !first_cpe) {

                    sce_parity = 0;

                } else {

                    return -1;

                }

            }

            num_pos_channels += 2;

            first_cpe = 1;

        } else {

            num_pos_channels++;

            sce_parity ^= 1;

        }

    }

    if (sce_parity &&

        ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE))

            return -1;

    *current = i;

    return num_pos_channels;

}

static int FUNC_0(VAR_0 (*layout_map)[3], int VAR_1, int VAR_2, int *VAR_3) {

    int VAR_4 = 0;

    int VAR_5 = 0;

    int VAR_6 = 0;

    int VAR_7;

    for (VAR_7 = *VAR_3; VAR_7 < VAR_1; VAR_7++) {

        if (layout_map[VAR_7][2] != VAR_2)

            break;

        if (layout_map[VAR_7][0] == TYPE_CPE) {

            if (VAR_6) {

                if (VAR_2 == AAC_CHANNEL_FRONT || !VAR_5) {

                    VAR_6 = 0;

                } else {

                    return -1;

                }

            }

            VAR_4 += 2;

            VAR_5 = 1;

        } else {

            VAR_4++;

            VAR_6 ^= 1;

        }

    }

    if (VAR_6 &&

        ((VAR_2 == AAC_CHANNEL_FRONT && VAR_5) || VAR_2 == AAC_CHANNEL_SIDE))

            return -1;

    *VAR_3 = VAR_7;

    return VAR_4;

}

static int FUNC_0(VAR_0 (*layout_map)[3], int VAR_1, int VAR_2, int *VAR_3) { int VAR_4 = 0; int VAR_5 = 0; int VAR_6 = 0; int VAR_7; for (VAR_7 = *VAR_3; VAR_7 < VAR_1; VAR_7++) { if (layout_map[VAR_7][2] != VAR_2)
break; if (layout_map[VAR_7][0] == TYPE_CPE) { if (VAR_6) { if (VAR_2 == AAC_CHANNEL_FRONT || !VAR_5) { VAR_6 = 0; } else { return -1; } } VAR_4 += 2; VAR_5 = 1; } else { VAR_4++; VAR_6 ^= 1; } } if (VAR_6 &&
((VAR_2 == AAC_CHANNEL_FRONT && VAR_5) || VAR_2 == AAC_CHANNEL_SIDE))
return -1; *VAR_3 = VAR_7; return VAR_4; }