In general, yes, although you'll need to write your function in assembly to do so.
On the other hand, it looks like what you're doing is micro-optimising your code rather than benchmarking it. BOOLs and conditionals in C++ are really, really fast, and the cost of patching opcodes on modern systems can cause really really surprisingly bad performance penalties (for example, the call to VirtualProtect to make the code writable is going to cost hundreds of thousands more than a single conditional, and you'll force pipeline stalls and cache misses by changing the function inline even if you're running on an embedded system).
So in summary, yes, what you're doing is possible. But unless you are doing this as an "out of interest" excercise or run in a very strange environment where performance of conditionals is critically important but you still write in C, then you probably want to just benchmark your code instead and find the real places where it's slow, instead of going to huge amount of pain and effort to patch things that aren't actually performance critical.