Build AST from C code
First, it is a difficult task, because the abstract syntax tree of C is much more complex than what you believe it is. Read the C11 standard n1570 for details, and see this website. Look also into tinyCC or nwcc (at least for inspiration).
Then if you are using a recent GCC (e.g. 4.7 or 4.8), I strongly suggest customizing GCC e.g. with a MELT extension (or your GCC plugin).
I don't claim it is a simple task, because very probably you need to understand the details of GCC internal representations (at least GIMPLE)
BTW, MELT is (was) a domain specific language to extend GCC, and is designed exactly for the kind of tasks you are dreaming about. You would be able with MELT to transform the internal GCC representations (Gimple and Tree-s). Today in 2020, MELT is not worked upon because of lack of funding.
The advantage of working inside GCC (or inside some other compiler like Clang/LLVM) is that you don't have to spit back some C code (which is actually much more difficult than what you think); you just transform the internal compiler representation and, perhaps most importantly, you take advantage "gratis" of the many things a compiler always do: all kind of optimizations like constant folding, inlining, common-subexpression elimination, etc, etc, etc, ....
In 2020, you could also consider using the libgccjit framework inside recent GCC 10, and read this draft report (related to Bismon; but see also RefPerSys, sharing some ideas but no code with Bismon). Try perhaps also the Clang static analyzer and/or Frama-C.
What you are asking for is a C source-to-source transformer. Such a tool is very difficult to build, partly because of the inherent complexity of C, and partly because of the C preprocessor: the AST may contain fragments from system headers etc. that you need to handle properly while unparsing (emitting C code again at the end).
You could give Robert Grimm's SuperC a try: https://cs.nyu.edu/rgrimm/xtc/ That particular parser is supposed to handle all of C (including the preprocessor bits). I don't know if it can handle unparsing, but that should be comparatively easy (read: still lots of work) to do.