static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)

{

    const ASSSection *section = &ass_sections[ctx->current_section];

    int *number = &ctx->field_number[ctx->current_section];

    int *order = ctx->field_order[ctx->current_section];

    int *tmp, i, len;



    while (buf && *buf) {

        if (buf[0] == '[') {

            ctx->current_section = -1;

            break;

        }

        if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) {

            /* skip comments */

        } else if (section->format_header && !order) {

            len = strlen(section->format_header);

            if (strncmp(buf, section->format_header, len) || buf[len] != ':')

                return NULL;

            buf += len + 1;

            while (!is_eol(*buf)) {

                buf = skip_space(buf);

                len = strcspn(buf, ", \r\n");

                if (!(tmp = av_realloc(order, (*number + 1) * sizeof(*order))))

                    return NULL;

                order = tmp;

                order[*number] = -1;

                for (i=0; section->fields[i].name; i++)

                    if (!strncmp(buf, section->fields[i].name, len)) {

                        order[*number] = i;

                        break;

                    }

                (*number)++;

                buf = skip_space(buf + len + (buf[len] == ','));

            }

            ctx->field_order[ctx->current_section] = order;

        } else if (section->fields_header) {

            len = strlen(section->fields_header);

            if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') {

                uint8_t *ptr, *struct_ptr = realloc_section_array(ctx);

                if (!struct_ptr)  return NULL;

                buf += len + 1;

                for (i=0; !is_eol(*buf) && i < *number; i++) {

                    int last = i == *number - 1;

                    buf = skip_space(buf);

                    len = strcspn(buf, last ? "\r\n" : ",\r\n");

                    if (order[i] >= 0) {

                        ASSFieldType type = section->fields[order[i]].type;

                        ptr = struct_ptr + section->fields[order[i]].offset;

                        convert_func[type](ptr, buf, len);

                    }

                    buf = skip_space(buf + len + !last);

                }

            }

        } else {

            len = strcspn(buf, ":\r\n");

            if (buf[len] == ':') {

                for (i=0; section->fields[i].name; i++)

                    if (!strncmp(buf, section->fields[i].name, len)) {

                        ASSFieldType type = section->fields[i].type;

                        uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset;

                        ptr += section->fields[i].offset;

                        buf = skip_space(buf + len + 1);

                        convert_func[type](ptr, buf, strcspn(buf, "\r\n"));

                        break;

                    }

            }

        }

        buf += strcspn(buf, "\n");

        buf += !!*buf;

    }

    return buf;

}

static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)

{

    const ASSSection *section = &ass_sections[ctx->current_section];

    int *number = &ctx->field_number[ctx->current_section];

    int *order = ctx->field_order[ctx->current_section];

    int *tmp, i, len;



    while (buf && *buf) {

        if (buf[0] == '[') {

            ctx->current_section = -1;

            break;

        }

        if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) {

            

        } else if (section->format_header && !order) {

            len = strlen(section->format_header);

            if (strncmp(buf, section->format_header, len) || buf[len] != ':')

                return NULL;

            buf += len + 1;

            while (!is_eol(*buf)) {

                buf = skip_space(buf);

                len = strcspn(buf, ", \r\n");

                if (!(tmp = av_realloc(order, (*number + 1) * sizeof(*order))))

                    return NULL;

                order = tmp;

                order[*number] = -1;

                for (i=0; section->fields[i].name; i++)

                    if (!strncmp(buf, section->fields[i].name, len)) {

                        order[*number] = i;

                        break;

                    }

                (*number)++;

                buf = skip_space(buf + len + (buf[len] == ','));

            }

            ctx->field_order[ctx->current_section] = order;

        } else if (section->fields_header) {

            len = strlen(section->fields_header);

            if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') {

                uint8_t *ptr, *struct_ptr = realloc_section_array(ctx);

                if (!struct_ptr)  return NULL;

                buf += len + 1;

                for (i=0; !is_eol(*buf) && i < *number; i++) {

                    int last = i == *number - 1;

                    buf = skip_space(buf);

                    len = strcspn(buf, last ? "\r\n" : ",\r\n");

                    if (order[i] >= 0) {

                        ASSFieldType type = section->fields[order[i]].type;

                        ptr = struct_ptr + section->fields[order[i]].offset;

                        convert_func[type](ptr, buf, len);

                    }

                    buf = skip_space(buf + len + !last);

                }

            }

        } else {

            len = strcspn(buf, ":\r\n");

            if (buf[len] == ':') {

                for (i=0; section->fields[i].name; i++)

                    if (!strncmp(buf, section->fields[i].name, len)) {

                        ASSFieldType type = section->fields[i].type;

                        uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset;

                        ptr += section->fields[i].offset;

                        buf = skip_space(buf + len + 1);

                        convert_func[type](ptr, buf, strcspn(buf, "\r\n"));

                        break;

                    }

            }

        }

        buf += strcspn(buf, "\n");

        buf += !!*buf;

    }

    return buf;

}

