# fast-decomp and Ghidra, measured This page compares fast-decomp with [Ghidra](https://github.com/NationalSecurityAgency/ghidra), the reference open-source decompiler, on the same x86-64 programs, without symbols or debug information (the case of a game being modded). It says where fast-decomp is ahead, where Ghidra is, and what was not measured. Every number comes from the runs described here: Ghidra's made on 2026-11-24, fast-decomp's made again on 2026-11-25 with its current version; the raw results are summarised in [benchmark-results.json](benchmark-results.json), and [Reproduce](#reproduce) gives the commands. ## Summary Whole-program decompile time on a logarithmic axis, fast-decomp against Ghidra 12.2; the numbers are in the table below. | Input | Ghidra 12.2: wall time to every function's text, peak memory, functions with text | fast-decomp: the same | | --- | --- | --- | | SQLite (gcc -O2, ELF, stripped) | 94 s, 1.9 GB, 1,077 | 0.41 s, 97 MB, 1,646 | | Lua (gcc -O2, ELF, stripped) | 36 s, 1.7 GB, 567 | 0.18 s, 45 MB, 778 | | SQLite (mingw, PE) | 253 s, 5.0 GB, 2,162 (1 timed out) | 0.47 s, 105 MB, 2,188 | | OpenTTD 14.1 (MSVC, PE) | 27 min on one decompiler thread (six exceeded the 8 GB cap), 5.4 GB (4.9 GB anonymous), 44,851 (6 timed out) | 6.4 s, 1.0 GB (0.3 GB anonymous), 112,712 | | Godot 4.3 editor (mingw, PE) | no text: the analysis hit the 8 GB cap in one run and stopped on an internal error after 6 h 28 min in another | 28 s, 2.5 GB (0.9 GB anonymous), 137,813 | Peak memory is the cgroup's peak for the whole process tree: it includes the page cache of the files the run wrote (fast-decomp's Godot export is 0.8 GB of text); the anonymous memory (heaps and stacks) is given where the run was long enough to sample it. - **Speed and memory**: fast-decomp is 201 to 543 times faster on the whole program, uses 5 to 48 times less memory, prints its first function after 0.40 s on SQLite and 22.8 s on Godot (Ghidra: 69 s and none), then answers per function with a median 15 to 22 times lower. - **Functions found**: on stripped ELF files fast-decomp prints 99.9 % of the symbol starts as functions, Ghidra's decompile-all 64 to 70 %: Ghidra disassembles the other starts (all 581 on SQLite, all 212 on Lua) but creates no function at most of them (578 and 206), mostly functions reached only through pointers, so it prints no text for them; in its GUI a user creates each such function by hand. On OpenTTD the two tools have 44,775 functions in common; fast-decomp's other 67,937 are mostly leaf functions of a few instructions (median 12 bytes, 0.98 MB of code together, against 9.7 MB for the common ones). - **Signatures and C++**: fast-decomp has more parameter counts right (97.8 % against 95.3 % on SQLite, 98.9 % against 92.5 % on Lua) and recovers classes, methods and virtual calls from the RTTI and vtables (6,875 functions of OpenTTD attributed to a class, Ghidra none of OpenTTD's own). - **Correctness**: in 30 functions read against their source, Ghidra printed 9 wrong statements in 9 functions (all missing call arguments). fast-decomp's first measurement printed 6 in 2; the three defects behind them were fixed, and the current texts (27 of the 30 changed since) read again find none (see [Defects this benchmark found in fast-decomp](#defects-this-benchmark-found-in-fast-decomp)). - **Independent reviews**: a separate model instance compared the two texts of 14, then 14 again, then 20 other functions against the source and the machine code without knowing which tool wrote which. On fresh functions it preferred fast-decomp's text in 15 of 20 and Ghidra's in 3; in the first review, before a fix and the readability work, it had preferred Ghidra's in 10 of 14. It found 22 wrong statements in Ghidra's texts of the fresh sample and none in fast-decomp's (see [Independent reviews](#independent-reviews): small samples, one reviewer model). - **Where Ghidra is better**: its text has fewer C tokens on every input (fast-decomp 2 to 23 % more), fewer lines on three of the six and fewer casts on four, fewer `goto`s on Lua and OpenTTD, it prints fewer values for `void` functions, it names library functions by their bytes, and it does much that fast-decomp does not do at all (other architectures, x87 and AVX-512, a GUI and a debugger, type libraries). The details are in [Where Ghidra is better](#where-ghidra-is-better). - **Not measured**: readability judged by people; the model reviews above are small. ## What was compared **Tools.** fast-decomp 0.1.0 at commit `6ce5878` (`main`, 2026-11-25), release build (`cargo build --release`, Rust 1.100). Two earlier versions were measured the same way: the first measurement at `720f557`, and `58d74b8`, which fixed the three defects that measurement found (see [Defects this benchmark found in fast-decomp](#defects-this-benchmark-found-in-fast-decomp)); since `58d74b8` a fix of the un-threading pass and three readability packages (call arguments; expressions and types; the shape of the control flow) changed the text. Ghidra's side was measured once, on 2026-11-24, and was not re-run: its numbers are its kept results; the fast-decomp lanes, the comparisons and measure 7's re-read were made again with `6ce5878`. Ghidra 12.2 (`ghidra_12.2_PUBLIC_20261016.zip`, SHA-256 `2c2cd776db3c1f6a097ba418922378ac3649cadd5e844a6f5f088ae628a7be67`, as stated on the release page) on Eclipse Temurin JDK 25.0.5.1+2 (Ghidra 12.2 requires Java 25). **Machine.** A 6-core x86-64 virtual machine (Intel, Haswell generation, one thread per core), 11 GB of memory, Linux 6.12, no other work running; runs one after the other, never two at once. The load average at the start of each run is in the results file: 0.3 to 2.3 for Ghidra's runs, from the run just before; 1.8 to 3.5 for fast-decomp's, which ran one right after another and after the `bench` runs (one minute's load of a sequence of short runs, not concurrent work). **Inputs.** Both tools read exactly the same file. The ELF inputs are `strip` copies of corpus binaries (no `.symtab`, no debug information); the PE inputs have no PDB next to them, and neither tool found one (Ghidra: `Skipping PDB processing: failed to locate PDB file`; fast-decomp `info`: `debug names none`). | Input | From the corpus | File | Bytes | SHA-256 | | --- | --- | --- | ---: | --- | | `m` | `small/m-gcc-O2` (the test program `m.c`, gcc -O2) | `strip` copy | 14,512 | `8f14a4b9…ab6a6` | | `cpp` | `small/cpp-gcc-O2` (the C++ test program `cpp.cpp`, g++ -O2) | `strip` copy | 23,056 | `e9d2451c…f8637` | | `sqlite` | `bin/sqlite-gcc-O2` (SQLite 3.54.1, gcc -O2, ELF) | `strip` copy | 1,137,840 | `bb7855a0…a1a094` | | `lua` | `bin/lua-gcc-O2` (Lua 5.4.7, gcc -O2, ELF) | `strip` copy | 269,144 | `57457065…779513` | | `sqlite-pe` | `bin/sqlite-pe-O2.exe` (SQLite, mingw -O2, PE) | copy, PDB withheld | 1,370,624 | `2528dbef…ca937` | | OpenTTD | `big/openttd-msvc.exe` (OpenTTD 14.1, MSVC, official release) | the file | 15,112,712 | `d8ef27fb…fd23434` | | Godot | `big/godot-win64.exe` (Godot 4.3 editor, mingw, official release) | the file | 132,918,392 | `b554ba80…ee32f` | The full SHA-256 of each file is in the results file. **The Ghidra lane** (`scripts/bench/run.py ghidra`): `analyzeHeadless PROJECT fdbench -import FILE -preScript FdBenchMark.java ... -postScript FdBenchDecompile.java ... -deleteProject`, with default auto-analysis (no analyzer switched on or off, no analysis timeout). The options set, all of them: - `GHIDRA_HEADLESS_MAXMEM=5G` on the small inputs, `3G` on OpenTTD and Godot: the Java heap. Ghidra's default for headless runs is 2 GB; the heap was set so that the JVM and the native decompiler processes fit in the 8 GB cap, and lowered to 3 GB after the first OpenTTD and Godot runs were killed by the cap (measure 1 lists every run). One labelled run on SQLite uses the 2 GB default. - `GHIDRA_HEADLESS_JAVA_OPTIONS=-Djava.io.tmpdir=RUN/tmp`: temporary files beside the run. - The run is in its own cgroup with an 8 GB memory cap and no swap (`systemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0`) and a wall-clock limit (2 h for the small inputs; 4 h for OpenTTD, 10 h for Godot). `FdBenchMark.java` runs after the import and before the analysis and records the time. `FdBenchDecompile.java` runs after the analysis: it decompiles every function of the program (`FunctionManager.getFunctions(true)`) with Ghidra's parallel decompiler API (`ParallelDecompiler`, the API of Ghidra's own C/C++ exporter) on 6 threads (1 in the OpenTTD run that finished, after 6 and 3 exceeded the cap), with default decompiler options (`DecompileOptions` read from the program) and the default per-function timeout (`getDefaultTimeout()`: 30 s); it writes each function's C and records, per function, its entry, its status (text, failed, timed out, with Ghidra's message) and the time of its `decompileFunction` call. In the same JVM it decompiles the sample of measure 2 on one thread: after decompile-all on the small inputs, before it on OpenTTD and Godot (so that the sample exists even if decompile-all is stopped; its time is then not counted in the totals). Functions Ghidra places in its `EXTERNAL` block (the imported symbols of an ELF file, which are not code of the file) are decompiled but not counted below. **The fast-decomp lane** (`scripts/bench/run.py fd`): `fast-decomp export FILE --out DIR --jobs 6 --no-project`, which writes every function's text, the index files and the data index, in its own cgroup with a 6 GB cap. The phase split comes from a separate `fast-decomp bench --json --jobs 6` run (it runs the same pipeline without writing files). **How time and memory are read**, the same way for both (`scripts/bench/measure.py`, which runs inside the run's cgroup and starts the tool): wall time from the start of the tool's process; CPU time and peak memory from the cgroup, that is, the whole process tree (Ghidra: the JVM and its native decompiler processes; fast-decomp: its one process). Peak memory is the cgroup's `memory.peak`, which counts the anonymous memory of the tree and the page cache of the files it wrote during the run (Ghidra's project database and its C output, fast-decomp's export). For Ghidra the times and the peak are read when decompile-all ends (the sample of measure 2 and the JVM's exit are not counted); for fast-decomp at the process's exit. The file was read once before each run, so both start with it in the page cache. ## Results ### 1. The whole program From nothing to every function's text: Ghidra's import, auto-analysis and decompile-all against fast-decomp's `export`. Small inputs: three runs each, the minimum and the range; OpenTTD and Godot: one finished run each (the runs that did not finish are in the next table). | Input | Tool | Functions | With text / failed / timed out | Wall time (s) | Phases (s) | CPU (s) | Peak memory | | --- | --- | ---: | --- | ---: | --- | ---: | ---: | | `m` | Ghidra | 34 | 34 / 0 / 0 | 13.3 (13.3–15.3) | JVM start and import 7.5, analysis 4.3, decompile 1.5 | 21.0 | 422 MB | | | fast-decomp | 33 | 33 / 0 / 0 | 0.01 (0.01–0.01) | | 0.03 | 10 MB | | `cpp` | Ghidra | 58 | 58 / 0 / 0 | 13.6 (13.6–14.1) | 7.3, 4.7, 1.6 | 23.1 | 487 MB | | | fast-decomp | 66 | 66 / 0 / 0 | 0.02 (0.02–0.02) | | 0.04 | 12 MB | | `sqlite` | Ghidra | 1,077 | 1,077 / 0 / 0 | 94.3 (94.3–97.0) | 7.6, 59.3, 26.5 | 230 | 1,932 MB | | | fast-decomp | 1,646 | 1,646 / 0 / 0 | 0.41 (0.41–0.43) | discovery 0.02, functions 0.33, the rest 0.01; writing 0.05 | 2.07 | 97 MB | | `lua` | Ghidra | 567 | 567 / 0 / 0 | 36.2 (36.2–37.5) | 7.8, 21.6, 6.1 | 74.1 | 1,708 MB | | | fast-decomp | 778 | 778 / 0 / 0 | 0.18 (0.18–0.20) | 0.02, 0.14, 0.01; 0.01 | 0.65 | 45 MB | | `sqlite-pe` | Ghidra | 2,163 | 2,162 / 0 / 1 | 253 (253–262) | 8.8, 209, 35.5 | 550 | 5,050 MB | | | fast-decomp | 2,188 | 2,188 / 0 / 0 | 0.47 (0.47–0.50) | 0.03, 0.40, 0.01; 0.02 | 2.40 | 105 MB | | OpenTTD | Ghidra, 1 decompiler thread | 44,857 | 44,851 / 0 / 6 | 1,637 | 22.7, 584, 1,030 | 2,348 | 5,356 MB | | | fast-decomp | 112,712 | 112,712 / 0 / 0 | 6.4 | 0.35, 3.36, 0.23; 2.51 | 31.1 | 1,006 MB | | Godot | Ghidra | no text | no function decompiled: the auto-analysis did not complete (below) | | import 42 s, then 6 h 28 min of analysis | 27,772 | 8,192 MB (the cap) | | | fast-decomp | 137,813 | 137,813 / 0 / 0 | 28.4 | 1.21, 19.3, 1.6; 6.2 | 141 | 2,481 MB | fast-decomp's phases are from `bench --json` (its own phase timers: discovery; the function phase with return demand's second pass; names, statics, the class model, the structure merge and the end of the run as "the rest"), then the time `export` adds to write the files (the difference of the two wall times). Its "functions" count all of `functions --json` (import thunks included); fast-decomp prints a text for every function (no internal error, no flat fallback: `state ok`, or `likely-withdrawn` for a text whose guesses were taken back, 1 on SQLite, 17 on OpenTTD and 12 on Godot). The peak memory includes the page cache of the files written (fast-decomp's Godot export is 0.8 GB of text; its anonymous memory peaked at 909 MB, `bench`'s peak RSS was 1,054 MB). measure.py's own share is 7 MB and 4 ms of CPU (a run of `true`). **The large inputs.** Ghidra was killed by the 8 GB cap on both large programs, every run listed: | Run | Heap | Decompiler threads | Outcome | | --- | --- | ---: | --- | | OpenTTD 1 | 5 GB | 6 | analysis finished (546 s); killed by the cap in decompile-all | | OpenTTD 2 | 5 GB | 3 | analysis finished (569 s); killed by the cap in decompile-all | | OpenTTD 3 | 3 GB | 6 | analysis finished (564 s); killed by the cap 35 s into decompile-all, after starting 921 functions | | OpenTTD 4 | 3 GB | 1 | finished (the row above) | | Godot 1 | 5 GB | 6 | killed by the cap 18 minutes into the auto-analysis | | Godot 2 | 3 GB | 6 | the auto-analysis ran for 6 h 28 min (1.2 cores busy on average), then Ghidra stopped with `ERROR REPORT: Can't checkpoint with locked buffers (1 locks found)` (an `AssertException` when the analysis transaction ended) and `Import failed`; the post-script never ran, no function was decompiled | The memory record of OpenTTD 3 (`measure-memory.tsv`, every 2 s) shows why: during the analysis the JVM held 2.5–2.9 GB; when decompile-all started, each of the six native `decompile` processes grew by about 60 MB/s, to 1.2–1.3 GB each within 18 s, and the cgroup reached 8 GB. With one thread the single decompiler process reached 2.35 GB at most, the JVM 2.8 GB, and the run's anonymous memory 4.9 GB. Ghidra's default heap for headless runs is 2 GB: on SQLite a run with it took 92.0 s (94.3 s with 5 GB) and peaked at 1,373 MB instead of 1,932 MB; the heap changes Ghidra's memory, not its speed. On Godot the first run's cap was reached during the analysis, while the native decompilers of the "Decompiler Switch Analysis" ran beside the JVM; in the second, the anonymous memory peaked at 7.4 GB 19 minutes in, then stayed between 2 and 3.5 GB; thread dumps taken from 1 h 44 min to 6 h 15 min into the run all showed the "Non-Returning Functions - Discovered" analyzer repairing code flow (`ClearFlowAndRepairCmd`), the last one before the end "Create Address Tables". A third run would have needed more than the 3.5 hours left of the 10-hour limit: none was made. So Ghidra produced no text for Godot on this machine, and Godot is missing from the Ghidra side of measures 2 to 6; its example in measure 8 comes from a separate run without auto-analysis. **What is counted as Ghidra's functions** differs on the large inputs: Ghidra's auto-analysis created 44,857 functions on OpenTTD where fast-decomp found 112,712 (measure 3 says what the others are). The decompile times are for those. ### 2. Interactive use What an agent working in a loop waits for: the first function's text, then one function at a time. Ghidra's first text comes after the import, the whole auto-analysis and one decompile; fast-decomp's `serve` session answers its first `decompile` after analysing the whole program (every function's pipeline, the class model, the data index); a one-shot `fast-decomp decompile` analyses the whole program first on images of at most 25,000 functions and only the function and its callees above that (OpenTTD, Godot: its header then says the text is local). Per-function latency: the same sample for both, 1,000 functions (seeded, `fdbench-2026-11-24`, among the entries both tools have; all of them on the small inputs), timed one at a time: Ghidra's `decompileFunction` in the same JVM after the analysis (one thread; on the small inputs after decompile-all, on OpenTTD and Godot before it), fast-decomp's `serve` `decompile` request round trip. | Input | Ghidra: first text | fast-decomp: `serve`, first text / one-shot `decompile` | Ghidra per function (ms): median / p90 / p99 / max | fast-decomp per function (ms) | | --- | ---: | ---: | --- | --- | | `m` (31 functions) | 13.2 s | 0.01 / 0.01 s | 3.5 / 7.9 / 14.8 / 14.8 | 0.20 / 0.33 / 0.44 / 0.44 | | `cpp` (55) | 13.4 s | 0.02 / 0.02 s | 2.7 / 10.2 / 104 / 104 | 0.16 / 0.53 / 4.1 / 4.1 | | `sqlite` | 68.7 s | 0.40 / 0.37 s | 11.1 / 70.1 / 1,128 / 17,475 | 0.57 / 2.1 / 15.7 / 79.1 | | `lua` (565) | 31.1 s | 0.22 / 0.17 s | 5.8 / 19.9 / 85.6 / 2,712 | 0.34 / 0.79 / 2.0 / 68.6 | | `sqlite-pe` | 219 s | 0.47 / 0.46 s | 9.7 / 64.5 / 958 / 9,975 | 0.45 / 1.6 / 11.3 / 30.9 | | OpenTTD | 608 s | 4.6 / 0.51 s (local) | 9.5 / 29.4 / 234 / 1,726 | 0.65 / 1.05 / 3.4 / 8.7 | | Godot | none after 6 h 28 min | 22.8 / 2.4 s (local) | - | 1.2 / 2.2 / 8.5 / 15.2 (sample drawn from fast-decomp's entries alone) | The interactive gap is the large one: Ghidra's first text waits for the analysis of the whole program (68 s on SQLite, 10 minutes on OpenTTD); after that, a function takes milliseconds in both, with Ghidra's median 15 to 22 times fast-decomp's on the inputs of more than a thousand functions, and its slowest functions taking seconds. **Labelled variants** (one option changed from Ghidra's defaults; the tables above are the defaults). "Decompiler Parameter ID" is an analyzer that Ghidra 12.2 runs by default on the small PE input (90 s of its 217 s of analysis on `sqlite-pe`) but not on ELF files or on OpenTTD; turned on for the ELF inputs, it took SQLite from 94 s to 152 s (analysis 106 s instead of 59 s), Lua from 36 s to 43 s; its effect on the text is in measures 4 and 7. The 2 GB default heap on SQLite: 92.0 s and 1,373 MB. ### 3. Function discovery **Against ground truth** (the stripped ELF inputs; truth: the `FUNC` symbols of the unstripped file, one start per address; `scripts/bench/compare.py`). gcc's `.cold` parts (code split off a function, with their own symbol) are counted apart: fast-decomp prints them inside their parent function (checked: `0xa300`, `sqlite3_db_status64.cold`, is part of `sub_26600`'s text). Import stubs in `.plt` have no symbol after `strip` and are not counted either way. "Missed" is classified by how the start can be reached: the target of a direct call or jump in the code, an address stored in data (an `R_X86_64_RELATIVE` relocation: a function pointer in a table), or neither. What Ghidra has at the starts it made no function of comes from a second run of its default analysis with a post-script (`run.py ghidra-missed`, `FdBenchMissed.java`) that records, for each one, whether Ghidra has an instruction there and a function containing it. | Input | Symbol starts (of which `.cold`) | Tool | Found, without `.cold` | Missed, without `.cold` | Missed: reached by a direct call or jump / only from data / neither | Starts that are not symbol starts | | --- | ---: | --- | ---: | ---: | --- | ---: | | `m` | 28 (1) | fast-decomp | 26 of 27 (96.3 %) | 1 | 1 / 0 / 0 | 0 | | | | Ghidra | 25 (92.6 %) | 2 | 0 / 0 / 2 | 1 | | `cpp` | 37 (4) | fast-decomp | 32 of 33 (97.0 %) | 1 | 1 / 0 / 0 | 1 | | | | Ghidra | 24 (72.7 %) | 9 | 0 / 8 / 1 | 1 | | `sqlite` | 1,637 (33) | fast-decomp | 1,603 of 1,604 (99.9 %) | 1 | 1 / 0 / 0 | 0 | | | | Ghidra | 1,023 (63.8 %) | 581 | 18 / 484 / 79 | 2 | | `lua` | 703 (7) | fast-decomp | 695 of 696 (99.9 %) | 1 | 1 / 0 / 0 | 0 | | | | Ghidra | 484 (69.5 %) | 212 | 12 / 156 / 44 | 0 | Ghidra's missed starts, from the second run: | Input | Missed, without `.cold` | Disassembled, no function at or around the start | Disassembled, inside another function | Not disassembled | With references to the start | | --- | ---: | ---: | ---: | ---: | ---: | | `sqlite` | 581 | 578 | 3 | 0 | 581 | | `lua` | 212 | 206 | 6 | 0 | 212 | So Ghidra does not fail to see this code: its analysis disassembles every one of these starts and records references to it, but creates no function there, which is why decompile-all prints no text for it (in its GUI a user creates the function with one key). The percentages above are what a decompile-all of the whole program gives. Of the `.cold` parts themselves, fast-decomp has a separate start for none (it prints them in their parent), Ghidra for 9 of 33 on SQLite and 0 of 7 on Lua. The starts that are not symbol starts, all of them classified by hand with `objdump`: | Input | Tool | Address | Where | What it is | | --- | --- | --- | --- | --- | | m | Ghidra | 0x1a94 | `parse_int` + 0x14 | real code inside `parse_int` (a loop head), not a function start | | cpp | fast-decomp | 0x3a39 | `safe_parse` + 0x9 | real code inside `safe_parse`: the return point of its call to `parse_positive` (the function was split there) | | cpp | Ghidra | 0x227a | `parse_positive.cold` + 0x28 | real code inside the `.cold` part: an exception landing pad | | sqlite | Ghidra | 0x7216a | `sqlite3ExprCompareSkip` + 0x1a | real code inside the function (a loop condition) | | sqlite | Ghidra | 0xcce4 | `sqlite3ExprCanBeNull` + 0x14 | real code inside the function (a loop body) | The one non-`.cold` start fast-decomp misses in each ELF input is `register_tm_clones`, a C runtime helper that `frame_dummy` reaches by a jump; fast-decomp prints it inside `frame_dummy`. The starts at which Ghidra creates no function are mostly those reached only through function pointers (SQLite's method tables, Lua's library registration arrays): 484 of the 581 on SQLite. **On the PE inputs** (no ground truth: no symbols, and the PDB of `sqlite-pe-O2.exe` withheld from both), the counts and the overlap of the two start sets, with a sample of each tool's exclusive starts classified by hand (twelve per tool, or all when fewer): | Input | fast-decomp | Ghidra | Both | Only fast-decomp | Only Ghidra | | --- | ---: | ---: | ---: | ---: | ---: | | `sqlite-pe` | 2,188 | 2,163 | 2,159 | 29 | 4 | | OpenTTD | 112,712 | 44,857 | 44,775 | 67,937 | 82 | | Godot | 137,813 | no output | | | | | Input | Exclusive starts of | Sample classified by hand | | --- | --- | --- | | `sqlite-pe` | fast-decomp (29) | 12 of 12: import thunks (`jmp [IAT]`) that Ghidra did not make functions | | | Ghidra (4) | 4 of 4: import thunks that fast-decomp did not list | | OpenTTD | fast-decomp (67,937) | 12 of 12: real code, small leaf functions of 1 to 5 instructions ending in `ret` (accessors, field stores) between `int3` padding. By how fast-decomp found them: 62,336 by its scan of the gaps between known functions (53,462 of them under 16 bytes), 2,842 from unwind records (`.pdata`), 1,703 from code references, 1,002 from pointers in data, 54 other. Together 0.98 MB of code (median 12 bytes) | | | Ghidra (82) | 12 of 12: real code that fast-decomp prints inside another function: 7 five-byte `jmp` stubs that follow a function and that fast-decomp prints as that function's tail, 5 small functions reached by a jump that fast-decomp includes in the jumping function | ### 4. Signatures against the source The method of `scripts/sig.py`, applied to both outputs: every function with a unique definition in the C source (SQLite's amalgamation, Lua 5.4.7, `m.c`; local clones such as `.isra.0` skipped) whose symbol start both tools printed. The printed declaration of each text is parsed (`compare.py`, `parse_decl`): the parameter count (`void` and `()` are 0, `...` is not counted) and whether the result is `void`. Functions Ghidra did not find are not in the comparison (on SQLite, 870 of the 1,604 functions fast-decomp printed). | Input | Compared | Parameter count exact: fast-decomp / Ghidra | `void` or value right: fast-decomp / Ghidra | fast-decomp: `void` for a value / a value for `void` | Ghidra: the same | | --- | ---: | --- | --- | --- | --- | | `m` | 16 | 16 / 16 | 16 / 16 | 0 / 0 | 0 / 0 | | `sqlite` | 870 | 851 (97.8 %) / 829 (95.3 %) | 840 (96.6 %) / 833 (95.7 %) | 9 / 21 | 27 / 10 | | `lua` | 441 | 436 (98.9 %) / 408 (92.5 %) | 418 (94.8 %) / 401 (90.9 %) | 10 / 13 | 39 / 1 | | `cpp` (by hand, the 6 functions of `cpp.cpp`) | 6 | 6 / 5 | 5 / 5 | 1 / 0 | 1 / 0 | On the C++ test program the six functions were compared by hand (`sig.py` reads C): | Function | Source | fast-decomp | Ghidra | | --- | --- | --- | --- | | `total_area` | `double (1)` | `double sub_3190(struct s_3190_0 *a1)` | `double FUN_00103190(undefined8 *param_1)` | | `count_words` | `int (2)` | `int32_t sub_31e0(struct s_31e0_0 *a1, uint64_t a2)` | `int FUN_001031e0(long *param_1,long param_2)` | | `parse_positive` | `int (1)` | `void sub_39b0(struct s_39b0_0 *a1)` | `ulong FUN_001039b0(long *param_1)` | | `safe_parse` | `int (1)` | `uint64_t sub_3a30(struct s_39b0_0 *a1)` | `void FUN_00103a30(void)` | | `clamp_sum` | `int (3)` | `int32_t sub_3b60(struct s_3b60_0 *a1, int32_t a2, int32_t a3)` | `int FUN_00103b60(undefined8 *param_1,int param_2,int param_3)` | | `clamp_sum` | `double (3)` | `double sub_3bc0(struct s_3bc0_0 *a1, double a2, double a3)` | `double FUN_00103bc0(double param_1,double param_2,undefined8 *param_3)` | Variadic functions: the source has 18 on SQLite and 4 on Lua; fast-decomp printed `...` for 15 and 3, Ghidra for none. Ghidra wins when fast-decomp prints a value for a `void` function (21 on SQLite: callbacks and API functions whose callers are not all known keep the value `rax` happens to hold, a known limit of fast-decomp) and on `parse_positive` of the C++ test program (fast-decomp guesses `void` there: the discovery split `safe_parse` at the return point of the call, measure 3, so the caller that reads the result is a separate function; the text drops no computation, `return;` replaces `return v;`); fast-decomp wins on the parameter counts and on Ghidra's `void` for functions that return a value. With "Decompiler Parameter ID" on (the labelled variant), Ghidra's exact parameter counts fall to 424 of 870 on SQLite and 218 of 441 on Lua: it then adds the floating-point argument registers to many integer functions. ### 5. Text counters Over the functions both tools printed (not thunks or imports), each function's declaration and body. fast-decomp's comment header and the structure declarations it prints before a function, and Ghidra's comment lines before its declaration, are not counted, except Ghidra's warnings. These counters describe the text; they are not a readability verdict (a cast that states a width is information to one reader and noise to another); a model's judgement of readability is in [Independent reviews](#independent-reviews). | Input | Functions | Lines: fast-decomp / Ghidra | C tokens | `goto`s | Without a `goto` | Casts | | --- | ---: | --- | --- | --- | --- | --- | | `m` | 22 | 363 / 401 | 2,189 / 2,034 | 0 / 1 | 22 / 21 | 85 / 44 | | `cpp` | 24 | 1,197 / 994 | 7,434 / 6,038 | 55 / 62 | 21 / 19 | 294 / 236 | | `sqlite` | 1,020 | 136,991 / 115,669 | 1,020,303 / 926,979 | 5,166 / 5,278 | 561 (55.0 %) / 524 (51.4 %) | 47,817 / 45,105 | | `lua` | 481 | 26,051 / 22,840 | 190,424 / 170,310 | 1,039 / 994 | 392 (81.5 %) / 343 (71.3 %) | 7,392 / 7,753 | | `sqlite-pe` | 2,087 | 207,779 / 213,917 | 1,747,966 / 1,710,039 | 5,465 / 5,871 | 1,377 (66.0 %) / 1,311 (62.8 %) | 70,868 / 91,525 | | OpenTTD | 44,465 | 1,586,568 / 1,609,350 | 11,537,459 / 11,189,039 | 14,233 / 13,559 | 41,087 (92.4 %) / 40,831 (91.8 %) | 504,793 / 413,070 | A cast is a parenthesised type (a C or tool type name, a `struct`, or anything with a `*`) before an operand. fast-decomp's text has more C tokens than Ghidra's on every input (1.02 to 1.23 times); it has more lines on SQLite, Lua and the C++ test program (1.14 to 1.20 times) and fewer on `m.c`, SQLite's PE build and OpenTTD (0.91 to 0.99 times); more casts on four inputs (1.06 to 1.9 times) and fewer on Lua and SQLite's PE build (0.95 and 0.77 times). `goto`s: fast-decomp prints fewer than Ghidra on `m.c`, the C++ test program, SQLite and SQLite's PE build, and more on Lua (1,039 against 994) and OpenTTD (14,233 against 13,559); it has more functions without any `goto` on every input. The version measured before (`58d74b8`) printed fewer `goto`s than Ghidra on every input (Lua 969, OpenTTD 12,217, SQLite 4,527). The change is the control-flow package's: a cleanup or exit that several paths share, longer than a `return` and one statement, is now written once behind a label that the other paths jump to, as a source's `goto cleanup;` does, where it was copied into each path before. On these functions, with the other packages, fast-decomp's lines went from 157,912 to 136,991 on SQLite (28,065 to 26,051 on Lua, 1,682,763 to 1,586,568 on OpenTTD) and its `goto`s from 4,527 to 5,166. Each tool's own artifacts, counted separately (occurrences, and in parentheses the functions that contain one): | Ghidra | `sqlite` | `lua` | `sqlite-pe` | OpenTTD | | --- | ---: | ---: | ---: | ---: | | `undefined1`...`undefined8` types | 11,649 (872) | 2,624 (389) | 22,107 (1,583) | 310,942 (36,136) | | `CONCAT`, `SUB`, `ZEXT`, `SEXT` | 356 | 68 | 1,825 | 15,570 | | `CARRY`/`SCARRY`/`SBORROW` | 6 (3) | 3 (3) | 183 (60) | 60 (20) | | `extraout_` / `unaff_` / `in_` variables | 155 / 0 / 38 | 21 / 0 / 20 | 2,534 / 31 / 417 | 433 / 386 / 5,213 | | `halt_baddata()` | 0 | 0 | 0 | 2 (1) | | warnings in comments (`/* WARNING`) | 160 (75) | 172 (92) | 366 (168) | 23,150 (12,400) | | calls through raw pointer arithmetic (`(**(code **)(...))(`) | 418 (137) | 18 (9) | 707 (227) | 8,159 (4,135) | | fast-decomp | `sqlite` | `lua` | `sqlite-pe` | OpenTTD | | --- | ---: | ---: | ---: | ---: | | `__unknown(...)` (instructions without semantics: x87, MMX, AVX-512) | 0 | 11 (1) | 1,942 (41) | 16 (5) | | `__clobbered_*` reads | 565 (50) | 421 (9) | 835 (174) | 2,154 (1,012) | | `__unset(...)` arguments / `__undef*()` values | 67 / 4 | 26 / 5 | 264 / 0 | 775 / 97 | | `__noarg` (a position of a call the callee does not read) | 119 (49) | 16 (13) | 401 (83) | 3,942 (1,942) | | `VCALL`/`VTCALL` (a slot of an unknown class) | 215 (63) | 0 | 327 (102) | 5,889 (2,670) | | `__indirect_jump(...)` (unresolved) | 0 | 5 (1) | 1 (1) | 79 (71) | | `/* likely */` marks | 2,395 (560) | 548 (191) | 4,363 (824) | 14,059 (7,602) | | calls through raw pointer arithmetic (`((fn_t)*(...))(`) | 286 (99) | 0 | 1,811 (330) | 1,070 (489) | | flat fallbacks (`state internal-error`) | 0 | 0 | 0 | 0 | Against the version measured before (`58d74b8`), most of fast-decomp's placeholders left the argument lists (mostly the call-argument package's work): `__clobbered_*` reads 2,622 → 565 on SQLite (OpenTTD 2,218 → 2,154), `__unset(...)` 210 → 67 (OpenTTD 4,999 → 775), `/* likely */` marks 2,672 → 2,395 (OpenTTD 14,512 → 14,059); a position of an argument list that the callee does not read prints `__noarg`, new (119 on SQLite, 3,942 on OpenTTD), where the earlier text printed a register's leftover or an `__unset`. `VCALL`/`VTCALL` changed little (221 → 215 on SQLite, 5,944 → 5,889 on OpenTTD); calls through raw pointer arithmetic fell on SQLite (397 → 286) and rose on OpenTTD (964 → 1,070). ### 6. C++ on the game binaries Each count is defined by a pattern applied to each tool's output (`compare.py`, `cpp_counts`): **classes named**: fast-decomp's `classes.tsv` rows named from RTTI or a symbol; Ghidra's class namespaces (`SymbolTable.getClassNamespaces()`, outside its `EXTERNAL` namespace). **Functions attributed to a class**: a function whose printed name is `Class::method` for a class of that list (fast-decomp: the demangled name of `index.tsv`; Ghidra: a function in a class namespace). **Virtual call sites**: a call through a slot of the table at an object's first word, printed through a named class or slot (fast-decomp `p->vt->vf90_name(...)`; Ghidra: a named field of a vtable structure, `->vftable->...(`, `->_vptr...(`), or through a slot number or raw pointer arithmetic (fast-decomp `VCALL(p, k)`, `VTCALL(t, k)`; Ghidra `(**(code **)(*p + 0x48))(...)`); counted over every function's text, comments removed. **`this` typed**: a printed declaration whose `this` parameter has a class type (fast-decomp `struct C *this` for a class of `classes.tsv`; Ghidra `C *this` with `C` not `undefined`, `void` or an integer). | Count | OpenTTD: fast-decomp | OpenTTD: Ghidra | Godot: fast-decomp | Godot: Ghidra | | --- | ---: | ---: | ---: | ---: | | classes named | 1,133 | 1,267 | 8,518 | no output | | functions attributed to a class | 6,875 | 178 | 58,085 | no output | | virtual call sites through a named class or slot | 1,145 | 0 | 5,587 | no output | | virtual call sites through a slot number or raw pointer arithmetic | 6,214 | 6,493 | 30,266 | no output | | functions whose `this` has a class type | 5,858 | 157 | 49,162 | no output | On OpenTTD (MSVC), Ghidra's RTTI analyzer names 1,267 classes (namespaces holding the RTTI records and `vftable`s) but attributes no function of OpenTTD to them; its 178 class functions are library functions its Function ID analyzer recognised by their bytes (`std::_Lockit::_Lockit`, `std::ctype::~ctype`, the C runtime's `__crt_stdio_input::...`): 922 functions are named that way, with a `/* Library Function - Single Match ... */` comment. fast-decomp names no library function by its bytes; its class names come from the RTTI, the vtables (`Window::vf12` for a slot only the vtable knows) and, on Godot, the program's error-reporting strings. **Checked by hand** (`scripts/bench/cpp_sample.py`, seed `fdbench-cpp`, against the Godot 4.3-stable sources; read on the export of `720f557`, and the same draw from the current export gives the same 15 functions and 15 call sites): 15 Godot functions fast-decomp attributes to a class by a name from the program's strings, and 15 virtual call sites it prints through a named slot inside such functions. Functions: the class is right in 15 of 15, the method name in 14 (the 15th, `obstacle_set_map_command::_cmd_obstacle_set_map`, is `obstacle_set_map_command::exec` with the named method inlined into it). Call sites: the named slot is the virtual method the source calls there in 14 of 15 (two through an inlined helper: `get_system_menu` through `_get_rid_from_name`, `_font_set_variation_coordinates` through `_find_sys_font_for_text`); the 15th could not be checked, its caller being misnamed after an inlined `Variant::get_constructor_count`. Ghidra attributes no OpenTTD function to a class and prints no call through a named slot (and produced no output for Godot), so there was nothing of the same kind to check on its side; on OpenTTD, 5 of its Function ID names were read against their code (the `_Lockit` constructor, `allocator::deallocate`, the `ctype` destructor, `vector::erase`, a scalar deleting destructor): the code matches the named library functions (for the last one, the class name `MRECmpImpl` could not be checked). ### 7. Wrong statements, on 30 functions read by hand **Sample.** 20 SQLite functions and 10 functions of `small/m.c`, drawn by `scripts/bench/wrong_sample.py` (the smallest SHA-256 of `fdbench-wrong-statements:`) among the functions with a unique definition in the source that both tools printed at their symbol's address: for SQLite, those of 10 to 150 source lines (727 candidates); `m.c`'s functions are each written on one line, so all 17 candidates qualified. Both texts were read against the source with the same rule: a statement counts when it contradicts what the source does (a wrong constant, a dropped or invented side effect, a wrong condition, a wrong callee or argument); unknowns printed as unknowns, guesses marked as guesses, and missing names or types do not count. Calls whose callee is inlined were checked against the inlined code. | | fast-decomp, first measurement (`720f557`) | fast-decomp, fixed (`58d74b8`) | fast-decomp, current (`6ce5878`) | Ghidra | | --- | ---: | ---: | ---: | ---: | | `m.c`, 10 functions | none found | none found | none found | none found | | SQLite, 20 functions | 6 statements in 2 functions | none found | none found | 9 statements in 9 functions | | of which: an argument the callee reads is missing from the call | 3 (one callee, three calls) | 0 | 0 | 9 | | of which: a stack parameter read as if it were a pointer | 3 (one function) | 0 | 0 | 0 | No other kind of error was found in any text: no wrong constant, condition, side effect or callee. With the fixed version, 28 of the 30 fast-decomp texts were byte for byte those of the first measurement; the two that changed were read again against the source and the machine code: `btreeDropTable` now passes the `0` (`sub_c370(v1, v3, &local_48, 0) /* likely */`, and the same in the two other calls), and `sqlite3CompleteInsertion` declares `uint32_t a7, uint8_t a8, uint8_t a9` and reads `v1 = a8;`. The current version changed 27 of the 30 texts (all but `sqlite3ValueText`, `sw_sparse` and `kind_name`): conversions C makes itself no longer printed, byte arithmetic on addresses (`v15 = a5 + 8;`), loops with their test at the end written `do { } while`, cleanup code written once behind a label (`sqlite3GetCollSeq`, `pager_unlock`, `btreeDropTable`), `__noarg` for the argument positions a callee does not read. Each of the 27 was read again against the source and the machine code, by the same rule, every changed statement and every changed path: none has a wrong statement. Two guesses are gone (`sqlite3WhereRightJoinLoop` now calls `sqlite3WhereBegin` with exactly the source's eight arguments, `sub_941e0(v2, &local_88, local_c0, 0, 0, 0, 4096, 0)`, where the earlier text added a vector value; `sqlite3IdListDup` no longer has an unreachable second `return NULL;`), and one jump is new noise (`btreeEnterAll`: `goto continue_b10;` to the statement that follows, example 1). Every statement counted at the first measurement is listed with both texts in [the appendix](#appendix-the-statements-counted-in-measure-7). With "Decompiler Parameter ID" on (the labelled variant), Ghidra prints the missing arguments in 8 of the 9 places, but `btreeGetPage`'s calls lose their fourth argument there as they did in fast-decomp's first measurement, and it adds the eight floating-point argument registers as parameters to many functions (`FUN_00172780(param_1, ..., param_8, auStack_98, ...)`). ### Independent reviews Measure 7 was read by the person who measured, who works on fast-decomp. Three reviews were made by someone else: a separate instance of a language model, given for each function the C source, the two texts under neutral labels (decompiler A and decompiler B, the assignment drawn per function, each tool A in half of the functions, and the reviewer told that it changes), and the machine code (`objdump -d -M intel` of the unstripped build). It was told nothing about the tools or about which one anybody favours, was asked not to work out which tool wrote which text, and was asked, per function and with the same strictness for both texts: which statements contradict what the code does (wrong, as in measure 7), which are explicit unknowns or noise, what each text tells about the interface and types, how readable each is, and which text it would rather work from (A, B or no real difference; slightly or clearly), with the reason. It can recognise the two styles (`FUN_…`/`undefined8` against `sub_…`/`struct s_…`), so the reviews are not blind. The functions were drawn by seed among those of 15 to 120 source lines of SQLite and Lua (gcc -O2, ELF, stripped) that both tools printed, excluding those already read (measure 7's, and for the second sample the first review's): 8 SQLite and 6 Lua functions, then 12 and 8. Ghidra's texts are those of this page (Ghidra 12.2 at its defaults). Each review is one reviewer instance's report; the key was added to it afterwards. | Review | fast-decomp | Functions | Preferred: fast-decomp (of which clearly) / Ghidra (clearly) / no difference | Wrong statements: fast-decomp / Ghidra | | --- | --- | ---: | --- | --- | | First | before the un-threading fix and the three readability packages (the code of `58d74b8`) | 14 | 3 (2) / 10 (3) / 1 | 2 in 1 function / 3 in 3 functions | | The same 14 functions again | after them (`622430f`) | 14 | 5 (3) / 4 (0) / 5 | 0 / 5 in 4 functions | | 20 other functions | after them (`622430f`) | 20 | 15 (8) / 3 (0) / 2 | 0 / 22 in 11 functions | (`622430f`'s texts of these functions are those of `6ce5878`, which changed only the README.) The counts are the reviewers' own, recounted from their reports with the keys. In the re-review of the first 14, two of Ghidra's five wrong statements are in `exprCodeBetween`: a declared sixth parameter the function does not have, and four unmarked extra arguments passed to `exprDup`; the first review had noted the same two things as an error of information and as noise, not as wrong statements. **What the first review found.** In the hardest function, `sqlite3SubqueryColumnTypes`, fast-decomp's text had an endless loop that the code does not have, and the block that sets the BLOB affinity (reached from two places) printed under `// not reached from the entry:`: two wrong statements, which a reader would take for a function that hangs. The cause was the un-threading pass (the control-flow rewrites before structuring): two redirects, each right alone, were applied together and made a cycle. Counted over the corpus, the same defect made wrong text in 4 functions of the SQLite builds, 9 of Godot, 6 of node, 23 of bun and 1 of zig. It is fixed: each redirect is now proven on the graph all the rewrites make together, every run checks that the entry still reaches every block it reached before, and `selfcheck` also checks that every variable the text reads is assigned on every path to the read ([validity guide](guide/validity.md#how-it-is-checked); defect 4 in [Defects this benchmark found in fast-decomp](#defects-this-benchmark-found-in-fast-decomp)). The reviewer's other complaints were noise, which the three readability packages then took on: cleanup code and error tails copied into each exit (`sqlite3JoinType`'s error message three times, `sqlite3Vacuum`'s delete four times), unreachable code left after a `return`, absolute addresses printed as decimal numbers (`964242` for `0xeb692`), leftover registers passed as extra arguments (`/*out xmm1*/`, `__unset(xmm2)`), vector-register shuffles for two scalar stores (`v_shuffle64x2`), `(void)(v11 % v3);` statements. **What the reviewers still prefer in Ghidra's text.** Real case values in a `switch` where fast-decomp switches on `x - 7` with long `case 1: case 2: …` lists and an `__unreachable()` default (`sqlite3_file_control`); a flatter text with one error label where fast-decomp nests the body or repeats a store (`sqlite3PagerSetPagesize`); the source's single `if` where fast-decomp splits an exit into two `goto`s (`sqlite3Vacuum`); a clean inner `do … while` (`sqlite3JoinType`); character constants for SQLite's affinities (`'A'` to `'F'`, where fast-decomp prints 65 to 70); `uint *`, `code *` and `byte *` parameter types where fast-decomp says `void *` or `uint64_t`; `& 0x80` where fast-decomp writes `(int8_t)x > -1`; a search loop kept apart from the code that follows it (`sqlite3OpenTable`); a test fast-decomp leaves as an unknown (`__clobbered_r8 != v2` in `exprCodeTargetAndOr`, where Ghidra prints `param_2 == pcVar8`). Once its verdict went to Ghidra's text in spite of two wrong statements in it, by the reviewer's explicit weighing (`sqlite3_file_control`: the dropped mutex argument "barely misleads"). **The noise they still name in fast-decomp's text.** Leftover registers passed as extra, marked arguments (`VTCALL(v5, 6)(v4, &local_40, v2) /* likely */`); `/*out rax*/` pseudo-arguments for a callee's result; an explicit unknown `__clobbered_r8` standing for a parameter the code still holds; register spills shown as variables (`local_d4 = v5; … v5 = local_d4`); temporaries and cast chains (`(int64_t)(int32_t)(uint32_t)((uint64_t)v3 >> 4) << 4`); `uint128_t` packing of two stores; many `goto`s into the middle of blocks in the largest functions; `VCALL`/`VTCALL` not defined in the text; and a global table indexed without `&` (`g_eb692 + v6 * 3`), whose correctness the reviewer could not decide from one function's text because the declaration is not shown (it is a byte array in the export's `globals.h`; the [reading guide](guide/reading-output.md#types) now says so). **Limits.** One reviewer model, and a different instance for each review (the re-review of the first 14 was not made by the instance that wrote the first). Small samples: 14 and 20 functions, two C programs, gcc -O2 for Linux only; no C++, no Windows or MSVC code, no other compiler. The fresh sample happened to hold more of Ghidra's errors (22 wrong statements in 11 of 20 functions, 19 of them dropped call arguments) than the first (3 in 14) and than measure 7 (9 in 30). A reviewer can recognise the styles. And the caveat of this whole page applies: fast-decomp was developed on these programs, and the packages that changed its text after the first review were written in answer to it. ### 8. Three examples Chosen by rule from the samples above, not searched for: the first function of the measure-7 sample; the function of the first call site of the Godot hand-check sample; and, for a case where Ghidra's text was the better one, one of the two functions of the C++ test program's signature check where Ghidra's signature was right and fast-decomp's was not (at the first measurement `parse_positive` and `clamp_sum`: the shorter one; fast-decomp's signature of `clamp_sum` has been right since `58d74b8`, and the example shows what changed). **A C function: `btreeEnterAll` of SQLite** (the first of the measure-7 sample). Source (SQLite 3.54.1, public domain): ```c static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ int i; u8 skipOk = 1; Btree *p; assert( sqlite3_mutex_held(db->mutex) ); for(i=0; inDb; i++){ p = db->aDb[i].pBt; if( p && p->sharable ){ sqlite3BtreeEnter(p); /* inlined: p->wantToLock++; if( p->locked==0 ) btreeLockCarefully(p); */ skipOk = 0; } } db->noSharedCache = skipOk; } ``` fast-decomp (`sqlite-gcc-O2-stripped`, the body as exported): ```c void sub_1a9a0(struct s_1a9a0_0 *a1) { uint64_t v1; uint8_t v2; struct s_1a9a0_32 *v3; if ((int32_t)a1->f0x28_32 < 1) { a1->f0x6f_8 = 1; return; } v1 = 0; v2 = 1; do { v3 = *(ptr_u *)((v1 << 5) + a1->f0x20_64 + 8); if (v3 != NULL) { if (v3->f0x11_8 != 0) { v3->f0x14_32 = v3->f0x14_32 + 1; if (v3->f0x12_8 == 0) { sub_169f0(v3); } v2 = 0; goto continue_b10; } } continue_b10: v1 = v1 + 1; } while ((int32_t)a1->f0x28_32 > (int32_t)v1); a1->f0x6f_8 = v2; return; } ``` Ghidra 12.2 (same file): ```c void FUN_0011a9a0(long param_1) { long lVar1; undefined1 uVar2; long lVar3; if (*(int *)(param_1 + 0x28) < 1) { *(undefined1 *)(param_1 + 0x6f) = 1; return; } lVar3 = 0; uVar2 = 1; do { while ((lVar1 = *(long *)(lVar3 * 0x20 + *(long *)(param_1 + 0x20) + 8), lVar1 != 0 && (*(char *)(lVar1 + 0x11) != '\0'))) { *(int *)(lVar1 + 0x14) = *(int *)(lVar1 + 0x14) + 1; if (*(char *)(lVar1 + 0x12) == '\0') { FUN_001169f0(); } uVar2 = 0; lVar3 = lVar3 + 1; if (*(int *)(param_1 + 0x28) <= (int)lVar3) goto LAB_0011a9fd; } lVar3 = lVar3 + 1; } while ((int)lVar3 < *(int *)(param_1 + 0x28)); LAB_0011a9fd: *(undefined1 *)(param_1 + 0x6f) = uVar2; return; } ``` Both texts compute what the source computes, both keep one `goto` (fast-decomp's, `goto continue_b10;`, jumps to the statement that follows it: noise), and Ghidra's call `FUN_001169f0()` omits the argument `p` (one of the nine statements of measure 7). fast-decomp names the fields by offset and width through a structure recovered from the accesses (`f0x28_32` is `nDb`), where Ghidra prints the pointer arithmetic; its loop is the source's one `do … while`, Ghidra's a `while` inside a `do … while`. **A C++ method of Godot with a virtual call: `DisplayServer::global_menu_set_item_radio_checkable`** (the function of the first call site of the Godot hand-check sample). Source (`servers/display_server.cpp` at `4.3-stable`, MIT license, Copyright (c) 2014-present Godot Engine contributors, Juan Linietsky, Ariel Manzur): ```cpp void DisplayServer::global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable) { NativeMenu *nmenu = NativeMenu::get_singleton(); ERR_FAIL_NULL(nmenu); nmenu->set_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable); } RID DisplayServer::_get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const { if (p_menu_root == "_main") { return p_nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID); } else if (p_menu_root == "_apple") { ... ``` fast-decomp (`godot-win64.exe`, the export; the comment header is cut): ```c // 0x143565880 DisplayServer__global_menu_set_item_radio_checkable (212 bytes) // likely: parameter a3, a4 (heuristic) void DisplayServer__global_menu_set_item_radio_checkable(struct DisplayServer *this, void *a2, uint32_t a3, uint8_t a4) { struct NativeMenu *v1; uint64_t v2, v3; uint64_t local_40; v1 = *(ptr_u *)&g_147e084a8; if (v1 == NULL) { sub_1447a7540("global_menu_set_item_radio_checkable", "servers/display_server.cpp", 285, "Parameter \"nmenu\" is null.", &g_147088854, 0, 0); return; } v2 = (uint64_t)v1->vt->vf85_set_item_radio_checkable; if ((uint8_t)sub_1447b1100(a2, "_main") == 0) { v3 = sub_143563650(this, v1, a2); } else { v3 = v1->vt->vf40_get_system_menu(v1, 1) /* likely */; } local_40 = v3; ((fn_t)v2)(v1, &local_40, a3, a4) /* likely */; return; } ``` Ghidra 12.2 produced no text for Godot after its auto-analysis (measure 1). This is its text of the same function from a separate run that imports the file without auto-analysis (`run.py ghidra-one godot 0x143565880`: `analyzeHeadless ... -noanalysis` and a post-script that creates the function and decompiles it with default options; 49 s, 1.9 GB): ```c void FUN_143565880(undefined8 param_1,undefined8 param_2,undefined4 param_3,undefined1 param_4) { code *pcVar1; longlong *plVar2; char cVar3; undefined8 auStack_40 [2]; plVar2 = plRam0000000147e084a8; if (plRam0000000147e084a8 == (longlong *)0x0) { FUN_1447a7540(&UNK_14708aca8,&UNK_14708897d,0x11d,&UNK_14708a859,&UNK_147088854,0,0); return; } pcVar1 = *(code **)(*plRam0000000147e084a8 + 0x2a8); cVar3 = FUN_1447b1100(param_2,&UNK_14708a889); if (cVar3 == '\0') { auStack_40[0] = FUN_143563650(param_1,plVar2,param_2); } else { auStack_40[0] = (**(code **)(*plVar2 + 0x140))(plVar2,1); } (*pcVar1)(plVar2,auStack_40,param_3,param_4); return; } ``` The two texts have the same statements. fast-decomp names the method and its class (from the error report's string and the vtable that holds it), types `this`, shows the strings, and prints both virtual calls through named slots of `NativeMenu`'s vtable (`vf85_set_item_radio_checkable`, `vf40_get_system_menu`); Ghidra, without analysis here, prints the strings as unknown addresses and the virtual calls as offsets into the table (`+ 0x2a8`, `+ 0x140`). This comparison is not fair to Ghidra's analysis, which did not complete; it shows what Ghidra prints for this binary on this machine. **Where Ghidra's text was the better one: `clamp_sum` of the C++ test program.** Source (`small/cpp.cpp`, written for this project): ```cpp template __attribute__((noinline)) T clamp_sum(const std::vector &v, T lo, T hi) { T s{}; for (auto x : v) s += std::min(std::max(x, lo), hi); return s; } ``` fast-decomp at the first measurement (`cpp-gcc-O2-stripped`, commit `720f557`): ```c // 0x3bc0 sub_3bc0 (115 bytes) // likely: that there is no result (heuristic) void sub_3bc0(struct s_3bc0_0 *a1, uint128_t a2, double a3) { void *v1, *v2; double v3, v4; uint64_t local_18; uint64_t local_8; v1 = (void *)a1->f0x0_64; v2 = (void *)a1->f0x8_64; local_18 = (uint64_t)a2; if (v2 == v1) { return; } do { v3 = *(double_u *)v1; local_8 = as_u64(v3); if (!(as_f64((uint64_t)a2) > v3)) { v4 = v3; } else { v4 = as_f64((uint64_t)a2); } v1 = (char *)v1 + 8; } while (v1 != v2); return; } ``` fast-decomp now (commit `6ce5878`): ```c // 0x3bc0 sub_3bc0 (115 bytes) // likely: the result (heuristic) double sub_3bc0(struct s_3bc0_0 *a1, double a2, double a3) { void *v1, *v2; double v3, v4, v6, v7; uint64_t v5; uint64_t local_18; uint64_t local_8; v1 = (void *)a1->f0x0_64; v2 = (void *)a1->f0x8_64; local_18 = as_u64(a2); if (v2 == v1) { return 0.0; } v3 = 0.0; do { v4 = *(double_u *)v1; local_8 = as_u64(v4); if (!(a2 > v4)) { v5 = (uint64_t)&local_8; } else { v4 = a2; v5 = (uint64_t)&local_18; } if (v4 > a3) { v6 = a3; } else { v6 = *(double_u *)v5; } v1 = v1 + 8; v7 = v3 + v6; v3 = v7; } while (v1 != v2); return v7; } ``` Ghidra 12.2: ```c double FUN_00103bc0(double param_1,double param_2,undefined8 *param_3) { double *pdVar1; double *pdVar2; double dVar3; double dVar4; double local_18 [2]; double local_8; pdVar1 = (double *)*param_3; local_18[0] = param_1; if ((double *)param_3[1] == pdVar1) { return 0.0; } dVar4 = 0.0; do { local_8 = *pdVar1; pdVar2 = &local_8; if (local_8 < param_1) { pdVar2 = local_18; local_8 = param_1; } dVar3 = param_2; if (local_8 <= param_2) { dVar3 = *pdVar2; } pdVar1 = pdVar1 + 1; dVar4 = dVar4 + dVar3; } while (pdVar1 != (double *)param_3[1]); return dVar4; } ``` At the first measurement fast-decomp guessed (`likely`) that the function returns nothing, and with that guess the sum and the clamp to `hi` became dead code and were not printed: the text showed a loop that computes nothing, where Ghidra prints the sum, both clamps and the `double` result. That was a fast-decomp defect (defect 3 below): its rule is that a `likely` fact changes names and types, never the computation shown. Since `58d74b8` fast-decomp prints the sum, both clamps and the `double` result (still marked `likely`: the result is a guess from the caller's use of `xmm0`), and since the expressions package it types `lo` and `hi` as `double`, as Ghidra does, where `58d74b8` printed vector registers converted by `as_f64` (`as_f64((uint64_t)a2) > v4`). The two texts now have the same statements (35 and 32 lines from the declaration to the closing brace); what remains is that Ghidra holds the address of `local_8` or `local_18` in a `double *`, where fast-decomp holds it in an integer and stores the doubles' bits with `as_u64`. By the rule above the remaining candidate is `parse_positive`, whose result fast-decomp still prints as `void` (measure 4). ## Defects this benchmark found in fast-decomp The first measurement (fast-decomp at commit `720f557`) found three defects in fast-decomp's text, each of which made it state something the machine code does not do while every check of the project passed. They were 6 wrong statements in 2 of the 30 functions of measure 7 (listed in [the appendix](#appendix-the-statements-counted-in-measure-7)), and one function of measure 8's examples. All three were fixed in `58d74b8`. The first independent review found a fourth, and the compiled test written for the expressions package found five more in the printer before that package was merged. All are fixed in `6ce5878`, whose results the tables of this page give; the appendix keeps the first measurement's statements. 1. **A stack parameter narrower than 64 bits was printed as a dereference of itself.** `sqlite3CompleteInsertion` declared `uint64_t a8` and read `v1 = *(uint8_t *)a8;`: a load through the parameter's value, where the code reads the parameter's low byte. 46 parameters in 24 functions of the stripped SQLite export were printed that way, 157 in 101 of SQLite's PE build, 4,165 in 2,576 of OpenTTD and 11,570 in 7,581 of Godot (every parameter after the fourth is on the stack on Win64). Now each stack parameter is declared as wide as the code reads it (`uint8_t a8`, `v1 = a8;`), a part of it reads as a part of its value (`(uint8_t)a8`), and the AST check fails on any access printed through a frame variable that reaches beyond it. Reading the changed functions found a second form of the defect: a function that does not read `r9` numbered its first stack parameter as the fourth parameter (2,551 functions of Godot, 388 of OpenTTD: `MethodBind::call`'s argument count); the register positions before a stack parameter are now always declared. 2. **A parameter only passed on to an indirect call was dropped, and the signature still said "parameters proven".** `btreeGetPage(pBt, pgno, ppPage, flags)` hands `flags` to `pPager->xGet(...)` untouched; fast-decomp printed three parameters, its indirect call three arguments, and `btreeDropTable`'s three calls lost the `0`. Now a list is "proven" only when complete (the header says `at least these (an indirect call may also read rcx, ...)` otherwise), and a register the direct callers set for the call becomes a `likely` parameter, which the callers print: `btreeGetPage` has four, its indirect call and its callers print the fourth. (A first version also printed, at every call of such a function, the extra registers the call set; measured against the source, that made 342 call sites of SQLite print too many arguments for 23 it made right, and it was dropped.) 3. **A guessed `void` result deleted the computation of the result.** `clamp_sum` printed `void` with a loop that computed nothing (its only caller read the result in `xmm0`, the analysis looked only at `rax`). Now a caller's use of either result register counts, and a `likely` decision never leaves a computation out of the text: `clamp_sum` returns its sum as a `double` (example 3). Every text is checked for this as it is printed; a likely result or argument list that would hide a computation is taken back (the result printed as `rax` and `xmm0`, the call with every argument register; state `likely-withdrawn`): 374 of the corpus's 651,911 functions at `58d74b8`, 380 at `6ce5878`, a noisier but complete text. 4. **Un-threading made an endless loop and printed reachable code as unreachable** (found by the [first independent review](#independent-reviews)). The un-threading pass rewrites the control flow before structuring, undoing the compiler's jump threading; each redirect of an edge was proven alone, and two redirects that were each right could be applied together and send two edges into a cycle. `sqlite3SubqueryColumnTypes` then printed an endless loop on both paths that set the BLOB affinity, and the block that sets it under `// not reached from the entry:` with a variable nothing assigns. Over the corpus it made wrong text in 4 functions of the SQLite builds, 9 of Godot, 6 of node, 23 of bun and 1 of zig, and `selfcheck` passed: its equivalence check runs random states, which in that function never get past the first test. Now each redirect is proven on the graph that all the rewrites make together, every run checks that the entry still reaches every block it reached (a function that loses one is printed without the rewrites, as an internal error), and `selfcheck` checks that every variable the text reads is assigned on every path to the read ([internals/OPT.md](internals/OPT.md) section 5). No export of the corpus prints the comment since. 5. **Five printing rules that made the C text compute something else** (found by the compiled test of the conversions the printer leaves to C, `crates/fd-emit/tests/conversions.rs`, before the expressions package was merged: random integer expressions over parameters of every width and signedness, printed, compiled with gcc and run against the IR; [EMIT.md section 7](internals/EMIT.md#7-verification)). A right operand at its operator's precedence printed without parentheses regrouped once an operand printed narrower than the operator's type (`x32 | (y | z64)`), and a division hidden in a product chain regrouped (`a * (b / c * d)`); a `uint32_t` compared signed with a negative literal compared unsigned (`a4 > -2`); `-2147483648` is a `long` in C (now `INT32_MIN`); a `return` of a result narrower than its register dropped the truncation below the declared width (`(uint8_t)x` returned as a `uint16_t` printed `x`). The last rule, at least, was already in `58d74b8`'s printer; the AST check, which runs the statement tree and not the printed C, cannot see such rules. The test (20,000 expressions by default) passes since. Re-read with the fixed version (measure 7, same sample and rule): 0 wrong statements in the 30 functions, against 6 in 2 at `720f557`. 28 of the 30 texts did not change; the two that did are the two functions above, now right. Re-read again with `6ce5878`, whose texts of 27 of the 30 changed: 0 wrong statements. Over whole programs the fixes changed: defect 1, every narrow stack parameter of the exports above (0 printed as a dereference now); defect 2, 4 functions with a parameter more and 34 call sites with more arguments on SQLite, 2,588 and 3,312 on Godot (register positions before stack parameters included), and of SQLite's 10,319 call sites of functions defined in the source, 10,046 print the right number of arguments (10,020 at `720f557`); defect 3, `sig.py`'s count of `void` printed for a value did not rise on any build and the parameter counts it finds exact rose on seven of the eight builds (SQLite gcc -O2 1,342 to 1,346) and fell on none. ## Where fast-decomp is better - **Time, whole program**: 201 to 543 times less wall time on SQLite, Lua and SQLite's PE build (SQLite 0.41 s against 94 s; the PE build 0.47 s against 253 s), 254 times on OpenTTD (6.4 s against 27 minutes, Ghidra on one decompiler thread); on Godot 28 s, where Ghidra had not produced a text after 6.5 hours. CPU time: 76 to 230 times less. (On the two test programs Ghidra's 13 s are mostly the JVM's start and the import.) - **Memory**: 97 MB against 1.9 GB on SQLite; 1.0 GB against 5.4 GB on OpenTTD (anonymous memory 0.3 GB against 4.9 GB). Ghidra needed fewer decompiler threads than the six it was given to fit the 8 GB cap on OpenTTD, and its analysis of Godot reached the cap twice. - **Time to the first function**: 0.40 s against 69 s on SQLite, 4.6 s (0.5 s one-shot, local) against 10 minutes on OpenTTD; 22.8 s (2.4 s one-shot, local) on Godot, where Ghidra printed none; then 15 to 22 times lower median latency per function, and a worst case of 9 to 79 ms against 1.7 to 17 s. - **Functions printed on stripped ELF files**: 99.9 % of SQLite's and Lua's non-`.cold` symbol starts against 63.8 % and 69.5 % for Ghidra's decompile-all. Ghidra disassembles the other starts but creates no function there (mostly functions reached only through pointers), so it prints no text for them until a user creates the functions. On OpenTTD the tools have 44,775 functions in common; fast-decomp's other 67,937 are mostly leaf functions of a few instructions (0.98 MB of code, against 9.7 MB in the common functions). - **Wrong statements**: none in fast-decomp's texts of the 30 functions of measure 7 (Ghidra 9, all missing call arguments), none in the 34 functions of the two reviews of the current text (Ghidra 5 and 22). - **Readability as one reviewer model judged it** (small samples, see [Independent reviews](#independent-reviews)): on 20 fresh functions it preferred fast-decomp's text in 15 (8 clearly), Ghidra's in 3 (none clearly). - **Parameter counts**: 97.8 % / 98.9 % exact on SQLite / Lua against 95.3 % / 92.5 %; variadic functions printed as such (15 of 18 on SQLite). - **C++**: classes, slots and `this` types from the RTTI and the vtables: on OpenTTD 6,875 functions attributed to a class and 1,145 virtual calls through a named slot, where Ghidra attributes none of OpenTTD's own functions and prints every virtual call as pointer arithmetic. - **More functions without a `goto`** on every input (SQLite: 55.0 % of the functions, against 51.4 %; Lua 81.5 % against 71.3 %), and fewer `goto`s in all on four of the six inputs (`m.c`, the C++ test program, SQLite and SQLite's PE build). - **Every function printed**: no timeout, no failure (Ghidra: SQLite's PE build's largest function times out at 30 s in every run; 6 timeouts on OpenTTD). ## Where Ghidra is better - **`void` functions**: fast-decomp printed a value for 21 of SQLite's `void` functions (Ghidra 10) and 13 of Lua's (Ghidra 1); on the C++ test program both have the `void`-or-value right for 5 of 6 functions. - **Fewer C tokens**: on the functions both printed, fast-decomp's text has 2 to 23 % more tokens on every input; more lines on SQLite, Lua and the C++ test program (14 to 20 % more) and more casts on four of the six inputs (1.06 to 1.9 times). - **Fewer `goto`s on Lua and OpenTTD**: 994 against fast-decomp's 1,039, and 13,559 against 14,233, where fast-decomp writes code that several paths share once behind a label (measure 5). - **What the reviewer still preferred in Ghidra's text**: real `case` values instead of an offset switch, flatter code with one error label in a few functions, character constants, pointer parameter types (`uint *`, `code *`) where fast-decomp says `void *` or `uint64_t` (see [Independent reviews](#independent-reviews)). - **Library functions recognised by their bytes** (Function ID): 922 functions of OpenTTD's MSVC runtime named (`std::_Lockit::_Lockit`, `__crt_stdio_input::...`); fast-decomp names none. - **Capabilities fast-decomp does not have at all**: other architectures (ARM, AArch64, MIPS, PowerPC, ... where fast-decomp decompiles x86-64 only); x87, MMX and AVX-512 instructions (an `__unknown(...)` effect in fast-decomp: 1,942 in the PE build of SQLite, whose mingw runtime uses x87); C++ exception handling marked in the parent function (Ghidra's comments `/* try { // try from ... */` and `/* catch() { ... } */`; fast-decomp prints funclets and landing pads as separate functions); a GUI, a debugger, an emulator, scripting in Java and Python, data type archives for the Windows API and the C library, a project database with undo and version tracking, and about twenty years of use on real reverse-engineering work. No longer in this list, measured again: **wrong statements** (fast-decomp's first measurement printed 6 in 2 of the 30 functions where Ghidra printed them right, and a guessed `void` hid a computation; now none, against Ghidra's 9); **readability as the reviewer judged it** (first review: Ghidra's text preferred in 10 of 14 functions; the same 14 with the current text: 4, fast-decomp's 5; 20 fresh functions: 3, fast-decomp's 15); **shorter text in lines** on `m.c`, SQLite's PE build and OpenTTD (fast-decomp had 1.04 to 1.37 times Ghidra's lines on every input but `m.c`; now 0.91 to 0.99 times on those three) and **fewer casts** on Lua and SQLite's PE build (1.2 to 2.9 times before; now 0.95 and 0.77 times). ## Not measured - Readability or comprehension judged by people; by a model, only the three small reviews above (blind to which tool wrote which text, not to their styles). The text counters describe the text, they do not say which text is easier to read. - Other architectures (Ghidra decompiles dozens; fast-decomp only x86-64), Ghidra's GUI, debugger, type archives and scripting, and fast-decomp's projects. - Correctness beyond the 30 functions of measure 7 and the 34 of the reviews. - Inputs with symbols or debug information. - `node`, the last and optional input of the plan: not run, the time went to the repeated Ghidra runs on OpenTTD and Godot. ## Caveats - **A development corpus.** fast-decomp was developed while reading these very binaries (SQLite, Lua, the two test programs, OpenTTD, Godot); its heuristics were tuned on them. Ghidra was not. Other programs may favour Ghidra more. - **One machine, a VM**, 6 cores and 11 GB of memory. Ghidra's analysis is mostly single-threaded (about 1.6 cores busy on OpenTTD); its time scales with the core's speed, not the count. - **Run counts.** The small inputs ran three times each (the tables give the minimum and the range); the large ones once each. - **Two dates.** Ghidra's side is its runs of 2026-11-24, kept; fast-decomp's ran again on 2026-11-25, on the same machine with nothing else running. - **Ghidra's heap.** The JVM grows its heap toward its maximum before collecting, so the peak memory of the Ghidra runs depends on the heap limit (5 GB on the small inputs, 3 GB on the large ones); the labelled 2 GB run on SQLite shows by how much. - **The large inputs ran outside Ghidra's defaults where the defaults did not fit**: OpenTTD's finished run used one decompiler thread instead of six, so its decompile time is a single-threaded one; Godot has no Ghidra result at all, so the comparison on the largest program is one-sided. - **The person who measured works on fast-decomp.** The definitions were written before the results and are applied to both outputs by the same scripts; every error counted in measure 7 is listed with both texts so that it can be checked; the [independent reviews](#independent-reviews) were made by a reviewer that did not know which tool wrote which text, on small samples. - Ghidra is Apache-2.0; the excerpts of its output on this page were produced by Ghidra 12.2. ## Reproduce The scripts are in [scripts/bench/](../scripts/bench/); these are the commands that produced the numbers above (the large inputs' failed attempts aside). Requirements: Linux with systemd (each run gets its own cgroup through `systemd-run --user --scope`), Python 3, `readelf`/`objdump`/`strip` (GNU binutils), the [corpus](CONTRIBUTING.md#the-corpus), Ghidra 12.2 and a JDK 25. ```sh cargo build --release export FD_CORPUS=/path/to/corpus FDBENCH_OUT=/path/to/results export GHIDRA_INSTALL_DIR=/path/to/ghidra_12.2_PUBLIC JAVA_HOME=/path/to/jdk-25.0.5.1+2 # optional: how each run is put in a capped cgroup (defaults: systemd-run with MemoryMax=8G / 6G) # export FDBENCH_WRAP_GHIDRA="..." FDBENCH_WRAP_FD="..." R="python3 scripts/bench/run.py" $R prepare # stripped copies, PE copies, SHA-256 manifest for n in m cpp sqlite lua sqlite-pe; do $R fd-bench $n # phases (bench --json) and the function list for k in 1 2 3; do $R ghidra $n --run $k; done for k in 1 2 3; do $R fd $n --run $k; done $R sample $n; $R fd-first $n; $R fd-latency $n done for n in openttd godot; do $R fd-bench $n; $R fd $n; done $R --heap 3G ghidra openttd --run 4 --threads 1 --sample-first $R --heap 3G ghidra godot --run 2 --sample-first for n in openttd godot; do $R sample $n; $R fd-first $n; $R fd-latency $n; done for n in sqlite lua cpp; do $R ghidra $n --variant paramid; done $R ghidra sqlite --variant heap2g for n in m cpp sqlite lua sqlite-pe openttd; do python3 scripts/bench/compare.py $n; done $R --heap 3G ghidra-one godot 0x143565880 # the Godot example, without analysis for n in sqlite lua cpp; do python3 scripts/bench/compare.py $n --ghidra-run ghidra-paramid-1; done python3 scripts/bench/wrong_sample.py sqlite 20 # review files for measure 7 python3 scripts/bench/wrong_sample.py m 10 --min-lines 1 python3 scripts/bench/cpp_sample.py godot fd # the hand-check sample of measure 6 python3 scripts/bench/cpp_sample.py openttd ghidra --count 30 python3 scripts/bench/report.py # docs/benchmark-results.json and the tables python3 scripts/bench/chart.py # docs/assets/benchmark-speed-{light,dark}.svg ``` On the machine of this page the two wrappers were the repository's development tooling (`tools/heavy -m 8G` and `-m 6G`: the same `systemd-run` scope, plus a lock so that runs never overlap). ## Appendix: the statements counted in measure 7 Source excerpts are SQLite 3.54.1 (`sqlite3.c`, public domain). The Ghidra lines are Ghidra 12.2's output on `sqlite-gcc-O2-stripped`; the fast-decomp lines are its export of the same file. Each entry gives the function (its symbol in the unstripped twin, its address), the source statement, and the statement each tool printed for it. ### fast-decomp: 6 statements in 2 functions (first measurement, commit `720f557`; fixed since) **`btreeDropTable` (0x5aab0), 3 statements: an argument dropped.** The source calls `btreeGetPage(pBt, (Pgno)iTable, &pPage, 0)` and twice `btreeGetPage(pBt, maxRootPgno, &pMove, 0)`. `btreeGetPage` passes its fourth parameter `flags` to `sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, flags)`, an indirect call through `pPager->xGet`; the machine code leaves `ecx` untouched before that call, so the value flows through. fast-decomp prints `btreeGetPage` (`sub_c370`) with three parameters, marked proven, and its indirect call with three arguments (`/* likely */`), so all three calls lose the `0`: ```c v2 = sub_c370(v1, v3, &local_48); /* fast-decomp */ uVar5 = FUN_0010c370(lVar2,param_2 & 0xffffffff,&local_48,0); /* Ghidra */ ``` (and `sub_c370(v1, v5, &local_40)` twice, where Ghidra prints `FUN_0010c370(lVar2,local_4c,local_40,0)`). **`sqlite3CompleteInsertion` (0x3c990), 3 statements: stack parameters read as pointers.** The three last parameters (`int update_flags, int appendBias, int useSeekResult`) are passed on the stack. fast-decomp declares them `uint64_t a7, uint64_t a8, uint64_t a9` and reads them as if they were their addresses: ```c v1 = *(uint8_t *)a8; /* appendBias */ v2 = *(uint8_t *)a9; /* useSeekResult */ v3 = *(uint32_u *)a7; /* update_flags */ ``` Ghidra declares `int param_7, byte param_8, byte param_9` and uses the values. (In this export every stack parameter narrower than 64 bits is printed this way: 46 parameters in 24 functions; the 64-bit ones are used as values.) ### Ghidra: 9 statements in 9 functions All nine are calls printed without an argument the callee reads (the callee's own text, printed by Ghidra, has the parameter). Ghidra's auto-analysis of ELF files leaves the "Decompiler Parameter ID" analyzer off (it ran by default on the small PE input, not on OpenTTD); the labelled variant turns it on. | Function | Source | Ghidra | fast-decomp | | --- | --- | --- | --- | | `btreeEnterAll` (0x1a9a0) | `sqlite3BtreeEnter(p)`, inlined: `btreeLockCarefully(p)` | `FUN_001169f0();` | `sub_169f0(v3);` | | `sqlite3WhereFindTerm` (0x72860) | `p = whereScanInit(&scan, pWC, iCur, iColumn, op, pIdx);` | `lVar1 = FUN_00172780(auStack_98,param_1,param_2,param_3);` | `v1 = (struct s_72860_16 *)sub_72780(local_98, a1, a2, a3, a5, a6);` | | `resizeIndexObject` (0x32780) | `zExtra = sqlite3DbMallocZero(db, nByte);`, inlined: `sqlite3DbMallocRawNN(db, n)` | `pvVar1 = (void *)FUN_0012fe40();` | `v5 = (void *)sub_2fe40(v3, v4);` | | `pager_unlock` (0x22040) | `sqlite3OsDeviceCharacteristics(pPager->fd)`, inlined: `pFd->pMethods->xDeviceCharacteristics(pFd)` | `uVar5 = (**(code **)(**(long **)(param_1 + 0x48) + 0x60))();` | `VTCALL(v6, 12)(v5)` | | `codeDistinct` (0x6c050) | `sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, regElem, nResultCol);` | `FUN_0013c920(lVar2,0x1c,param_3,param_4,param_6);` (two lines below, the same callee is printed with six arguments) | `sub_3c920(v3, 28, a3, a4, v1, (uint32_t)v2);` | | `exprMightBeIndexed` (0x72340) | `return exprMightBeIndexed2(pFrom,aiCurCol,pExpr,i);` | `uVar3 = FUN_001721c0(param_1,param_2);` | `return sub_721c0(a1, a2, a3, v4);` | | `sqlite3ExprListAppendVector` (0x49010) | `pRet = sqlite3ExprDup(pParse->db, pVector, 0);`, inlined: `exprDup(db, p, 0, 0)` | `pcVar4 = (char *)FUN_00132c50(lVar6,pcVar4,0);` | `v12 = (struct s_49010_3 *)sub_32c50(v14, v15, 0, 0);` | | `sqlite3WhereRightJoinLoop` (0x99820) | `sqlite3ExprDelete(pParse->db, pSubWhere);`, inlined: `sqlite3ExprDeleteNN(db, p)` | `FUN_0011f060(*puVar4);` | `sub_1f060(v2->f0x0_64, v56);` | | `blobSeekToRow` (0xe5250) | `sqlite3VdbeMemSetInt64(&v->aMem[1], iRow);`, inlined: `vdbeReleaseAndSetInt64(pMem, val)` | `FUN_00119d20(lVar3 + 0x38);` | `sub_19d20((char *)v2 + 56, a2);` | ### Not counted Printed as unknowns or guesses, or not about behaviour: fast-decomp's extra `/* likely */` arguments after a call's real ones (`sqlite3ErrorMsg(..., "%d columns assigned %d values", n1, n2, r8, n1)` in `sqlite3ExprListAppendVector`; an extra vector value among `sqlite3WhereBegin`'s arguments in `sqlite3WhereRightJoinLoop`); fast-decomp's unreachable second `return NULL;` in `sqlite3IdListDup`; Ghidra's `uStack_60 = 0x1016eb;` in `fill_buf` (the return address the call pushes, stored in a variable it also uses to address `tmp`); types and names on both sides. In the current texts (`6ce5878`) the extra vector value and the unreachable `return NULL;` are gone; still not counted, by the same rule: the extra `/* likely */` arguments of `sqlite3ErrorMsg`; `blobSeekToRow`'s `sqlite3_errmsg` call, printed with the `likely` parameters fast-decomp guesses for it (`sub_6ec80(v15, __noarg, v14, __noarg) /* likely */`: the source passes `db` alone); `fill_buf`'s 64-byte buffer, declared as four frame variables (`uint8_t local_58[16]` and three `uint128_t`) that the copy then reads across; and `btreeEnterAll`'s `goto` to the next statement.