def METHOD_NAME(function, templates, concat_lines=False):
    arglist_separator = ", \\\n" if concat_lines else ",\n"
    function_name = templates["function_name"].format(
        function=function["name"],
    )
    arglist_indent = " " * len(f"{function_name} (")
    arglist = f"{arglist_separator}{arglist_indent}".join([
        templates["function_argument"].format(
            argument_index=index,
            argument_name=argument["name"],
            argument_type=argument["type"],
        )
        for index, argument in enumerate(function["arguments"])
    ])
    call_lower_template = templates["call_lower"]
    if function["version"] >= 3:
        call_lower_template = templates.get("call_lower_v3",
                                            call_lower_template)
    call_lower = call_lower_template.format(
        function=function["name"],
    )
    call_lower_arglist_indent = " " * len(f"{INDENT}{call_lower} (")
    call_lower_arglist = f"{arglist_separator}{call_lower_arglist_indent}".join([
        templates["call_lower_argument"].format(
            argument_index=index,
            argument_name=argument["name"],
            argument_type=argument["type"],
        )
        for index, argument in enumerate(function["arguments"])
    ])
    has_slot_id = next((argument for argument in function["arguments"] if argument["type"] == "CK_SLOT_ID"), None)
    has_session_handle = next((argument for argument in function["arguments"] if argument["type"] == "CK_SESSION_HANDLE"), None)
    assert not (has_slot_id and has_session_handle)
    function_body_template = templates.get("function_body")
    if function_body_template and function["version"] >= 3:
        function_body_template = templates.get("function_body_v3",
                                               function_body_template)
    if has_slot_id:
        template = templates.get("function_body_with_slot")
        if template is not None:
            function_body_template = templates.get(
                "function_body_with_slot_v3",
                template,
            )
    elif has_session_handle:
        template = templates.get("function_body_with_session")
        if template is not None:
            function_body_template = templates.get(
                "function_body_with_session_v3",
                template,
            )
    return function_body_template.format(
        indent=INDENT,
        function_name=function_name,
        arglist=arglist,
        arglist_indent=arglist_indent,
        call_lower=call_lower,
        call_lower_arglist=call_lower_arglist,
        call_lower_arglist_indent=call_lower_arglist_indent,
    )