import lzma
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path

here = Path(__file__).resolve().parent
archive, output = (Path(arg).resolve() for arg in sys.argv[1:3])
with tempfile.TemporaryDirectory() as work:
    program = Path(work, "x")
    program.write_bytes(
        lzma.decompress((here / "c.xz").read_bytes())
        + (here / "e").read_bytes()
        + (here / "w").read_bytes()
        + archive.read_bytes()
    )
    program.chmod(0o755)
    subprocess.run([program], cwd=work, check=True)
    shutil.move(f"{program}.out", output)
