# Path: asmprinter.py
# class AsmPrinter(CFGPrinter):
# 
#     def __init__(self, cfg, stream=sys.stdout):
#         super().__init__(cfg, stream)
#         self.addr_width = 8
#         self.inst_indent = 4
#         self.no_dead = False
# 
#         self.inst_printer = self.print_with_addr
#         self.referenced_labels = set()
#         self.get_jump_labels()
# 
#     def format_addr(self, addr, extra=0):
#         return addr.ljust(self.addr_width + extra)
# 
#     def get_jump_labels(self):
#         def collect_labels(inst):
#             assert isinstance(inst, Inst), "Perhaps, this is structured CFG? Use --format=c for output."
#             addr = inst.jump_addr()
#             if isinstance(addr, list):
#                 self.referenced_labels.update(addr)
#             elif addr is not None:
#                 self.referenced_labels.add(addr)
#         foreach_inst(self.cfg, collect_labels)
# 
#     def print_with_addr(self, inst):
#         if inst.op == "DEAD" and self.no_dead:
#             return
#         addr = inst.addr
#         if addr is None:
#             addr = "?"
#         return self.format_addr(addr, self.inst_indent) + " " + str(inst)
# 
#     def resolve_label(self, addr):
#         return self.cfg.parser.label_from_addr(addr)
# 
#     def print_label(self):
#         # If there was symbolic label originally, print it
#         # otherwise, skip it if it's not referenced by insts
#         # (like bblock start labels).
#         label = self.cfg.parser.label_from_addr(self.addr)
#         if label == self.addr:
#             if self.addr not in self.referenced_labels:
#                 return
#         print("%s %s:" % (self.format_addr(self.addr), label), file=self.stream)
# 
#     def print_graph_header(self):
#         pass
#     def print_header(self):
#         pass
#     def print_separator(self):
#         pass
#     def print_trailer(self):
#         pass
# 
#     def print(self):
#         core.ADDR.resolver = self.resolve_label
#         super().print()


import sys
import argparse
import os.path
import glob
import logging
import yaml
import yamlutils
import core
import dot
import cprinter
import progdb
import bindata
import copy
        import dot
import arch
from parser import *
from dataflow import *
from xform import *
from xform_utils import *
from decomp import *
from asmprinter import AsmPrinter
                func = globals()[op_name]
                foreach_inst(cfg, func)
            elif op_type == "script:":
                mod = __import__(op_name)
                mod.apply(cfg)
            else:
                assert 0

    if args.debug:
        with open(args.file + ".out.bb", "w") as f:
            dump_bblocks(cfg, f, no_graph_header=args.no_graph_header)
        with open(args.file + ".out.dot", "w") as f:
            dot.dot(cfg, f)

    if args.output and args.format != "none":
        out = open(args.output, "w")
    else:
        out = sys.stdout

    if args.no_comments:
        Inst.show_comments = False

    if args.format == "bblocks":
        p = CFGPrinter(cfg, out)
        if args.no_graph_header:
            p.print_graph_header = lambda: None
        p.inst_printer = repr if args.repr else str
        p.no_dead = args.no_dead
        p.print()
    elif args.format == "asm":

# Path: asmprinter.py
# class AsmPrinter(CFGPrinter):
# 
#     def __init__(self, cfg, stream=sys.stdout):
#         super().__init__(cfg, stream)
#         self.addr_width = 8
#         self.inst_indent = 4
#         self.no_dead = False
# 
#         self.inst_printer = self.print_with_addr
#         self.referenced_labels = set()
#         self.get_jump_labels()
# 
#     def format_addr(self, addr, extra=0):
#         return addr.ljust(self.addr_width + extra)
# 
#     def get_jump_labels(self):
#         def collect_labels(inst):
#             assert isinstance(inst, Inst), "Perhaps, this is structured CFG? Use --format=c for output."
#             addr = inst.jump_addr()
#             if isinstance(addr, list):
#                 self.referenced_labels.update(addr)
#             elif addr is not None:
#                 self.referenced_labels.add(addr)
#         foreach_inst(self.cfg, collect_labels)
# 
#     def print_with_addr(self, inst):
#         if inst.op == "DEAD" and self.no_dead:
#             return
#         addr = inst.addr
#         if addr is None:
#             addr = "?"
#         return self.format_addr(addr, self.inst_indent) + " " + str(inst)
# 
#     def resolve_label(self, addr):
#         return self.cfg.parser.label_from_addr(addr)
# 
#     def print_label(self):
#         # If there was symbolic label originally, print it
#         # otherwise, skip it if it's not referenced by insts
#         # (like bblock start labels).
#         label = self.cfg.parser.label_from_addr(self.addr)
#         if label == self.addr:
#             if self.addr not in self.referenced_labels:
#                 return
#         print("%s %s:" % (self.format_addr(self.addr), label), file=self.stream)
# 
#     def print_graph_header(self):
#         pass
#     def print_header(self):
#         pass
#     def print_separator(self):
#         pass
#     def print_trailer(self):
#         pass
# 
#     def print(self):
#         core.ADDR.resolver = self.resolve_label
#         super().print()


# Path: apply_xform.py
import sys
import argparse
import os.path
import glob
import logging
import yaml
import yamlutils
import core
import dot
import cprinter
import progdb
import bindata
import copy
        import dot
import arch
from parser import *
from dataflow import *
from xform import *
from xform_utils import *
from decomp import *
from asmprinter import AsmPrinter

                func = globals()[op_name]
                foreach_inst(cfg, func)
            elif op_type == "script:":
                mod = __import__(op_name)
                mod.apply(cfg)
            else:
                assert 0

    if args.debug:
        with open(args.file + ".out.bb", "w") as f:
            dump_bblocks(cfg, f, no_graph_header=args.no_graph_header)
        with open(args.file + ".out.dot", "w") as f:
            dot.dot(cfg, f)

    if args.output and args.format != "none":
        out = open(args.output, "w")
    else:
        out = sys.stdout

    if args.no_comments:
        Inst.show_comments = False

    if args.format == "bblocks":
        p = CFGPrinter(cfg, out)
        if args.no_graph_header:
            p.print_graph_header = lambda: None
        p.inst_printer = repr if args.repr else str
        p.no_dead = args.no_dead
        p.print()
    elif args.format == "asm":

        p = AsmPrinter(cfg, out)