How to use SplitBlockAndInsertIfThen() correctly?

The way I have used SplitBlockAndInsertIfThen() throws this assertion error: “Assertion `IDomNode && “Not immediate dominator specified for block!”’ failed”. Consider the following abstraction:

I believe the problem comes from inserting instructions both at the THEN block and the beginning of the tail block. Any idea how’s that possible?