devirt.re
Create account
Menu

Decompilation: what a decompiler recovers from a binary, and what it cannot

Decompilation is the process of translating compiled machine code back into readable source in a high-level language such as C. A decompiler reads an executable, finds its functions, works out how data and control move through them, and prints pseudocode that does what the binary does. It cannot print what the compiler threw away: names, comments, most types and the shape of the code the programmer wrote.

To put numbers on that loss, Devirt wrote a 9-function C program, compiled it three ways on 13 November 2026, stripped the symbols and ran the open-source angr decompiler on each build. The decompiler named 1 of the 9 functions, matched every parameter count it could see, and on the optimized builds rebuilt the program's main structure without its name. On the -O2 build it printed 247 lines of code for 90 lines of source, and one printed loop, run as written, did not do what the source function does. A second test shows why decompilers fail on virtualized code: on a function run by an interpreter, the decompiler prints the interpreter.

What is decompilation?

Decompilation is the reverse of compilation: it starts from machine code and produces source code in a higher-level language. A compiler turns if, for, variables and types into processor instructions, registers and memory offsets. A decompiler takes those instructions and rebuilds the statements, expressions and functions they most likely came from.

The output is pseudocode, not the original file. It uses invented names such as sub_1001720 and v3, and it reflects every choice the compiler made, including code it inlined, reordered or deleted. Decompilation is used in malware analysis, vulnerability research, interoperability work, recovery of lost source code and game preservation, and it sits at the center of most binary analysis.

Decompilation is an old research problem. In 1995 Cristina Cifuentes and K. John Gough of Queensland University of Technology described the structure of their decompiler, dcc, in Decompilation of Binary Programs. dcc read DOS programs for the Intel 80286 and produced C, and the structure the paper set out still describes most decompilers.

Bytecode decompilers are a separate, easier case. Java class files and .NET assemblies keep class names, method names and type information, so tools such as ILSpy, dotPeek and Jadx often recover something close to the source. Native code compiled from C, C++, Rust or Go keeps far less, and the rest of this article is about native code.

How does a decompiler work?

A decompiler works in five stages: disassembly, lifting, data-flow analysis, type recovery and control-flow structuring. Cifuentes and Gough grouped these phases into a machine-dependent front end, a machine-independent middle they called the universal decompiling machine, and a back end that writes the target language. The split still describes Ghidra, IDA and angr.

  1. Disassembly. The decompiler decodes bytes into instructions and finds where functions start and end. On a stripped binary there is no symbol table to help, so it finds functions by following calls from the entry point and by recognizing common prologues.
  2. Lifting. Each instruction is translated into a machine-independent intermediate representation, such as Ghidra's P-code or the VEX representation angr uses, so that later stages do not need to know about x86 flags or ARM condition codes.
  3. Data-flow analysis. The decompiler tracks values through registers, the stack and memory. Temporary registers collapse into expressions, stack slots become local variables, and the calling convention tells it which registers carry parameters and the return value.
  4. Type recovery. The decompiler guesses integers, pointers, arrays and structures from how each value is used. A value that is dereferenced is a pointer; a pointer read at offset 16 and offset 20 suggests a structure with fields there.
  5. Control-flow structuring. The control-flow graph of basic blocks and jumps is rebuilt into if, while, for and switch. When no structured form fits, the decompiler prints a goto.
Illustration of the five decompiler stages, each with a small drawing: bytes decoded into instructions, instructions lifted into an expression tree, registers merged into variables, memory offsets grouped into a structure, and a block graph turned into a while loop. Under each stage, what is lost or guessed.
A decompiler reads a binary in five stages. Each one adds structure the machine code does not carry, and each one guesses where the compiler left nothing behind. Illustration, not a measured result.

Structuring is the stage with the longest research history. The Phoenix decompiler from Carnegie Mellon (Schwartz and colleagues, USENIX Security 2013) recovered control structure without changing the program's behavior. DREAM (Yakdan and colleagues, NDSS 2015) aimed to remove every goto. SAILR (Basque and colleagues, USENIX Security 2024) argued that a decompiler should instead get as close as possible to the original source, which means keeping the gotos the programmer wrote and removing only the ones the compiler created. SAILR's authors implemented it in an open-source decompiler built on angr, the framework used in the test below.

Control-flow structuring groups basic blocks into regions, innermost loop first. The back edge from the shift block to the inner test becomes a while loop, and the back edge from the store block to the outer test becomes the for loop around it. Illustration, not a measured result.

What is the difference between decompilation and disassembly?

