Optimizing stack memory requirements for real-time embedded applications