static const char *FUNC_0(ASSSplitContext *VAR_0, const char *VAR_1)

{

    const ASSSection *VAR_2 = &ass_sections[VAR_0->current_section];

    int *VAR_3 = &VAR_0->field_number[VAR_0->current_section];

    int *VAR_4 = VAR_0->field_order[VAR_0->current_section];

    int *VAR_5, VAR_6, VAR_7;



    while (VAR_1 && *VAR_1) {

        if (VAR_1[0] == '[') {

            VAR_0->current_section = -1;

            break;

        }

        if (VAR_1[0] == ';' || (VAR_1[0] == '!' && VAR_1[1] == ':')) {

            

        } else if (VAR_2->format_header && !VAR_4) {

            VAR_7 = strlen(VAR_2->format_header);

            if (strncmp(VAR_1, VAR_2->format_header, VAR_7) || VAR_1[VAR_7] != ':')

                return NULL;

            VAR_1 += VAR_7 + 1;

            while (!is_eol(*VAR_1)) {

                VAR_1 = skip_space(VAR_1);

                VAR_7 = strcspn(VAR_1, ", \r\n");

                if (!(VAR_5 = av_realloc(VAR_4, (*VAR_3 + 1) * sizeof(*VAR_4))))

                    return NULL;

                VAR_4 = VAR_5;

                VAR_4[*VAR_3] = -1;

                for (VAR_6=0; VAR_2->fields[VAR_6].name; VAR_6++)

                    if (!strncmp(VAR_1, VAR_2->fields[VAR_6].name, VAR_7)) {

                        VAR_4[*VAR_3] = VAR_6;

                        break;

                    }

                (*VAR_3)++;

                VAR_1 = skip_space(VAR_1 + VAR_7 + (VAR_1[VAR_7] == ','));

            }

            VAR_0->field_order[VAR_0->current_section] = VAR_4;

        } else if (VAR_2->fields_header) {

            VAR_7 = strlen(VAR_2->fields_header);

            if (!strncmp(VAR_1, VAR_2->fields_header, VAR_7) && VAR_1[VAR_7] == ':') {

                uint8_t *ptr, *struct_ptr = realloc_section_array(VAR_0);

                if (!struct_ptr)  return NULL;

                VAR_1 += VAR_7 + 1;

                for (VAR_6=0; !is_eol(*VAR_1) && VAR_6 < *VAR_3; VAR_6++) {

                    int VAR_8 = VAR_6 == *VAR_3 - 1;

                    VAR_1 = skip_space(VAR_1);

                    VAR_7 = strcspn(VAR_1, VAR_8 ? "\r\n" : ",\r\n");

                    if (VAR_4[VAR_6] >= 0) {

                        ASSFieldType type = VAR_2->fields[VAR_4[VAR_6]].type;

                        ptr = struct_ptr + VAR_2->fields[VAR_4[VAR_6]].offset;

                        convert_func[type](ptr, VAR_1, VAR_7);

                    }

                    VAR_1 = skip_space(VAR_1 + VAR_7 + !VAR_8);

                }

            }

        } else {

            VAR_7 = strcspn(VAR_1, ":\r\n");

            if (VAR_1[VAR_7] == ':') {

                for (VAR_6=0; VAR_2->fields[VAR_6].name; VAR_6++)

                    if (!strncmp(VAR_1, VAR_2->fields[VAR_6].name, VAR_7)) {

                        ASSFieldType type = VAR_2->fields[VAR_6].type;

                        uint8_t *ptr = (uint8_t *)&VAR_0->ass + VAR_2->offset;

                        ptr += VAR_2->fields[VAR_6].offset;

                        VAR_1 = skip_space(VAR_1 + VAR_7 + 1);

                        convert_func[type](ptr, VAR_1, strcspn(VAR_1, "\r\n"));

                        break;

                    }

            }

        }

        VAR_1 += strcspn(VAR_1, "\n");

        VAR_1 += !!*VAR_1;

    }

    return VAR_1;

}

