how to get the llvm IR from C source code?

Hi everyone.
I want to get the llvm IR from the C source code by LLVM-GCC. But I am not familiar with those command line arguments.
Can anyone give me a guidance? Thank you very much for any help.
Good luck.

Please run…

$ llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc

$ llvm-dis < hello.bc > hello.ll

The first command is to generate a byte code

and second is to translate the bytecode to a readable form.

Thanks!

Keun Soo Yim wrote:

Please run…

$ llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc

$ llvm-dis < hello.bc > hello.ll

The first command is to generate a byte code

and second is to translate the bytecode to a readable form.

llvm-gcc can emit the textual form directly too:

llvm-gcc -O2 -emit-llvm hello.c -S -o hello.ll
llvm-gcc -O2 -emit-llvm hello.c -S -o -

the latter will print it to standard out.

BTW, -O2 or any other optimization options can be omitted here if you intend to get raw (unoptimized) IR.