Well, spaghetti code is not about optimization. Everybody can create code that machine will understand. Making a good code is when it's understandable for another programmer. Where everything is in it's right place.
Imagine you want to surprise your partner and make him/her breakfast in bed. You wake up, go to kitchen, make french toasts, boil some eggs, maybe fry some bacon (an american/British thing), maybe prepare some cottage cheese for the toasts, etc. And then you take the plater to the bedroom and both of you have a delightful morning.
This is an example of a good code, where every action has it's own place in their "domains".
Now imagine, that again, you want to make a breakfast in bed for your partner. Again, you make french toasts, some bacon, boil some eggs. And you do your meal preparations... in the bedroom... That's what we call a spaghetti code - you find a function (for example settings) in block that does something totally different (let's say animations), that has totally different domain.
Long story short: AI chat is only for finding answers, not for using their code itself in yours.
I will try to create a sandbox Windows instance (dunno about Win11, but in Win10 there is a native Sandbox app) and I'll try to decode this app on the weekend.