"""Q11: dump the candidate functions to files for local analysis.

Rationale: the interesting functions are 3k-27k chars each and printing them all to
the transcript is wasteful. Write each decompile to
/tmp/claude-1000/-home-alex-Documents-OpenFUT/8e521ca1-ca3e-4138-bb96-df1744dd1d30/scratchpad/cards/dec/FUN_<addr>.c and print only name+length here.

Set chosen from Q10:
  FUN_180098f20  queries fcc_leaguelogos AND uses carddbid + cardassetid
  FUN_180098560 / FUN_1800989f0 / FUN_180042440 / FUN_180043350  fcc_myclubscategories
  FUN_1800991a0  fcc_myclubs
  FUN_180141660  the merge (carddbid)
  FUN_18011a860 / FUN_1801356c0 / FUN_1801362e0  other carddbid users
  FUN_18013fe00  the shared item deserializer (full, for local grep)
  FUN_18011e9d0  the <0x95 callback from Q9
  FUN_18013af30  the remaining scan hit

CONTROL: FUN_18013fe00 must come out at 26234 chars, the length Q8 measured. A
different length means a different function or a different decompiler setting.
"""
import os
import traceback

OUT = ("/tmp/claude-1000/-home-alex-Documents-OpenFUT/"
       "8e521ca1-ca3e-4138-bb96-df1744dd1d30/scratchpad/cards/dec")

try:
    os.makedirs(OUT, exist_ok=True)
    for a in (0x180098F20, 0x180098560, 0x1800989F0, 0x180042440, 0x180043350,
              0x1800991A0, 0x180141660, 0x18011A860, 0x1801356C0, 0x1801362E0,
              0x18013FE00, 0x18011E9D0, 0x18013AF30, 0x180096670, 0x1801017E0):
        src = dec(a)
        p = os.path.join(OUT, "FUN_%x.c" % a)
        with open(p, "w") as f:
            f.write(src)
        print("  %-14s len=%d -> %s" % ("FUN_%x" % a, len(src), p))
except Exception:
    traceback.print_exc()
