How do you write highly optimized low-level firmware in C or C++ while managing memory manually and avoiding memory leaks or race conditions?