Your code is extremely difficult to read and understand due to the excessive use of goto statements and labels. This creates chaotic control flow, making the execution fragmented, hard to follow, and prone to errors. Maintaining and modifying such code is unnecessarily complicated.
There is absolutely no need to use goto here. Instead, you should structure your logic using functions, loops, and conditional statements. Break the code into smaller, meaningful functions, and use structured programming principles to guide the execution flow naturally.
And let’s be clear - this isn't some advanced topic that requires a professor to solve. Any schoolboy with a little experience can rewrite this in a structured way without goto. It’s just a matter of approaching the problem correctly.
If you're struggling to refactor a specific part, describe what you're trying to achieve, and I'll help you restructure it properly.
The best way in this case in my opinion is just to discard this code entirely and start fresh with a properly structured approach. Trying to untangle and refactor this goto-ridden code will likely take more effort than writing a new, well-organized version from scratch.
If you don't have extensive experience, deciphering what this code actually does will be extremely challenging. Understanding such an unstructured flow requires deep knowledge of both low-level programming concepts and high-level software architecture, as well as significant experience in reading and restructuring complex code.
Instead of struggling with this, it's far more efficient to rethink the logic and implement it properly using functions, loops, and clean control flow from scratch. You'll end up with code that's easier to maintain, debug, and extend in the future.
In short, writing code without goto doesn’t require a PhD in Computer Science or even extensive experience. However, thoroughly understanding and untangling a codebase filled with goto statements—like the one you've presented—is a genuinely complex task. It demands significant expertise, deep knowledge of programming at both low and high levels of abstraction, and extensive experience. In this case, the skills and knowledge of a PhD in Computer Science would actually be highly beneficial.
Looking at this code, it's quite evident that the person who wrote it didn’t fully understand what the code actually does. The excessive use of goto and arbitrary jumps suggests a lack of structured design and a poor grasp of fundamental programming principles.
Because of this, refactoring this code properly is a difficult task - not just because you need to rewrite it correctly, but because you first have to decipher and reverse-engineer a messy and flawed implementation to even understand what it was supposed to do in the first place.