"""Q6: the club query taxonomy switch and the club URL builder.

Prior work (tools/fut_club_stats.py header) records FUN_18012ec50 as the 30-arm
atom switch that turns a club ?type= name into a code, with 11 badge, 12 kit,
13 stadium, 14 ball, 15 equippables, 16 leaguelogos.

HYPOTHESIS: something downstream of that code either (a) adds a &cardsubtype=
filter, which would give the mapping outright, or (b) buckets the RESPONSE items
by cardsubtypeid for the combined equippables view.

NOTE ON THE FAILED CONTROL IN Q5: the scalar scan did NOT find FUN_1800d8330,
whose 0x1e/0x1f/0x91..0x96 case labels are a jump table, so scalar scanning cannot
see switch dispatch here. Every "not found" from that scan is void. This query
therefore works from call graph and strings only.

CONTROL here: FUN_18012ec50 must decompile to a switch whose arms match the 30
names already recorded. If it does not, the recorded note (and my starting point)
is wrong.
"""
import traceback

try:
    for a, tag in [(0x18012EC50, "CONTROL club ?type= taxonomy switch"),
                   (0x180096670, "UI group-table switch")]:
        src = dec(a)
        print("=" * 78)
        print("%s @%#x len=%d" % (tag, a, len(src)))
        print(src)

    print("=" * 78)
    print("=== callers of FUN_18012ec50 ===")
    for frm, typ, fn, ent in xrefs_to(0x18012EC50):
        print("   %s(%#x) via %#x %s" % (fn, ent, frm, typ))

    print()
    print("=== url-ish literals ===")
    for p in [b"/club?", b"/club", b"club?type", b"type=%s", b"&cat=%s",
              b"&cardsubtype=%d", b"&count=%d", b"/item", b"/purchased"]:
        hits = find_all(p)
        print("  %-18r n=%d" % (p.decode(), len(hits)))
        for h in hits[:14]:
            s = rd_str(h, 120)
            fs = []
            for frm, typ, fn, ent in xrefs_to(h):
                fs.append("%s(%#x)" % (fn, ent))
            print("     %#x %-58r  <- %s" % (h, s, ",".join(fs) or "-"))
except Exception:
    traceback.print_exc()
