Yes. You want a program transformation system (PTS). These are designed to parse code, apply code-shuffling operations defined in terms of syntax, and then regenerate source code with the changes. They tend to use ASTs to ensure that there is no problem misinterpreting text.
To do this right, you have convince the tool to pick you your operand pairs, compute the type of the subexpression, and manufacture temporary variables with the appropriate types. And it has to be able to parse and analyze C, which is rather hard to parse esp. if you include preprocessor conditionals and macros. Not many PTS are capable of this. Practically nothing else is capable at all.