code: def optimize(initial_memory):
      
      global BLOCKS
      global PROC_COUNTER
  
      LABELS.clear()
      JUMP_LABELS.clear()
      del MEMORY[:]
      PROC_COUNTER = 0
  
      cleanupmem(initial_memory)
      if OPTIONS.optimization.value <= 2:
          return '\n'.join(x for x in initial_memory if not RE_PRAGMA.match(x))
  
      optimize_init()
      bb = BasicBlock(initial_memory)
      cleanup_local_labels(bb)
      initialize_memory(bb)
  
      BLOCKS = basic_blocks = get_basic_blocks(bb)  # 1st partition the Basic Blocks
  
      for x in basic_blocks:
          x.clean_up_comes_from()
          x.clean_up_goes_to()
  
      for x in basic_blocks:
          x.update_goes_and_comes()
  
      LABELS['*START*'].basic_block.add_goes_to(basic_blocks[0])
      LABELS['*START*'].basic_block.next = basic_blocks[0]
  
      basic_blocks[0].prev = LABELS['*START*'].basic_block
      LABELS[END_PROGRAM_LABEL].basic_block.add_goes_to(LABELS['*__END_PROGRAM*'].basic_block)
  
      for x in basic_blocks:
          x.optimize()
  
      for x in basic_blocks:
          if x.comes_from == [] and len([y for y in JUMP_LABELS if x is LABELS[y].basic_block]):
              x.ignored = True
  
      return '\n'.join([y for y in flatten_list([x.asm for x in basic_blocks if not x.ignored])
                        if not RE_PRAGMA.match(y)])
docs: This will remove useless instructions