# GATE SHADOWS (run link100, lane SHADOWS) -- the two rows out of the 29-row
# shadow queue that the ROM's own body can take, once the seam each host copy
# was written for is expressed as a BRIDGE instead of as an edited copy of the
# matched source.
#
# Both rows are the same defect and the same remedy. A matched TU calls a state
# setter with the setter's SECOND argument dropped. On ARM that rides
# byte-identical because the caller has already put the value in r1 and the
# `bl` does not disturb it; on the host, cdecl passes only the declared
# argument and the callee reads stack garbage, so the setter indexes its state
# table at garbage*16. Both host copies fixed that by re-typing the call inside
# a line-for-line copy of the matched body. That is one edited statement and a
# whole ROM body kept out of the link.
#
# THE ARGUMENT IS NOT INFERRED IN EITHER ROW. This lane read both call sites
# out of extracted/overlays/ (never the dsd copies) at the overlay's own load
# base, and in both the instruction before the branch is `mov r1, #0`:
#
#   ov072, base 0x0211f000, BabyPenguin::InitResources 0x02121e84 (size 0x11c)
#     02121F68  0010a0e3  mov  r1, #0
#     02121F6C  d01084e5  str  r1, [r4, #0xd0]
#     02121F70  0400a0e1  mov  r0, r4
#     02121F74  601384e5  str  r1, [r4, #0x360]
#     02121F78  74ffffeb  bl   #0x2121d50        <- func_ov072_02121d50(this, 0)
#
#   ov080, base 0x02123740, CrazedCrate::InitResources 0x021251ec (size 0x12c)
#     021252DC  0010a0e3  mov  r1, #0
#     021252E0  0400a0e1  mov  r0, r4
#     021252E4  741384e5  str  r1, [r4, #0x374]
#     021252E8  93ffffeb  bl   #0x212513c        <- func_ov080_0212513c(this, 0)
#
# so the second argument is the ROM's own zero at both sites, and both setters
# are already in the link with their real two-argument shape
# (src/func_ov072_02121d50.c and src/func_ov080_0212513c.c both spell
# `(char* c, int i)` and store data_...[i << 4]).
#
# THE BRIDGE. hal/method_faces.cpp defines one zero-index forwarder per row --
# port_ov072_bp_state_i0 and port_ov080_cc_state_i0 -- and each src TU is
# compiled with a per-source -D that renames its call of the setter onto the
# forwarder. The rename is exact and total in both files:
#   * src/_ZN11BabyPenguin13InitResourcesEv.cpp declares the setter ITSELF
#     (`extern "C" void func_ov072_02121d50(void *c);`, one argument), so the
#     -D moves the declaration and the one call together and nothing else in
#     the tree sees it. decl_common.h has no declaration of that name.
#   * src/_ZN11CrazedCrate13InitResourcesEv.cpp takes its declaration from
#     include/decl_common.h:2857 (`extern void func_ov080_0212513c(void*);`,
#     inside that file's extern "C" block opened at line 20), so the -D moves
#     that one declaration and the one call in this TU only. The header is
#     unchanged and every other caller of the setter still spells the ROM name.
# The forwarder then calls the real two-argument body. That is the C-name
# bridge shape the port already uses everywhere else, pointed INTO the ROM's
# body rather than standing in front of it.
#
# WHAT IS RETIRED. port/unmatched/BabyPenguin_InitResources.cpp and
# port/unmatched/CrazedCrate_InitResources.cpp, both of which were the matched
# body with exactly one statement changed (verified by diff before deleting:
# one line differs in each, and it is the call above). BabyPenguin's copy came
# off the three target lists in port/CMakeLists.txt; CrazedCrate's is commented
# out of port/slice_w5a.txt, which is where that class's other seventeen TUs
# live. The two SIBLING seams of the same family stay as they are and are NOT
# part of this gate: port/unmatched/BabyPenguin_LandTransition.cpp
# (func_ov072_021217ac) and port/unmatched/CrazedCrate_State2Tick.c
# (func_ov080_02124e60) are not shadow rows -- neither name is in the queue --
# so retiring them would be a change with no measurement behind it.
#
src/_ZN11BabyPenguin13InitResourcesEv.cpp
src/_ZN11CrazedCrate13InitResourcesEv.cpp

