# Buggy code
def subgraph(self, ins_addrs):
    """
    Generate a sub control flow graph of instruction addresses based on self.graph

    :param iterable ins_addrs: A collection of instruction addresses that should be included in the subgraph.
    :return networkx.DiGraph: A subgraph.
    """

    # find all basic blocks that include those instructions
    blocks = []
    block_addr_to_insns = {}

    for b in self._local_blocks.values():
        # TODO: should I call get_blocks?
        block = self._get_block(b.addr, size=b.size, byte_string=b.bytestr)
        common_insns = set(block.instruction_addrs).intersection(ins_addrs)
        if common_insns:
            blocks.append(b)
            block_addr_to_insns[b.addr] = sorted(common_insns)

    # subgraph = networkx.subgraph(self.graph, blocks)
    subgraph = self.graph.subgraph(blocks).copy()
    g = networkx.DiGraph()

    for n in subgraph.nodes():
        insns = block_addr_to_insns[n.addr]

        in_edges = subgraph.in_edges(n)
        # out_edges = subgraph.out_edges(n)
        if len(in_edges) > 1:
            # the first instruction address should be included
            if n.addr not in insns:
                insns = [n.addr] + insns

        for src, _ in in_edges:
            last_instr = block_addr_to_insns[src.addr][-1]
            g.add_edge(last_instr, insns[0])

        for i in range(0, len(insns) - 1):
            g.add_edge(insns[i], insns[i + 1])

    return g


# 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 subgraph(self, ins_addrs):
    """
    Generate a sub control flow graph of instruction addresses based on self.graph

    :param iterable ins_addrs: A collection of instruction addresses that should be included in the subgraph.
    :return networkx.DiGraph: A subgraph.
    """

    # find all basic blocks that include those instructions
    blocks = []
    block_addr_to_insns = {}

    for b in self._local_blocks.values():
        # TODO: should I call get_blocks?
        block = self.get_block(b.addr, size=b.size, byte_string=b.bytestr)
        common_insns = set(block.instruction_addrs).intersection(ins_addrs)
        if common_insns:
            blocks.append(b)
            block_addr_to_insns[b.addr] = sorted(common_insns)

    # subgraph = networkx.subgraph(self.graph, blocks)
    subgraph = self.graph.subgraph(blocks).copy()
    g = networkx.DiGraph()

    for n in subgraph.nodes():
        insns = block_addr_to_insns[n.addr]

        in_edges = subgraph.in_edges(n)
        # out_edges = subgraph.out_edges(n)
        if len(in_edges) > 1:
            # the first instruction address should be included
            if n.addr not in insns:
                insns = [n.addr] + insns

        for src, _ in in_edges:
            last_instr = block_addr_to_insns[src.addr][-1]
            g.add_edge(last_instr, insns[0])

        for i in range(0, len(insns) - 1):
            g.add_edge(insns[i], insns[i + 1])

    return g