Back to assembler for this one.
To solve this one, I immediately started reverse engineering the code as I was guessing running the code with different values for register 0 would just require way too much time, especially since it’s possible for the program to never end. I noticed in my program that the only time register 0 is used, is to compare it with register 5 on instruction 28: if they are both equal the program stops, otherwise it loops back.
I then made my program run until I hit instruction 28 and return the value of register 5 at that point. This solved the first part of the problem.
For the second part, I reverse engineering further but failed as I had forgotten a branch I think. So I decided to record all the values in register 5 at instruction 28 until I found a value I had already seen. This gives all the values for register 0 for which the program eventually halts. The last of these is then the value for which the program takes the most time to stop.