How do compilers detect the need to replace high-level code with a hard-coded three-number sorting algorithm? As someone not deeply familiar with compiler internals, I'm eager to understand the underlying mechanisms. Could anyone shed light on how modern compilers recognize situations where it's beneficial to replace generic code with optimized assembly instructions specifically designed for sorting three numbers?