Worked example · Reverse engineering
Matching decompilation with Whiplash Driven Development
Matching decompilation is the task WDD grew up on: each function has a perfect, automatic check (does the compiled output match the original bytes?), so an agent can be pushed through thousands of small attempts without a person judging each one.
The goal
Rewrite one function from a disassembled binary as C source that compiles, with the original compiler and flags, to byte-identical machine code.
The verifier
A diff tool that compiles the function and compares it with the original (the project's own match script, or a tool such as objdiff or asm-differ).
Why this check: It gives a number (percentage matched) as well as a pass or fail, so the agent can see whether an edit brought it closer.
The set-up
- A project with the original compiler, its exact flags and a build that produces object files to compare.
- A list of functions still to do (TODO.md), smallest first.
- Standing orders that forbid inline assembly and any shortcut the project rules do not allow.
- A loop script that runs the agent, then the match check, and commits each function that reaches 100%.
The kickoff prompt
Kickoff
Decompile the function at the top of TODO.md into C that compiles to byte-identical output. Check with the match script; it must say 100%. Work by small edits, log every attempt and its score in NOTES.md, and move to the next function when it matches. Make no mistakes.
How the rounds went
- Rounds 1 to 3
- The agent writes a plausible first version from the disassembly. It compiles and matches 71%: the logic is right, the register use is not.
- Rounds 4 to 9
- Pushed with "not quite my tempo" and the diff, it tries the usual compiler idioms: swapping loop forms, changing a signed type to unsigned, splitting a temporary. The score climbs to 96%.
- Round 10
- Stuck at 96% for three rounds, the push changes from "keep going" to "step back": the agent lists three explanations and finds the original declared a local in a different order. 100%.
What worked
- A numeric score, not only pass or fail, so every round shows direction.
- Small functions first: early wins build NOTES.md, a growing list of idioms that work for this compiler.
- Committing each match at once, so nothing is lost when a later round goes wrong.
What to watch for
- Agents will reach for inline assembly or compiler pragmas to force a match. Forbid them in AGENTS.md and check the diff.
- A loop stuck on one function burns the budget: cap the rounds per function and move on.
- Only work on code you have the right to work on.
Build a kit for a task like this
A worked example written to show the method, not a report of a specific project.
Questions people ask
Why does decompilation suit WDD so well?
Because the check is perfect and automatic: the bytes match or they do not. That lets the human step out of the loop and the agent grind through many small attempts.
How many rounds does one function take?
Small functions often match in a few rounds; awkward ones can take dozens. Cap the rounds per function so one stubborn case does not eat the budget.