--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/sqr.ll Mon Oct 28 13:34:03 2019 +0000
@@ -0,0 +1,24 @@
+@.str = private constant [4 x i8] c"%d\0A\00"
+
+declare i32 @printf(i8*, ...)
+
+; prints out an integer
+define i32 @printInt(i32 %x) {
+ %t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
+ call i32 (i8*, ...) @printf(i8* %t0, i32 %x)
+ ret i32 %x
+}
+
+; square function
+define i32 @sqr(i32 %x) {
+ %tmp = mul i32 %x, %x
+ ret i32 %tmp
+}
+
+; main
+define i32 @main() {
+ %1 = call i32 @sqr(i32 5)
+ %2 = call i32 @printInt (i32 %1)
+ ret i32 %1
+}
+