I'll go out on a limb here ....
The next time you do a hard trip at altitude, figure out how to eat 150 to 200 calories per hour, while you're hiking, rain or shine, want to or not. It means finding stuff that you like, and can eat, and will eat. Preferably high in carbohydrates, like 70% or more. And then take 300 calories per hour. When you feel like crap, stop, rest, and eat some more. You may bring some of it back, but that will diminish as you "tune the system".
Don't call it a hike. Call it a "food training walk". The goal is to learn what your body needs to be happy. Learn to recognize (early), acknowledge, and deal with the symptoms of "Low Fuel" and "Tank Empty". You mention them above. Andrew F. echos your observations.
A 20 mile, 4000', 10 hour day, all by itself requires about 3000 to 3500 calories, maybe more. (YMMV and all of that.) If you are fit, and your 2 mph pace is 20 beats below your lactic threshold (you can easily carry on a long-winded conversation), you can get 25% of those calories from body fat. Otherwise, you have to eat more carbs.
For hard 10 hour "first days" I'll eat 5 PowerBars (1,200 calories), a ProBar (360), a 2 ounce snack bag of chips (300), a 2 ounce bag of Chex Party Mix (300), a "Fun Size" Snicker Bar, and some gum drops, for a total of 2,500 calories. (Which is probably to little, and why I lose about 1/2 pound a day.)
I don't think you were anywhere close to that. (Not counting dinner and breakfast.)
...stepping off the soapbox.