All good compilers do this today. They use heuristics to guess what the likely outcome of branches, but you can provide them specific information with profile guided optimization, or with manual branch hits (the __builtin_expect I used in the example above is one such hint).
Similarly, you can annotate certain functions or paths "hot" or "cold", and compilers even understand that functions like abort() are cold (they can be called at most once, after all) and hence paths leading up to them are also cold.
Similarly, JIT compilers use the runtime observed branching behavior to organize branches so that fall-through is the common case.
This was done before linking, based on analysis of the common paths from a running program
What this also did - which was the important bit at the time - was move all the error code to pages that wouldn’t be loaded for most users
So it moved error handling out of common code pages and changed branch instructions to mostly fall through
This was many years ago - do similar tools exist in the OSS community?