def METHOD_NAME(relay_ir, filename: str, save_mem=True):
    """Writes the Calyx program lowered
    from `relay_ir` to `filename`."""
    (dahlia_defs, prog) = relay_visitor.emit_calyx(relay_ir, save_mem)
    with open(filename, "w") as file:
        imports = [
            Import("primitives/core.futil"),
            Import("primitives/binary_operators.futil"),
            Import("primitives/math.futil"),
            Import("primitives/memories.futil"),
        ]
        for imp in imports:
            file.writelines(imp.doc())
        file.writelines(dahlia_defs)
        file.writelines(prog.doc())