prepare C source program
for example sum.c
int main(){
int sum = 0;
for(int i=0;i<10;i++){
sum = sum + i;
for(int j=0;j<10;j++){
sum = sum + j;
}
for(int k=0;k<10;k++){
sum = sum + k;
}
}
}
compile C source program to IR file
run the script below to compile sum.c to sum.ll
clang -S -emit-llvm sum.c
generate CFG dot file from IR file
using opt command to generate .dot file
opt -dot-cfg sum.ll
mv .main.dot sum.dot # rename
#output:Writing '.main.dot'...
transfer dot file to PNG image
dot sum.dot -Tpng -o sum.png
and then, you can get
Thanks for your supports !