I have auto-generated benchmark files in LLVM IR, but to extract loop bounds using another tool I need them in C. Converting to C is fairly simple using llvm-cbe/Julia (as suggested in comments in this post) or llvm2c. However, as far as I got, both tools represent the entire control flow with gotos, which makes the result a C program, but not much more usable. For example, this excerpt just represents some if/else constructs.
gene_glob_input_variable = llvm_cbe_gene_arg;
llvm_cbe_tmp__1 = gene_glob_input_variable;
llvm_cbe_arith1 = llvm_cbe_tmp__1 ^ 253077109;
llvm_cbe_tmp__2 = gene_glob_input_variable;
if (((((llvm_cbe_tmp__2 & -129) == 0u)&1))) {
goto llvm_cbe_br1_2e_then;
} else {
goto llvm_cbe_br1_2e_else_2e_wcp;
}
llvm_cbe_br1_2e_then:
llvm_cbe_tmp__3 = gene_glob_input_variable;
*((uint32_t*) alloca(sizeof(uint32_t))) = llvm_cbe_tmp__3;
llvm_cbe_tmp__4 = gene_glob_input_variable;
*((uint32_t*) alloca(sizeof(uint32_t))) = llvm_cbe_tmp__4;
goto llvm_cbe_br1_2e_end_2e_wcp;
llvm_cbe_br1_2e_else_2e_wcp:
*(volatile uint16_t*)(&cons0) = (((uint16_t)llvm_cbe_tmp__1));
*(volatile uint16_t*)(&cons0) = (((uint16_t)llvm_cbe_tmp__2));
llvm_cbe_tmp__5 = gene_glob_input_variable;
if (((((llvm_cbe_tmp__5 & -1048577) != 0u)&1))) {
goto llvm_cbe_br2_2e_then_2e_wcp;
} else {
goto llvm_cbe_br2_2e_else;
}
Is there a way to reconstruct if/else and for loops from C with gotos, or is there a way to use these tools to make that happen directly from .ll files? The constructs selected for generation in the benchmarks are fairly simple, so a solution with incomplete loop reconstruction would suffice. Thanks for any hint.