A Question

You can generate IR for the declarations while you're transforming it.
Once you've loaded the
.bc into a Module, you can call
module->getOrInsertFunction("pthread_XXX", etc.). As long as
you don't add any BasicBlocks to it, it's a declaration. Just create
calls to it where needed.

As soon as you're finished modifying the Module, write it out with the

Or wrap your transformer up in a Pass and just add the declarations to
the module in your pass init and insert calls to them in your

Hopefully, your transformer won't have to even look at the C source.