LLVM used to provide llc -march=cpp test.ll -o test.cpp
instruction to learn C++ API, but this is not available in llvm 12.
Unfortunately, there is no alternative. The reason why C++ backend was removed long time ago is quite simple: it did not serve its main intention to be a guide to LLVM C++ API well, it generated suboptimal code and was not updated to support the latest changes to C++ API.
You can use the code of existing transformation passes to learn LLVM C++ API