def extend_smallest_list(a, b, extension_val=None):
    """Extend the smallest list to match the length of the longest list.

    If extension_val is None, the extension is done by repeating the last element of the list. Otherwise, use
    extension_val.

    Arg(s):
        a - A list.
        b - A list.
        extension_val - Extension value.
    Returns:
        The input lists with the smallest list extended to match the size of the longest list.
    """
    gap = abs(len(a) - len(b))
    if len(a) > len(b):
        extension_val = extension_val if extension_val is not None else b[-1]
        b += [extension_val] * gap
    else:
        extension_val = extension_val if extension_val is not None else a[-1]
        a += [extension_val] * gap
    return a, b