Disassembly and decompilation are two levels of reading the same machine code. A disassembler maps each instruction to its assembly mnemonic one for one, so its output is exact and as long as the program. A decompiler analyzes data flow and control flow and prints C-like pseudocode, which is shorter and easier to read but is a reconstruction that can be wrong.

Disassembly and decompilation compared
AspectDisassemblyDecompilation
OutputAssembly instructionsC-like pseudocode
Mapping to the binaryOne instruction per lineMany instructions per statement
ExactnessExact, if the bytes were decoded correctlyA reconstruction, which can be wrong
Length in our test (-O0 build)395 instructions125 lines of code
What the reader needsThe processor’s instruction setC, and an eye for compiler patterns
Where it failsData mistaken for code, overlapping instructionsLost types, unusual control flow, interpreters

Hex-Rays, which sells the IDA decompiler, writes in its introduction to decompilation vs disassembly that decompiler output is usually five to ten times shorter than disassembly. In our small test the angr decompiler's code lines were 3.2 times shorter than the disassembly at -O0 and 1.8 times shorter at -O2. The ratio depends on the program, the decompiler and the optimization level, and a small program with short functions sits at the low end.

Analysts read both views together. The disassembly is the ground truth that the decompiler's output has to agree with, and most decompilers show the two side by side for that reason. The Devirt guide to reverse engineering tools sorts disassemblers and decompilers by the job each one does.

What a decompiler recovered in our test

Devirt's decompilation test compiled one ordinary C program three ways and ran the angr decompiler on each stripped build, with the source as the answer key. The test ran on 13 November 2026.

  • The program. records.c, written for this test: 9 functions and 98 source lines. A string hash, a number parser, a small clamp helper, a switch-based grader, an insertion sort over a 24-byte record structure, a recursive greatest common divisor, a loader, a report printer and main.
  • The builds. clang through zig cc 0.17.1, targeting x86-64 Linux, at -O0, -O2 and -Os, with debug information off. zig cc produced byte-identical binaries for -O1, -O2 and -O3, and again for -Os and -Oz, so those three are the distinct builds this toolchain makes. Each build was stripped of its symbol table.
  • The answer key. A second build of each level kept its symbols, and its code section was checked byte for byte against the stripped build so that addresses match. The decompiler never saw it.
  • The decompiler. angr 9.2.213 with default settings: function discovery, calling-convention and variable recovery, then the angr decompiler on every function that came from the source.
  • What was counted. Functions found, names recovered, parameter counts, whether pointer parameters were shown as pointers, whether a structure layout was rebuilt, decompiled lines (all, and code only without the declaration block) and goto statements.
What the angr decompiler recovered from each stripped build
Measure-O0-O2-Os
Source functions still in the binary9 of 98 of 98 of 9
Function names recovered1 of 9 (main)1 of 8 (main)1 of 8 (main)
Parameter counts matching the source9 of 98 of 88 of 8
Pointer parameters shown as pointers3 of 75 of 75 of 7
Functions with the record layout rebuilt0 of 92 of 81 of 8
Source lines (functions present)989090
Decompiled lines, code only125247190
Decompiled lines, all161357270
goto statements000
Bar chart of the decompilation test. -O0 build: 98 source lines, 125 decompiled code lines, 395 disassembly instructions. -O2 build: 90, 247 and 435. -Os build: 90, 190 and 299. Below the bars: function names recovered 1 of 9, 1 of 8, 1 of 8; parameter counts matched 9 of 9, 8 of 8, 8 of 8; record layout rebuilt 0 of 9, 2 of 8, 1 of 8.
The same C program, three builds, one decompiler. The decompiled code grows with optimization because inlining copies functions into their callers, while the names never come back. Measured on 13 November 2026.

The counts show five things.

  • Names are gone, and only main comes back. Every recovered function except main is called sub_ plus its address. angr names main because the startup code passes its address to the C library, a pattern decompilers recognize. The three functions angr found that were not in the source were that startup code: _start and two initializers.
  • Parameter counts survive; types often do not. angr counted every function's parameters correctly on all three builds. Pointer types were another matter: at -O0 it showed argv in main as an unsigned int and the record array in the loader as an unsigned long.
  • Layout comes back without names. On the optimized builds, angr rebuilt the record as an unnamed structure (struct_0 at -O2, struct_1 at -Os), with 4-byte fields at offsets 0x10 and 0x14 (an int and an unsigned int at -O2). That is the right shape for the score and flags fields, but their names exist only in the source.
  • Optimization moves code between functions. At -O2 the clamp helper no longer exists as a function, because the compiler copied it into its only caller, and main grew from 9 source lines to 59 decompiled lines because the sort and the report were copied into it too.
  • No gotos. The program's control flow is simple, and the structuring stage turned all of it into loops and conditionals. Larger programs with break, early returns and shared error paths are where gotos appear.