static const char *FUNC_0(ASSSplitContext *VAR_0, const char *VAR_1)
{ const ASSSection *VAR_2 = &ass_sections[VAR_0->current_section]; int *VAR_3 = &VAR_0->field_number[VAR_0->current_section]; int *VAR_4 = VAR_0->field_order[VAR_0->current_section]; int *VAR_5, VAR_6, VAR_7; while (VAR_1 && *VAR_1) { if (VAR_1[0] == '[') { VAR_0->current_section = -1; break; } if (VAR_1[0] == ';' || (VAR_1[0] == '!' && VAR_1[1] == ':')) { } else if (VAR_2->format_header && !VAR_4) { VAR_7 = strlen(VAR_2->format_header); if (strncmp(VAR_1, VAR_2->format_header, VAR_7) || VAR_1[VAR_7] != ':')
return NULL; VAR_1 += VAR_7 + 1; while (!is_eol(*VAR_1)) { VAR_1 = skip_space(VAR_1); VAR_7 = strcspn(VAR_1, ", \r\n"); if (!(VAR_5 = av_realloc(VAR_4, (*VAR_3 + 1) * sizeof(*VAR_4))))
return NULL; VAR_4 = VAR_5; VAR_4[*VAR_3] = -1; for (VAR_6=0; VAR_2->fields[VAR_6].name; VAR_6++) if (!strncmp(VAR_1, VAR_2->fields[VAR_6].name, VAR_7)) { VAR_4[*VAR_3] = VAR_6; break; } (*VAR_3)++; VAR_1 = skip_space(VAR_1 + VAR_7 + (VAR_1[VAR_7] == ',')); } VAR_0->field_order[VAR_0->current_section] = VAR_4; } else if (VAR_2->fields_header) { VAR_7 = strlen(VAR_2->fields_header); if (!strncmp(VAR_1, VAR_2->fields_header, VAR_7) && VAR_1[VAR_7] == ':') { uint8_t *ptr, *struct_ptr = realloc_section_array(VAR_0); if (!struct_ptr)  return NULL; VAR_1 += VAR_7 + 1; for (VAR_6=0; !is_eol(*VAR_1) && VAR_6 < *VAR_3; VAR_6++) { int VAR_8 = VAR_6 == *VAR_3 - 1; VAR_1 = skip_space(VAR_1); VAR_7 = strcspn(VAR_1, VAR_8 ? "\r\n" : ",\r\n"); if (VAR_4[VAR_6] >= 0) { ASSFieldType type = VAR_2->fields[VAR_4[VAR_6]].type; ptr = struct_ptr + VAR_2->fields[VAR_4[VAR_6]].offset; convert_func[type](ptr, VAR_1, VAR_7); } VAR_1 = skip_space(VAR_1 + VAR_7 + !VAR_8); } } } else { VAR_7 = strcspn(VAR_1, ":\r\n"); if (VAR_1[VAR_7] == ':') { for (VAR_6=0; VAR_2->fields[VAR_6].name; VAR_6++) if (!strncmp(VAR_1, VAR_2->fields[VAR_6].name, VAR_7)) { ASSFieldType type = VAR_2->fields[VAR_6].type; uint8_t *ptr = (uint8_t *)&VAR_0->ass + VAR_2->offset; ptr += VAR_2->fields[VAR_6].offset; VAR_1 = skip_space(VAR_1 + VAR_7 + 1); convert_func[type](ptr, VAR_1, strcspn(VAR_1, "\r\n")); break; } } } VAR_1 += strcspn(VAR_1, "\n"); VAR_1 += !!*VAR_1; } return VAR_1; }