# Buggy code
def _analyze_function(self) -> Optional[SimCC]:
    """
    Go over the variable information in variable manager for this function, and return all uninitialized
    register/stack variables.
    """

    if self._function.is_simprocedure or self._function.is_plt:
        # we do not analyze SimProcedures or PLT stubs
        return None

    if not self._variable_manager.has_function_manager:
        l.warning(
            "Please run variable recovery on %r before analyzing its calling convention.",
            self._function,
        )
        return None

    vm = self._variable_manager[self._function.addr]

    input_variables = vm.input_variables()

    input_args = self._args_from_vars(input_variables)

    # TODO: properly determine sp_delta
    sp_delta = self.project.arch.bytes if self.project.arch.call_pushes_ret else 0

    cc = SimCC.find_cc(self.project.arch, list(input_args), sp_delta)

    if cc is None:
        l.warning(
            "_analyze_function(): Cannot find a calling convention for %r that fits the given arguments.",
            self._function,
        )
    else:
        # reorder args
        args = self._reorder_args(input_args, cc)
        cc.args = args

        # set return value
        cc.ret_val = cc.return_val

    return cc


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/main_window.py", line 496, in decompile_current_function
self.workspace.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 265, in decompile_current_function
view.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/disassembly_view.py", line 382, in decompile_current_function
self.workspace.decompile_function(self._current_function.am_obj)
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 279, in decompile_function
view.function = func
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 66, in function
self.decompile()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 43, in decompile
d = self.workspace.instance.project.analyses.Decompiler(
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 24, in __init__
self._decompile()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 41, in _decompile
clinic = self.project.analyses.Clinic(self.func,
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 70, in __init__
self._analyze()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 138, in _analyze
ail_graph = self._make_returns(ail_graph)
File "/home/dnivra/angr-dev/angr/angr/utils/timing.py", line 28, in timed_func
return func(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 457, in _make_returns
AILGraphWalker(ail_graph, _handler, replace_nodes=True).walk()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailgraph_walker.py", line 23, in walk
r = self.handler(node)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 453, in _handler
walker.walk(block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 37, in walk
self._handle_stmt(i, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 50, in _handle_stmt
return handler(stmt_idx, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 434, in _handle_Return
and self.function.calling_convention.ret_val is not None:
AttributeError: 'NoneType' object has no attribute 'ret_val'

# Fixed code
def _analyze_function(self) -> Optional[SimCC]:
    """
    Go over the variable information in variable manager for this function, and return all uninitialized
    register/stack variables.
    """

    if self._function.is_simprocedure or self._function.is_plt:
        # we do not analyze SimProcedures or PLT stubs
        return None

    if not self._variable_manager.has_function_manager:
        l.warning(
            "Please run variable recovery on %r before analyzing its calling convention.",
            self._function,
        )
        return None

    vm = self._variable_manager[self._function.addr]

    input_variables = vm.input_variables()
    input_args = self._args_from_vars(input_variables, vm)

    # TODO: properly determine sp_delta
    sp_delta = self.project.arch.bytes if self.project.arch.call_pushes_ret else 0

    cc = SimCC.find_cc(self.project.arch, list(input_args), sp_delta)

    if cc is None:
        l.warning(
            "_analyze_function(): Cannot find a calling convention for %r that fits the given arguments.",
            self._function,
        )
    else:
        # reorder args
        args = self._reorder_args(input_args, cc)
        cc.args = args

        # set return value
        cc.ret_val = cc.return_val

    return cc