Why is decompiled code not the original source?

Decompiled code is not the original source because compilation keeps behavior and discards everything else. The test shows four kinds of loss.

Names and comments. A stripped binary keeps no function names, variable names or comments, so the decompiler invents them. name_hash becomes sub_1001720, its parameter becomes a0, and its loop counter becomes v1.

Types. Machine code has registers of 32 and 64 bits, not char * or a named structure. The decompiler infers types from use, and when the evidence is thin it falls back to integers, which is why pointer parameters were shown as integers in four of seven cases at -O0.

Compiler idioms. Compilers replace slow operations with fast ones. The grader divides a score by 10; on every build the decompiled code multiplies by 1717986919 and shifts right by 34 instead, the standard way to divide by a constant without a division instruction. The grader's switch became a chain of conditional expressions at -O0 and a lookup table at -O2. This is the -O2 output, with the variable declarations omitted and the long line wrapped:

unsigned int sub_10017e0(unsigned int a0)
{
    v1 = (unsigned int)(a0 * 1717986919 >> 34)
       + (unsigned int)(a0 * 1717986919 >> 63) - 5;
    v2 = 0;
    if (v1 <= 5)
        v2 = g_1000498[v1];
    return v2;
}

The decompiler printed what the binary does. Nothing in it says that the function sorts a score into a grade band.

Structure. Inlining copies one function into another, and tail calls become loops: at -O2 the recursive greatest-common-divisor function decompiled to a do-while loop, because the compiler had already rewritten the recursion. A decompiler rebuilds the binary's structure, which after optimization is the compiler's structure, not the programmer's.

Is decompiled code correct?

Decompiled code is not guaranteed to be correct, and the test caught one case where it was not. The angr decompiler's -O2 output for the insertion sort, a 12-line function, was transcribed line for line into a C file, with types filled in the most charitable way and the control flow kept exactly as printed, then run next to the source function on the same five records.

The source sort and the printed -O2 loop on the same five records
RunOrder returned
Inputana 72, ben 91, cal 55, dee 91, eli 64
Source functionben 91, dee 91, ana 72, eli 64, cal 55
Printed -O2 loop, run as writteneli 64, dee 91, cal 55, ben 91, ana 72

The printed loop puts its comparison alone inside the loop body as if (...) continue;, which in C changes nothing, so every earlier record is shifted on every pass. The same function at -O0 decompiled to a faithful loop with the comparison in the right place. Elsewhere in the -O2 output, a printf call in main was printed with its format string and none of its four arguments.

This is one function, one decompiler version and default settings, and other decompilers handle this loop differently. The point holds well beyond this one loop. A decompiler's output is a hypothesis about the binary. Analysts check it against the disassembly, recompile and test it where they can, or rely on stronger evidence. Devirt keeps readable and proven apart for the same reason: every counted function in scope sits in one of four proof states, and only proven counts as proof.

How does compiler optimization change decompiler output?

Compiler optimization changes decompiler output because it changes the code the decompiler reads, and the three builds in the test read very differently. The unoptimized -O0 build gave the most faithful output: every source function survived, the lines stayed close to the source (125 code lines for 98), and the insertion sort read correctly.

The -O2 build kept 8 of 9 functions and doubled the output to 247 code lines, mostly because inlining copied whole functions into main. It also gave the highest layout count: angr rebuilt the record layout in 2 functions, against 1 at -Os and 0 at -O0. The size-optimized -Os build sat between the two at 190 code lines, with main back to 8 code lines because the sort and the report were not copied into it.

For anyone reading decompiler output, that means three things:

  1. A function in the source may not exist in the binary, and a function in the binary may contain several from the source.
  2. More lines does not mean more recovered logic. The -O2 output is longer because the same code appears more than once.
  3. A loop or condition that reads strangely in an optimized build is a reason to check the disassembly before trusting it.

Why do decompilers fail on virtualized code?

Decompilers fail on virtualized code because virtualization obfuscation removes a function's instructions and leaves an interpreter in their place. The decompiler reads the interpreter correctly and prints it: a loop that fetches an opcode and a switch that runs a handler for it. The original arithmetic is no longer code at all; it is bytecode, stored as data, that only the interpreter understands.

