how to get an independent copy of a function?

Hi,

I need to get a copy of a function which should be 'selfcontained'
(independent from the original function). Just like in C making a copy of a
functions source code, changing the name.

I tried to copy the basic blocks and their instructions (clone) to a new
function, but the module check gives 'referring to an argument in another
function'.
This seems obvious, because the clone on instruction level can not know that
the instruction later should belong to another function.

I could not find some sort of copy method on function level...

Alex

include/llvm/Transforms/Utils/Cloning.h