<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def optimize(update_working_block=True, block=None, skip_sanity_check=False):
 """ Return an optimized version of a synthesized hardware block. :param Boolean update_working_block: Don't copy the block and optimize the new block :param Block block: the block to optimize (defaults to working block) Note: optimize works on all hardware designs, both synthesized and non synthesized """

    block = working_block(block)
    if not update_working_block:
        block = copy_block(block)

    with set_working_block(block, no_sanity_check=True):
        if (not skip_sanity_check) or debug_mode:
            block.sanity_check()
        _remove_wire_nets(block)
        constant_propagation(block, True)
        _remove_unlistened_nets(block)
        common_subexp_elimination(block)
        if (not skip_sanity_check) or debug_mode:
            block.sanity_check()
    return block