The problem now is, if I change the file that
contains foo(), I have to
 apply my patch again.  Or in other words, once I patch the output from the
 compiler, I can no longer use the compiler.  If this is a one time shot and
 I will only work with the output from then on, then no problem.  But
 otherwise ... 
No, it's not a problem.  You comment out (or ifdef) the function, and
specifically comment that the C code is a reference implementation, but that
the actual implementation is in another file, foo.s (or foo.asm, or whatever).
Any time that I hand-optimize some code, I *always* maintain the high level
language code as a reference implementation.