Not sure if compilers are intelligent enough to take care of memory management in terms of functions.
But functions are very useful for reducing memory usage. every time a function returns, all the local variables are destroyed and the related memory region is freed up.
if the same have been implemented with all the code in main without functions then all the memory taken by main() variables, would have been taken through the program run-time life until the end of program.