# ---------------------------------------------------------------------------
# RUNG 2: THE LAKITU BRO'S InitResources, AND THE THIRD ARGUMENT THAT IS THE
# HOST WRAPPER'S OWN, NOT THE ROM'S
# ---------------------------------------------------------------------------
#
# src/_ZN9LakituBro13InitResourcesEv.cpp -- the third of the three InitResources
# rows in the shadow queue, and the same remedy read from the other end. Here
# the matched TU is RIGHT about the ROM and the HOST WRAPPER is the one that
# wants an argument the ROM never passed.
#
# TextureSequence::Prepare's ROM body is a 0xc tail-call veneer into
# func_02046d50, which takes two arguments. This lane re-read the call site in
# the overlay image rather than taking the host copy's word for it -- ov085,
# base 0x02129020, LakituBro::InitResources 0x0212ebec (size 0x168):
#
#     0212EC34  fc009fe5  ldr  r0, [pc, #0xfc]
#     0212EC38  00119fe5  ldr  r1, [pc, #0x100]
#     0212EC3C  040090e5  ldr  r0, [r0, #4]
#     0212EC40  041091e5  ldr  r1, [r1, #4]
#     0212EC44  4c9bfbeb  bl   #0x201597c        <- Prepare, r0 and r1 only
#     0212EC48  0020a0e3  mov  r2, #0            <- r2 is written AFTER the call
#
# so r2 held whatever was left in it and the ROM's call really is two arguments.
# The port's wrapper (hal/player_bridges.cpp) is a three-parameter thiscall
# face, so the matched TU's honest two-argument call leaves the wrapper's third
# parameter unwritten. port/unmatched/TexSeq_Caller_LakituBro.cpp fixed that by
# repeating the second argument inside a copy of the whole body.
#
# THE THIRD ARGUMENT IS A HOST VALUE, so it belongs on the host side of the
# seam and nowhere else: port_texseq_prepare_r1 (hal/method_faces.cpp) takes the
# ROM's two arguments and hands the wrapper the second one twice, which is
# exactly what the host copy did and what func_02046d50 ignores. The src TU is
# compiled with -D_ZN15TextureSequence7PrepareER8BMD_FileR8BTP_File=
# port_texseq_prepare_r1, which moves its own local declaration and both of its
# call sites together; no other Prepare caller in the tree is renamed.
#
# WHAT IS LOST WITH THE HOST COPY, said out loud: that file also carried an
# SM64DS_INTRO_WATCH diagnostic (which of the three LakituBro chains a spawn
# takes, printed once per spawn, inert unless the variable is set). Retiring the
# body retires the probe. Six other SM64DS_INTRO_WATCH sites remain, two of them
# on this same actor and chain -- hal/actor_classes_intro.cpp and
# port/unmatched/Ov085_LakituBro_IntroEnd.cpp -- so the watch still reports on
# the opening; this one line of it does not.
#
src/_ZN9LakituBro13InitResourcesEv.cpp

# ---------------------------------------------------------------------------
# RUNG 3: THE SHADOW WHOSE SEAM IS A RETURN TYPE
# ---------------------------------------------------------------------------
#
# src/_ZN13SharedFilePtr19ReallocateModelFileEv.cpp -- the tenth MSVC-NAME
# SHADOW row, and the first of the 29 whose host stand-in was not a copy of the
# matched body at all. It was an empty method:
#
#   port/hal/gx_upload_bridge.cpp:62
#     // Shrinks the file image to its post-parse size on the DS (a heap-space
#     // optimization). Skipped on host: the image simply stays at load size.
#     void SharedFilePtr::ReallocateModelFile() {}
#
# NOTHING WAS MISSING UNDER IT. The ROM's body is one statement,
# `return func_02017060(file);`, and func_02017060 (the DS shrink-to-fit:
# Heap::_Sizeof, func_020469e0, Heap::Reallocate on Memory::gameHeapPtr) has
# ridden port/slice_gate16.txt since gate 16. What kept the body out is that
# the two matched TUs DISAGREE ABOUT THE RETURN TYPE:
#
#   src/_ZN13SharedFilePtr19ReallocateModelFileEv.cpp  unsigned int  (the body)
#   src/_ZN5Model8LoadFileER13SharedFilePtr.cpp:12     void          (the caller)
#   include/SharedFilePtr.h:25                         void
#
# On ARM that is invisible: the Itanium name carries no return type, so all
# three are _ZN13SharedFilePtr19ReallocateModelFileEv and mwcc links them. MSVC
# puts the return type IN the decoration, so the caller asks for ?...@@QAEXXZ
# and the body publishes ?...@@QAEIXZ -- two names for one function, and the
# empty host method answered the first one.
#
# THE ALIAS IS ABI-EXACT AND READ OFF THE OBJECT, not off the mangling rules.
# cl /c on the matched TU publishes
#   ?ReallocateModelFile@SharedFilePtr@@QAEIXZ
#     (public: unsigned int __thiscall SharedFilePtr::ReallocateModelFile(void))
# and walk_window.map line 10683 carried
#   ?ReallocateModelFile@SharedFilePtr@@QAEXXZ   gx_upload_bridge.cpp.obj
# Both are public __thiscall f(void): receiver in ecx, no stack argument,
# callee cleans zero bytes, and the only difference is an eax the void-spelling
# caller never reads. hal/method_faces.cpp carries the one /alternatename.
#
# WHAT IS RETIRED, AND WHERE IT IS NOT. The empty method goes behind
# #ifndef SM64DS_SFP_REALLOC_ROM, which smoke_player, walk_window and
# walk_window_hires define -- the three targets that carry this slice AND
# slice_gate16.txt. The other ten harnesses link the CALLER (slice_gate4b) with
# no func_02017060 under it, so there the empty body is still the only
# definition there can be. A defined ?...@@QAEXXZ would also defeat the alias
# silently, which alternatename_guard.py refuses.
#
# THE SHRINK GOES LIVE ON THIS PATH, stated rather than hidden. The empty body
# was not only standing in for the ROM's body, it was declining the ROM's work.
# Model::LoadFile's numRefs==1 branch now performs the real shrink; the other
# model path (src/func_02016ff4.cpp, patched by hostgen) keeps its
# port_model_shrink_enabled gate and still declines by default, so the two
# halves now differ and hostgen's switch is the A/B for the second one. This
# rung's battery, its eight proofs and its level-1 capture all ran with the
# shrink live.
#
src/_ZN13SharedFilePtr19ReallocateModelFileEv.cpp
