Dimwitted Sage

This site is being rebuilt. Some pages and posts are still in progress.

Decompiling on a Budget

May 22, 2026
Part 1 of 1 in Taking NES Games Apart

One of my desires in software development has always been to gain a greater insight into how things work in software. A well functioning decompiler has always seemed like a massive undertaking because the optimizations performed by a compiler would lose so much contextual information from the original source code, that it would be of little utility translated (i.e., transliteration of assembly). It was several years ago that I became familiar with Kaze Emanuar’s effort to raise the Mario 64 frame rate through recompilation of reverse engineered source. It’s my understanding that a lot of this translate work was performed manually by developers. It seems like the evolution of AI would be able to do this at a much more rapid rate. I thought that doing a series on this would be interesting and allow analysis and modification of issues like those highlighted in other retro-focused videos such as https://youtu.be/3G6vkRz-_0I.

My early interactions with AI outside of company usage were on a non-API basis. I subscribed to OpenAI Pro, but relied heavily on copy-paste workflows to integrate any output, which of course negated any benefits of automated tool execution. As more tech companies introduced their own chatbots, driving down the cost of quality chatbot interactions, I began to use Google Gemini more frequently. From here I began laying the framework of my approach to reverse engineering.

Google Gemini recommended creating an embedded vector DB relating src code line to assembly segments, reversing direction to rebuild high level language from lower level inputs. Now the question is how to effectively generate this DB with enough expert knowledge to generate the src code. The lack of llvm-mos library support complicates the ease of taking existing library of src code to build for NES so I began looking at means of automation. In order to limit the cost associated with API tokens I started using ollama to see what local models on my 8GB Mac Mini are capable of. After trying a variety of models, it became clear that the existing 3-4GB models are not proficient at writing C that can be compiled by llvm-mos or making tool calls as an orchestrator. I do have access to my son’s gaming system with 16GB graphics card, but at least the early models I’ve attempted to use don’t seem like a slam dunk of capability for the additional overhead of integration and latency problems that I have working with a system that isn’t always on or is frequently busy “gaming”.

I also began playing with different LLM harnesses during this time. Most of the more commercial products like Cursor and competitors seemed to work well enough at first, but after burning through all of the “free” tokens from joining in a matter of no time, I wasn’t ready to begin subscribing to a product that looked like it would require paying a premium for tasks of higher complexity. I began to try to integrate ollama with IDEs like VS Code. First, decoupling VS AI plugins from Copilot seemed non-intuitive and then the customization of agents didn’t seem sufficient to address the limitation of the ollama agents. I then began to look at more custom agent technologies from minimal implementations to pi that Clawdbot was based on. Still, my local ollama agents weren’t able to reliably generate src code examples that compiled so I determined I was willing to invest more in making the project progress so I put $50 into a Gemini account and continued using pi AI integration.

Direct Gemini integration made a slight change in original approach for vector embedding DB by introducing an IR lifter from assembly. The idea was that an AI model would do a better job translating IR <-> source code using operational semantics rather than assembly with specific address references that might confuse the model.

Source to IR and Back Known C examples neslib examples + synthetic C mos-nes-nrom-clang compiled with llvm-mos llvm-objdump + llvm-nm assembly with specific addresses IR lifter: analysis_engine.py CFGBuilder basic blocks split at function symbols IRStructurer operations, loops, folded call args Vector DB IR ↔ C pairs IR → C lookup TF-IDF loses instruction order Recompile fails, even for small snippets
Source → IR → source

Moving to Gemini models dramatically improved the performance of AI automation, but I still find that almost one in five requests fails. I continually see Gemini 3+ models being inaccessible due to the model “experiencing high demand”. The 2.5 models complain about token rate allowance. This might be a configuration issue but feels more like a membership tier limitation and after throttling pi integration to control token usage rate, I began to see that model was inaccessible as well from high demand. It feels like I’m spending significantly more than what I’m getting in return for my investment. My frustrations are increasing because Gemini access seems more and more unstable and my attempts to recompile decompiled example code are still failing to compile, program -> IR -> program for very small snippets.

These are not the results I was looking for, I think I will need to revisit the approach.