'Derive a new function IR from this one, using the given blocks,
and possibly modifying the argument count and generator flag.
Post-processing will have to be run again on the new IR.'

def derive(self, blocks, arg_count=None, arg_names=None, force_non_generator=False):

    firstblock = blocks[min(blocks)]
    is_generator = (self.is_generator and (not force_non_generator))
    new_ir = copy.copy(self)
    new_ir.blocks = blocks
    new_ir.loc = firstblock.loc
    if force_non_generator:
        new_ir.is_generator = False
    if (arg_count is not None):
        new_ir.arg_count = arg_count
    if (arg_names is not None):
        new_ir.arg_names = arg_names
    new_ir._reset_analysis_variables()
    return new_ir
