#include "util.h"
#include "kmp.h"
#include <stdio.h>
#include <papi.h>
#include <malloc.h>

int main() {
    int text_len, pattern_len;

    long_long start_time = PAPI_get_real_usec();
    char *text = read_file("data/dante.txt", &text_len);
    char *pattern = read_file("data/pattern.txt", &pattern_len);

    int lps[pattern_len];
    create_lps(pattern, pattern_len, lps);

    int match_number = 0;
    int residue = 0;

    long_long start_search = PAPI_get_real_usec();
    int *matches = search_pattern(text, pattern, lps, &match_number, &residue);
    free(text);
    long_long end_time = PAPI_get_real_usec();

    printf("found %d matches\n", match_number);
    printf("total elapsed: %d\n", end_time - start_time);
    printf("search elapsed: %d\n", end_time - start_search);
}
