Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created April 27, 2019 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaskollmer/5d4627df1319c068b91e423c92fa569d to your computer and use it in GitHub Desktop.
Save lukaskollmer/5d4627df1319c068b91e423c92fa569d to your computer and use it in GitHub Desktop.
; ModuleID = 'main'
source_filename = "main"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin18.5.0"
declare i32 @atoi(i8*)
define i32 @main(i32 %argc, i8** %argv) {
entry:
%0 = alloca i32
%1 = getelementptr i8*, i8** %argv, i64 1
%2 = load i8*, i8** %1
%3 = call i32 @atoi(i8* %2)
%4 = call i32 @_F3fibii(i32 %3)
store i32 %4, i32* %0
br label %return
return: ; preds = %entry
%5 = load i32, i32* %0
ret i32 %5
}
define i32 @_F3fibii(i32 %n) {
entry:
%0 = alloca i32
%1 = sext i32 %n to i64
%2 = icmp eq i64 %1, 0
%3 = sext i32 %n to i64
%4 = icmp eq i64 %3, 1
%5 = or i1 %2, %4
br i1 %5, label %7, label %6
; <label>:6: ; preds = %entry
br label %8
; <label>:7: ; preds = %entry
br label %match_merge
; <label>:8: ; preds = %6
%9 = sub i32 %n, 1
%10 = call i32 @_F3fibii(i32 %9)
%11 = sub i32 %n, 2
%12 = call i32 @_F3fibii(i32 %11)
%13 = add i32 %10, %12
br label %match_merge
match_merge: ; preds = %8, %7
%14 = phi i32 [ %n, %7 ], [ %13, %8 ]
store i32 %14, i32* %0
br label %return
return: ; preds = %match_merge
%15 = load i32, i32* %0
ret i32 %15
; uselistorder directives
uselistorder i32 (i32)* @_F3fibii, { 1, 2, 0 }
uselistorder i64 1, { 1, 0 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment