PRA-MEN ARM 223M · neural decompiler for Apple Silicon (AArch64)

Pramen ARM turns the AArch64 assembly of a single function back into C. It is the ARM sibling of radix16/pramen-223m and radix16/pramen-498m (Windows and MS-DOS): same architecture, same prompt format, its own data and tokenizer.

variant target
apple-arm64-O0 macOS / iOS arm64, Apple clang 17, no optimization
apple-arm64-Os Apple clang, optimized for size
apple-arm64-O2 Apple clang, optimized

It is a 223 M parameter decoder-only transformer (GPT-2 style) trained from scratch on assembly and C only, with its own 16 384-token tokenizer (about 5.7 tokens per ARM instruction).

The output is a proposal. On unoptimized code it is usually right; on optimized code it often compiles but the logic is wrong. Names are invented (they are not in the binary) and types are guessed.

Results

HumanEval-C from LLM4Binary/decompile-eval (CC0), recompiled with the same Apple clang as the training data – 164 tasks per variant. A task counts as solved when the decompiled C compiles (C17, standard headers) and passes the original tests. Max 600 new tokens.

variant greedy --candidates 8
apple-arm64-O0 76.2 % 90.9 %
apple-arm64-Os 26.2 % 34.8 %
apple-arm64-O2 23.8 % 32.3 %
average 42.1 % 52.7 %

--candidates 8 samples 8 proposals, recompiles each and keeps the one whose assembly is closest to the input. It needs Apple clang (Xcode Command Line Tools).

Held-out ExeBench functions (500 functions × 3 variants never used in training, compiled with their real dependencies), greedy: how often the output compiles, and how often it recompiles to exactly the input assembly.

O0 compiles / exact Os compiles / exact O2 compiles / exact
no declarations 47.6 / 35.0 % 44.6 / 24.4 % 45.2 / 24.8 %
with the function's declarations (--context) 83.0 / 67.2 % 79.2 / 50.2 % 79.4 / 50.2 %

Optimized code is the weak spot: on HumanEval at -Os / -O2 about 100 of 164 outputs compile but fail the tests. The typical mistake is merging values that the optimized code keeps only in registers (a sum and a product written as one variable) or dropping a step of a loop.

These numbers are not directly comparable with the Windows / DOS models (other compilers, other task counts).

Quick start

pip install huggingface_hub
hf download radix16/pramen-arm-223m --local-dir pramen-arm
cd pramen-arm
pip install -r requirements.txt                   # torch, tokenizers, safetensors, capstone

python -m pramen_arm list program                                   # functions in a binary
python -m pramen_arm asm program --function main                    # the listing the model sees
python -m pramen_arm decompile program --function main --variant apple-arm64-O0 --model .
python -m pramen_arm decompile program --function main --variant apple-arm64-O2 --model . --candidates 8
python -m pramen_arm decompile program --function order_total --variant apple-arm64-O0 --model . --context types.h

The input is a linked binary: Mach-O arm64 (also the arm64e slice of a fat binary) or ELF AArch64, not a .o. Stripped binaries work too – give the function by address from list (--function 0x100003f20). Help texts of the command line are in Czech.

On an Apple M2 Pro (MPS) a small function takes about 2 s; --candidates 8 about 5–8× longer.

from pramen_arm.runtime import PramenArm

model = PramenArm(".")                                 # folder with config.json, model.safetensors, tokenizer.json
asm = open("example-order_total-apple-arm64-O0.asm").read()
print(model.decompile(asm, "apple-arm64-O0")[0])
print(model.decompile(asm, "apple-arm64-O0", context=open("example-order_total.h").read())[0])

Examples

example-count_words.c and example-order_total.c (+ .h) were built with clang -O0 / -O2 -shared; the .asm files are their listings. order_total at -O0, with the declarations from example-order_total.h:

int order_get(struct order *order) {
    int sum = 0;
    for (int i = 0; i < order->count; i++) {
        sum += order->items[i].price * order->items[i].quantity;
    }
    return sum - sum * order->discount_percent / 100;
}

Without the declarations the loop is right but the struct is invented (m->p[i].weight * m->p[i].delta) and the discount reads the wrong field. At -O2 the model drops the subtraction and returns only total * order->discount_percent / 100 – check optimized output carefully.

Input format

The model was trained on one exact listing format (arm64-v1), which python -m pramen_arm asm produces from the binary: Capstone 5.0 disassembly, upper-case mnemonics and registers, no spaces after commas, local branch targets as LAB_n: labels, calls and data references by symbol name (BL _strlen, ADRP X8,_total), string and constant literals as STR_n: / CONST_n: lines at the end. Text copied from objdump, otool, IDA or Ghidra is formatted differently and is not converted yet – use the binary.

Declarations (--context)

Plain C: struct / union / enum definitions, typedefs, extern globals and prototypes of called functions – only what the function uses. They are rewritten automatically into the one-line form the model was trained on (struct item {int price; int quantity; };); comments, #include, #pragma and include guards are dropped.

Prompt format

<|asm|>{variant}
{listing}
<|c|>
{declarations, optional – one per line, then an empty line}
{C code}<|endoftext|>

The newline after <|c|> is merged with the first word of the C code in training (\nint is one token). The included runtime removes it from the prompt and lets the first generated token start with a newline; if you write your own inference, do the same, otherwise the model starts with fragments like nt f(…).

Training

  • Data: 4.29 M C functions from ExeBench (train_real_compilable, train_synth_compilable), each compiled with Apple clang 17.0.0 at -O0, -Os and -O2 and linked into a small dylib (calls to own functions stay direct BL, libc goes through stubs). After removing duplicates and anything equal to the evaluation functions (exactly or structurally): 10.2 M examples, 5.3 B tokens.
  • Declarations: 30 % of examples that have them carry full declarations, 23 % only prototypes, 47 % none.
  • Stripped binaries: in 40 % of examples the names of functions and data defined in the image are replaced by sub_n / DAT_n in the assembly, the C and the declarations.
  • No extra C corpus (unlike the Windows / DOS models); the model learns C only from the target functions.
  • Run: 60 000 steps × 32 × 4 096 tokens (about 7.9 B tokens), AdamW (β 0.9 / 0.95, weight decay 0.1), learning rate 3e-4 → 3e-5 (cosine, 2 000 warm-up steps); loss on assembly tokens weighted 0.25. Dev loss on C: 0.48.
  • Architecture: 16 layers, 1 024 hidden, 16 heads, MLP 4 096, context 4 096, learned positions, tied embeddings – the tensor names are the same as in radix16/pramen-223m.

Limitations

  • one function at a time, up to ~3 500 input tokens
  • Apple clang 17 only; GCC / Linux AArch64 code and other clang versions are out of distribution (they read fine, but the model has not seen them)
  • C only – Objective-C, Swift and C++ are out of distribution
  • jump tables: the listing ends before data in code and BR Xn stays an indirect jump, so switch targets are not visible
  • without declarations, structs and globals are only offsets and addresses; the model guesses their meaning
  • no int8 copy, no GGUF

License and data

Model weights and code: Apache-2.0. The training functions keep the licenses of their original GitHub repositories (as collected by ExeBench). Decompiled code of third-party software is still subject to its original license.


Česky

Pramen ARM 223M je neuronový dekompilátor, který z assembleru jedné funkce AArch64 napíše C. Je to sourozenec pramen-223m a pramen-498m (Windows a MS-DOS) se stejnou architekturou a formátem promptu, ale s vlastními daty a tokenizerem. Míří na kód z Apple clangu (macOS, iOS) bez optimalizace, -Os a -O2. Na neoptimalizovaném kódu bývá výstup správně (HumanEval-C 76 %, s --candidates 8 91 %), na optimalizovaném se často přeloží, ale logika nesedí (24–35 %). Vstupem je binárka (Mach-O arm64 nebo ELF AArch64): python -m pramen_arm decompile program --function main --variant apple-arm64-O0 --model .. S --context typy.h dostane model deklarace, které funkce používá – na odložených funkcích se pak přesně stejný assembler podaří u 50–67 % místo 24–35 %. --candidates 8 vybere nejlepší z 8 návrhů podle zpětného překladu (potřebuje Apple clang z Xcode Command Line Tools).

Downloads last month
20
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including radix16/pramen-arm-223m