<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_r_ending_to_syllable(last_syllable: str, is_first=True) -> str: """ Adds an the -r ending to the last syllable of an Old Norse word. In some cases, it really adds an -r. In other cases, it on doubles the last character or left the syllable unchanged. 'armr' 'áss' 'stóll' 'jökull' 'steinn' 'mikill' 'sæll' 'litill' 'vænn' 'lauss' 'vinr' 'selr' 'fagr' 'vitr' 'vetr' 'akr' 'Björn' 'þurs' 'karl' 'hrafn' :param last_syllable: last syllable of the word :param is_first: is it the first syllable of the word? :return: inflected syllable """

    if len(last_syllable) >= 2:
        if last_syllable[-1] in ['l', 'n', 's', 'r']:
            if last_syllable[-2] in CONSONANTS:
                # Apocope of r
                return last_syllable
            else:
                # Assimilation of r
                if len(last_syllable) >= 3 and last_syllable[-3:-1] in DIPHTHONGS:
                    return apply_raw_r_assimilation(last_syllable)
                elif last_syllable[-2] in SHORT_VOWELS and is_first:
                    # No assimilation when r is supposed to be added to a stressed syllable
                    # whose last letter is l, n or s and the penultimate letter is a short vowel
                    return last_syllable + "r"
                elif last_syllable[-2] in SHORT_VOWELS:
                    return apply_raw_r_assimilation(last_syllable)
                elif last_syllable[-2] in LONG_VOWELS:
                    return apply_raw_r_assimilation(last_syllable)
                return apply_raw_r_assimilation(last_syllable)
        else:
            return last_syllable + "r"
    else:
        return last_syllable + "r"