Skip to content

Instantly share code, notes, and snippets.

@robstewart57
Created February 3, 2015 13:59
Show Gist options
  • Save robstewart57/c6be7dd6a496a8d028c7 to your computer and use it in GitHub Desktop.
Save robstewart57/c6be7dd6a496a8d028c7 to your computer and use it in GitHub Desktop.
simple C to LLVM
/* C code */
int add(int x, int y)
{
return (x+y);
}
int main()
{
return (add (2,3) );
}
/* corresponding LLVM IR for `main` from `clang` */
define i32 @main() #0 {
entry:
%retval = alloca i32, align 4
store i32 0, i32* %retval
%call = call i32 @add(i32 2, i32 3)
ret i32 %call
}
/* corresponding LLVM IR for `main` from `clang -O` */
define i32 @main() #0 {
entry:
ret i32 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment