from concurrent.futures import ThreadPoolExecutor
from os import system
from shutil import copytree, rmtree


def do(a: int, b: int):
    name = f"foo{a},{b}"
    copytree("typo", name, dirs_exist_ok=False)
    with open(name+"/mem", "r") as f:
        txt = f.read()
    with open(name+"/mem", "w") as f:
        f.write(txt.replace("0"*12+"7"*8, "0"*16+"{:02x}{:02x}".format(a, b)))
    system(f"cd {name}; (./analyze.sh |& grep -F '[sse:result] Model') || echo 'failed with {a} {b}'")
    rmtree(name)


with ThreadPoolExecutor(max_workers=12) as executor:
    for a in range(ord('a'), ord('z')+1):
        for b in range(ord('a'), ord('z')+1):
            executor.submit(do, a, b)
    executor.shutdown(wait=True)
