How can I get llvm ir representation with specific compiler options in memory?

Hi, I need to create graphs for every loop in an optimized llvm ir object and put it into a mapper.

In order to do that, I would need to compile the source file into llvm ir representation in memory and start from that to create graphs.

I tried to ask gpt and search on internet but haven’t found any good examples, all I can find is an example of using opt to load user defined pass to do that.

I would prefer to have the program it self to read the source file, hand it over to clang API and get llvm ir in memory representation. And it is better in C since the mapper is written in C (C++ would also be very fine).