Broken Knee IK HELP!

Why is the IK doing this? 3rd imagine shows how the knee is suppose to bend. 4th shows when the IK is working, it’s just when the leg bends further back. It’s as if the trig math that calculates the “knee’s position” gets screwed up somehow.