It seems to be a result of J-M Bony that every nonnegative function in $C^{2m}$ is a sum of squares of two $C^m$ functions, which means that every $C^\infty$ function is the sum of squares of two $C^\m$ functions for any $m$ (which, I suppose, does not mean that you can do it with two $C^\infty$ functions -- the counterexamples are attributed to Paul Cohen and D.B.A. Epstein -- see references 1and 4 in the cited paper): the reference is:
For functions from $\mathbb{R}^k \rightarrow $\mathbb{R}_+$ these results are extended in: