"""Side finding follow-up: the parsed item's +0x34 is pushed to the UI as
"BOUGHT_FOR" (FUN_1800eb850, from local_38+0x34) and it is NOT on the field map.
It is written once in the deserializer, at 0x180140885 (MOV [RBP+0x194],EAX).

Q: which wire atom writes it? Print the instruction stream from 0x180140780 to
0x1801408c0 so the dispatch arm and its atom immediate are visible, in whatever
form the compiler chose (cmp / sub-ladder / switch), rather than grepping for
one form.

CONTROL: the same window must also show the neighbouring known write
0x180140e43 -> [RBP+0x190] (item+0x30) or, failing that, at least one arm whose
atom is already in docs/fut_atoms.tsv, so that the arm-reading method is shown
to work on a known case in the same function.
"""
import traceback

OUT = "/tmp/claude-1000/-home-alex-Documents-OpenFUT/8e521ca1-ca3e-4138-bb96-df1744dd1d30/scratchpad/cards/q9_out.txt"

try:
    lines = []
    def P(*a):
        lines.append(" ".join(str(x) for x in a))

    for lo, hi, tag in ((0x180140760, 0x1801408D0, "around the +0x34 (BOUGHT_FOR) write"),
                        (0x180140DC0, 0x180140E60, "around the +0x30 write, as a control")):
        P("=== %s : %#x..%#x ===" % (tag, lo, hi))
        p = lo
        while p < hi:
            ins = listing.getInstructionAt(addr(p))
            if ins is None:
                p += 1
                continue
            P("  %#x  %s" % (p, ins))
            p += ins.getLength()
        P("")

    with open(OUT, "w") as fh:
        fh.write("\n".join(lines))
    print("wrote %s (%d lines)" % (OUT, len(lines)))
except Exception:
    traceback.print_exc()
