When One LLM Fixes Another's Code: A UEFI Game Repair Experiment
This article describes an experiment in which one large language model took over a half-finished UEFI game project left by another model and repaired it through code review, debugging, rendering optimization, and input handling. It covers specific issues such as GOP protocol GUID misconfiguration and dangling pointers after QueryMode/SetMode, then summarizes what the experiment suggests about LLM code repair, model capability gaps, AI-assisted development workflows, and low-level software engineering.
When One LLM Fixes Another’s Code: A UEFI Game Repair Experiment
In an earlier test, I asked two mainstream large language models to complete the same kind of low-level programming task: build a game from scratch in a UEFI environment. One model performed well. It delivered a runnable brick-breaker game in two and a half hours, compiled successfully on the first attempt, and ran correctly the first time. The other model spent nearly six hours and still failed—it could not even complete the build environment.
After I shared the comparison, a reader raised a sharp question: is it fair to compare two models when they were given tasks of different difficulty?
The criticism was reasonable. But I had not changed the task to avoid the hard part. I simply found it uninteresting to make an AI repeat the same task, and I was not trying to produce a rigorous head-to-head benchmark. What I wanted to explore was a different question: what role can large models actually play in real, complex engineering scenarios?
Then I looked back at the code left by the failed model and saw a new angle. The code did not run, but its structure was surprisingly reasonable: seven source files, modular design, clear layering, and even a basic wrapper for the graphics output protocol. Throwing it away felt wasteful.
So a new idea emerged: let Model A, which had just performed well, take over Model B’s unfinished project and try to clean up the mess. Using AI to repair AI-generated code—magic defeating magic—seemed more interesting than writing the game again from scratch. It also felt closer to the daily reality of developers, who constantly work with legacy code.
The test was still divided into two rounds. The first round aimed to get the code basically running. The second focused on refinement and optimization.
Round 1: From Dead Code to a Running Program
I copied all source code left by Model B into a new environment, started Model A, and began the first debugging round.
Step 1: Code Review
The first instruction was straightforward: review this code and identify possible problems.
Model A analyzed each module one by one—the entry function, main loop logic, game state machine, rendering module, and input subsystem. A few minutes later, it produced a detailed list of issues. Unlike a conventional manual review, Model A did not just list surface-level problems. It also provided repair suggestions and code snippets. It was not satisfied with merely identifying issues; it directly proposed fixes.
“Apply these changes and it should run,” it said.
I followed the instructions.
Issue 1: Program Exit
On the first run, startup logs appeared in the UEFI Shell, the screen flashed “Starting Game Loop,” and then the program exited immediately.
There was no crash report, but this was only slightly better than not running at all. It was still far from “working.”
I instructed Model A to add more debug output and monitor the execution path in real time through the serial port. It quickly identified a key clue: the program behaved abnormally after calling the GOP protocol.
A closer review revealed the problem: the info structure pointer returned by the QueryMode interface pointed to a dangling pointer. After calling SetMode to switch the graphics resolution, that memory had already been released by the system. Subsequent access to fields such as info->PixelsPerScanLine therefore touched invalid memory.
The fix was direct: after SetMode, call QueryMode again to retrieve the frame buffer information, ensuring that all pointers refer to valid memory.
After the change, the program no longer exited and remained stable in graphics mode.
Issue 2: Incorrect GUID Configuration
The program could now run, but the screen remained black and the graphical interface did not appear.
I reported this back to Model A. After analyzing the runtime logs, it found a problem with the GOP protocol GUID configuration. In this firmware development kit, multiple GUIDs related to the graphics output protocol are defined. Some are used to locate device paths, while others identify the protocol interface itself. Using the wrong GUID prevents the program from correctly obtaining the graphics output protocol, and therefore it cannot get a usable frame buffer address.
After fixing this configuration, the game interface finally appeared on screen. It was still rough—blocks were drawn with simple characters—but at least the program was running correctly.
The first round achieved its goal: the code moved from completely unusable to runnable, though not yet polished.
Round 2: Refinement and Performance Optimization
The first round got the program running, but the user interface and interaction experience were still in a “works but not pleasant to use” state. The second round focused on refinement.
Resolution and Aspect Ratio
The initial program used the system default resolution, but the image was severely stretched and the block proportions were distorted. Model A proposed a plan: switch the display mode to a higher resolution while redesigning the base block size and grid layout parameters.
It adjusted cell size, row and column counts, and grid margins so that the game maintained a reasonable aspect ratio on widescreen monitors. All of this was calculated in real time by modifying the HorizontalResolution and VerticalResolution fields returned by QueryMode, ensuring adaptability across different hardware environments.
Rendering Performance Optimization, Slightly Redundant but Useful
Because the UEFI environment has no GPU acceleration, all rendering depends on the CPU writing pixels directly into the frame buffer. Although a block game does not have high performance requirements, Model A still made some micro-optimizations: it separated background erasure from foreground drawing, reduced the dirty rectangle area updated each time, and improved overall smoothness.
Keyboard Input and Polling
The game needed to respond to direction keys, rotation keys, and the exit key. Model A implemented a polling-based input capture mechanism: a background task in the SPL stage continuously scanned the keyboard device, obtained input events through the GetKeyStrokeEx interface, and mapped them to game logic commands.
Fixes and Polish
Several edge cases appeared during testing: new blocks were not generated correctly after a block reached the bottom; scoring was incorrect after clearing a full row; and pause/resume functionality was missing. Model A fixed these one by one and added a “next block preview” feature. That feature itself required a small refactor of the code structure and data flow, but Model A handled it cleanly.
Summary and Reflections
The entire test took about two hours: one and a half hours for the first round and half an hour for the second. The final delivered version had about 600 lines of core logic. It could be played normally, ran smoothly, and had complete logic.
The experiment left me with several observations.
First, large models’ code repair capabilities are already far beyond expectations. Faced with unfamiliar code, Model A could not only understand it but also locate bugs and provide practical fixes. This has more engineering value than generating code from scratch, because much of real-world development is essentially “read code, find bugs, and change code.”
Second, capability differences between models remain obvious. One model could write a runnable project from scratch, while another could not even get through the build environment. This is not simply a matter of “being good at” something. It may involve deeper differences in program generation strategy: whether the model truly understands the UEFI software development model, and whether it grasps the complete chain from protocol acquisition to frame buffer drawing.
Third, a new paradigm for AI collaborative programming is taking shape. Letting different models take over at different stages, or letting one model repair another model’s output, is becoming practical. This process of “AI cleaning up AI’s mess” may become part of developers’ daily work: using AI to accelerate code generation and also using AI to accelerate code repair.
Fourth, low-level software development remains a litmus test for AI. Unlike web front-end or general application development, programming in a UEFI environment involves multiple constraints: protocols, firmware lifecycle, memory restrictions, and platform-specific behavior. A large model’s performance in such scenarios reveals more about its “true engineering understanding” than its performance in common frameworks.
Of course, Model A was not omnipotent. It occasionally produced duplicate type definitions or failed to account for UEFI-specific calling conventions, but it could correct these through feedback loops. This “iterate—feedback—correct” interaction model is becoming a core workflow in the era of large models.
In the end, the discarded Tetris code that had been thrown into the trash ran successfully after Model A repaired it. No human edited a single line of code. The entire process was driven by natural-language instructions. That was not common before, but it is becoming increasingly ordinary.
