def METHOD_NAME(format_addresses, elf, lines):
    STACK_RE = re.compile(r"^[0-9a-f]{8}:\s+([0-9a-f]{8} ?)+ *$")
    LAST_ALLOC_RE = re.compile(
        r"last failed alloc call: ([0-9a-fA-F]{8})\(([0-9]+)\).*"
    )
    LAST_ALLOC = "last failed alloc"
    CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER"
    EXCEPTION_STRING = "Exception ("
    EPC_STRING = "epc1="
    # either print everything as-is, or cache current string and dump after stack contents end
    last_stack = None
    stack_addresses = {}
    in_stack = False
    def print_all_addresses(addresses):
        for ctx, addrs in addresses.items():
            print()
            print(ctx)
            for formatted in format_addresses(elf, addrs):
                print(formatted)
        return dict()
    def format_address(address):
        return "\n".join(format_addresses(elf, [address]))
    for line in lines:
        # ctx could happen multiple times. for the 2nd one, reset list
        # ctx: bearssl *or* ctx: cont *or* ctx: sys *or* ctx: whatever
        if in_stack and "ctx:" in line:
            stack_addresses = print_all_addresses(stack_addresses)
            last_stack = line.strip()
        # 3fffffb0:  feefeffe feefeffe 3ffe85d8 401004ed
        elif in_stack and STACK_RE.match(line):
            stack, addrs = line.split(":")
            addrs = addrs.strip()
            addrs = addrs.split(" ")
            stack_addresses.setdefault(last_stack, [])
            for addr in addrs:
                stack_addresses[last_stack].append(addr)
        # epc1=0xfffefefe epc2=0xfefefefe epc3=0xefefefef excvaddr=0xfefefefe depc=0xfefefefe
        elif EPC_STRING in line:
            pairs = line.split()
            for pair in pairs:
                name, addr = pair.split("=")
                if name in ["epc1", "excvaddr"]:
                    output = format_address(addr)
                    if output:
                        print(f"{name}={output}")
        # Exception (123):
        # Other reasons coming before the guard shown as-is
        elif EXCEPTION_STRING in line:
            number = line.strip()[len(EXCEPTION_STRING) : -2]
            print(f"Exception ({number}) - {EXCEPTION_CODES[int(number)]}")
        # last failed alloc call: <ADDR>(<NUMBER>)[@<maybe file loc>]
        elif LAST_ALLOC in line:
            values = LAST_ALLOC_RE.match(line)
            if values:
                addr, size = values.groups()
                print()
                print(f"Allocation of {size} bytes failed: {format_address(addr)}")
        # postmortem guards our actual stack dump values with these
        elif ">>>stack>>>" in line:
            in_stack = True
        # ignore
        elif "<<<stack<<<" in line:
            continue
        elif CUT_HERE_STRING in line:
            continue
        else:
            line = line.strip()
            if line:
                print(line)
    print_all_addresses(stack_addresses)