Copy Instruction from one Basic block to another

I have created a new basic block. Now I want to make copy of instructions from one basic block to another . How to do that ?

See CloneBasicBlock @ Transforms/Utils/Cloning.h

I want to do the following:

suppose the program structure:

bb
/
bb1 bb2
\ /
bb3

bb4
Now I want to create a new basic block, say bb5 between bb2 & bb3, copy some instructions from bb3 to bb5. Then I want to add between bb2 and bb3, then outgoing edge from bb5 is to be attached with bb4. Finally my program will look like :

bb
/
bb1 bb2
\ /
bb3 bb5
\ /
bb4

Can you please help me out? How to proceed onto it? Thanx in advance.

Sounds like what the jump threading pass does (IIRC) if it figures out
that the terminator of bb3 can be simplified if control enters it from
bb2 (and bb3 is simple enough). Maybe you should have a look at
lib/Transforms/Scalar/JumpThreading.cpp?

Don't forget to handle the case where any of bb3's instructions are
used outside bb3; you'll need to insert a PHI node in bb4 for each
such instruction, merging the original and the copy.