Devirt's second test makes this measurable with a teaching interpreter, toyvm.c, written for this article. It contains the same five-step calculation twice: once as an ordinary C function, and once as 30 bytes of bytecode run by a 5-opcode interpreter. Both versions returned the same value on six test inputs, including 0 and 0xffffffff. The test counted how many of the calculation's five constants appear in each version's decompiled output.

What the angr decompiler shows for the same calculation, -O2 build
Decompiled functionConstants visibleOpcode switch casesDecompiled lines
Ordinary C function5 of 504
Bytecode version, interpreter inlined0 of 5548
The interpreter on its own0 of 5545

The ordinary function decompiled to a single return statement containing all five constants. The bytecode version decompiled to twelve times as many lines describing a loop, a byte decoder and five handlers, and none of the constants, because they sit in the bytecode as operands. The decompiler did its job without error: it decompiled the interpreter. The function the interpreter runs never reached it.

Commercial protectors take the same idea much further. VMProtect and Themida convert selected functions into bytecode for their own virtual machines, built into the protected file, and add further layers such as mutation and packing around them. Oreans, which makes Themida and Code Virtualizer, says that anyone who tries to decompile code protected by Code Virtualizer finds a completely new instruction set that no decompiler recognizes. The devirtualization methods hub explains how virtualization obfuscation is built: a VM entry, a dispatcher, handlers, a virtual context and a VM exit.

Recovering such a function is devirtualization, not decompilation. The bytecode has to be translated back into native logic first, by one of the method families the hub describes, and only then does a decompiler have the real function to read. The guide to devirtualization vs deobfuscation sets out where each step starts and stops. Devirt does that translation for authorized analysis, and delivers annotated pseudocode, an IDA database and a coverage ledger that counts every function in scope.

What is matching decompilation?

Matching decompilation is the practice of writing C source by hand until it compiles, with the original compiler and settings, to exactly the same machine code as the shipped binary. Game-preservation projects use it because a byte-for-byte match proves the rebuilt source is equivalent, something ordinary decompiler output never shows.

The Ocarina of Time decompilation is a well-known example: it recreates a source code base for the game from scratch, and its build checks whether the rebuilt ROM is the same as the original. Matching projects start from decompiler output and rewrite each function until the compiled bytes agree. decomp.me, which describes itself as a collaborative decompilation and reverse engineering website, is one shared home for that work. The process is slow, and it depends on having the exact compiler and flags the original developers used.

Matching decompilation is also one of the three approaches sold as an AI decompiler: a model proposes source, and recompiling it checks whether the guess matches. The model only proposes. The recompile is the check.

Which decompilers are in use today?

The decompilers most analysts use on native code are Ghidra, IDA Pro with the Hex-Rays decompiler, Binary Ninja and angr, with JEB and RetDec as further options.

  • Ghidra is the National Security Agency's open-source reverse engineering suite, created and maintained by its Research Directorate, with a decompiler built on its P-code representation.
  • IDA Pro with the Hex-Rays decompiler is the long-standing commercial standard.
  • Binary Ninja is a commercial disassembler and decompiler from Vector 35, with its own intermediate language.
  • angr is an open-source binary analysis framework in Python with its own decompiler, used for the tests on this page. Its documentation covers the decompiler and the analyses behind it.
  • JEB is a commercial decompiler from PNF Software.
  • RetDec is an open-source machine-code decompiler based on LLVM.

For bytecode, ILSpy and dotPeek decompile .NET, and Jadx decompiles Android applications. Decompiler Explorer runs one small binary through several decompilers at once, which is the quickest way to see that two decompilers rarely print the same function the same way.

What this test does and does not show

Devirt's decompilation test measures one decompiler, one compiler and two small programs. It shows the kinds of loss decompilation involves and how optimization changes them. It does not rank decompilers, and Ghidra, IDA or Binary Ninja would produce different counts on the same builds.

  • One decompiler, default settings. angr 9.2.213, with no manual types, no renaming and no user hints. Analysts often add all three, and output improves when they do.
  • One toolchain. clang through zig cc 0.17.1 for x86-64 Linux. GCC, MSVC and other targets produce different code.
  • Small programs. 98 and 35 lines of function code. Real programs have more functions, more indirect calls and more complicated control flow.
  • Correctness check by transcription. The sorting check ran a hand transcription of the printed loop, with types filled in. The printed control flow was kept exactly; the types were chosen to give the printed code its best chance.

The test programs, the measurement script and the raw decompiler output are kept with this article's working files, dated 13 November 2026. For files you are authorized to analyze, the how-it-works page follows one protected file from upload to a result with its ledger.

See how Devirt works