How to change waste pipe fitting with a small amount of male pipe to work with?
The bad news:
As already noted: you don't have enough pipe left inside the house to cut that clean out off and glue a new one one.
The good news:
It looks like they ran the 4&quot; pipe through a 6&quot; pipe sleeve, then packed it with (mortar?) to seal it. This means that instead of breaking up the foundation wall to replace the pipe, you &quot;only&quot; have to dig out the mortar inside the sleeve!
You'll have to:

Excavate on the outside down to the 4&quot; drain
Open up enough of a trench that you can cut it off outside the wall, leaving enough exposed on the downstream side to put a new slip joint connector on
Cut off the clean out and 45° inside.
Remove all that mortar from inside the sleeve
Remove the section of 4&quot; through the wall
Replace the 4&quot; through the wall
Plumb in new waste lines as appropriate inside

Sorry, while it's simple it's not going to be easy...