Insert new basic blocks

Using Module Pass
How could I insert new basic blocks such as

while(i==1) {}

in the IR and also change the predecessors and successors according to inserting these basic blocks.

You can get the context of the module and the function which you want to insert the basicblock.
Then you can use
BasicBlock::Create(context, “NameofBasicBlock”, F);
to create your basicblock.