Wayne Shorter tunes are incredibly difficult to analyze using conventional functional harmony techniques, although it can be done. All of his compositions are MASTERFULLY crafted - he was thinking something very specific for every chord he chose, and his use of chromatic relationships and voice-leading between chords provides a fascinating study.
The key center for all of this tune is F. There are moments where it skirts the edge of what works in that key, but for the most part it's all in F. The first four bars are really interesting, and provide an extremely ambiguous sort of V-I cadence. You can take all of the possible notes of an E7 altered chord scale, (E, F, G, G#, Bb, C, D) and re-interpret them as C7(9,b13)/E, which very easily leads to a traditional V-I analysis. This in theory could be considered a VII7-I cadence, such as in tunes like Whispering, Groovin' High and Meditation, although the chord/scale relationship for that kind of specialty 7th chord is always mixolydian, never altered.
The harmonic function in the first two bars is more even more ambiguous than this, because of its feminine dominant cadence. In classical terminology, when the dominant chord in a V-I cadence was placed in a weak harmonic rhythm, it was called a masculine cadence, and when it was placed in a strong harmonic rhythm, it was called a feminine cadence. Contemporary music overwhelmingly is based upon masculine cadences, with very few exceptions. When they do occur, they very often obscure the tonal center, which is one reason why it might be hard to hear "F" as the tonic. Since Fmaj7 is placed on the weak harmonic pulse, and E7(alt) is on the strong one and repeats again in the next four bar phrase, it's entirely possible to ear "E" as the tonic, even though the chord quality is unstable.
The resolution of the E7(alt) to the Ebmaj7(#11) in the next bar is vaguely a substitute dominant relationship, although subV's in their traditional usage will never have a altered chord scale (occasionally #9 if you're Duke Ellington, never b9 though) Ebmaj7(#11) is modal interchange from F mixolydian, and is a common modal interchange chord.
More importantly, and probably what Wayne Shorter was thinking with the chord, the Ebmaj7(#11) is part of a chromatic root motion that starts in the third bar. Fmaj7 goes to E7(alt), goes to Ebmaj7(#11), to D7, and then "bounces" back up to Ebmaj7, to E7 and then back to Fmaj7. All voices in all chords are relating to each other by a step in the same direction, and so the resulting voice leading in parallel and similar motion is very smooth. The D7 is traditionally interpreted as the "V7 of II" in the key of F, but the chromatic motion obscures its expected resolution. Instead, it relates back to the bVIImaj7 chord of Ebmaj7 the same way E7alt relates to the tonic Fmaj7 - 7th chord resolving to a maj7 up a half step. We eventually get back the same way we descended - all chromatic half steps, to Fmaj7
The first ending is a real refresher from all this chromatic harmony, it's pretty straight forward. The Ebmaj7 (bVIImaj7) in bar 12 is a nice link to get the VI-7, followed by a V7/V, which has delayed resolution down a half step (the subV7 relationship) two bars later to the Gbmaj7. A II-7 sets up the chromatic downward cadence in bar 15.
The second ending has a similar traditional, functional relationship, although there are a few little tricks. The Db9#11 is the subV/V, which is followed by the G-7, or II-7. Both set up an expectation for a V7 chord, but instead we get the subV7/I chord, Gb7 and it's related II-7, Db-7. The Db-7 is said to be an interpolated II (whenever you have ANY dominant 7 chord, you can "interpolate" its related II-7 chord, whether its related to the key or not). The relationship between this measure and the final measure has the same relationship as the first two measures and the second two measures - its a feminine dominant cadence that provides a little bit more ambiguity. Even though this isn't the strongest cadence (it's feminine and the root motion isn't typical for a final cadence) the Fmaj7 at the very end provides the strongest tonal picture, and sums up the relationships between all the chords within the context of F.
Overall, in typical Wayne Shorter fashion, you have a tune that incorporates functional harmony in new, interesting ways that directly obscure the functional relationship.