def longest_prefix(text, pattern, start):
    """
    Finds the longest prefix of text and pattern.
    """
    end = len(pattern)
    while text[start:start + end] != pattern[:end]:
        end -= 1
    return text[start:start + end]
