Skip to content

Instantly share code, notes, and snippets.

@LefterisJP
Created February 19, 2017 11:54
Show Gist options
  • Save LefterisJP/a01ac0c6e67e6dd623b6cfa5013ab0cc to your computer and use it in GitHub Desktop.
Save LefterisJP/a01ac0c6e67e6dd623b6cfa5013ab0cc to your computer and use it in GitHub Desktop.
LLVM IR from demo.rf
[DEBUG]: Module "function_end" is
; ModuleID = 'stdlib'
source_filename = "stdlib"
%string = type <{ i32, i8* }>
%internal_struct_4260204557 = type <{ i32, i64, i64, %string }>
@strbuff_3855993015 = private unnamed_addr constant [5 x i8] c"false"
@gstr_3855993015 = global %string <{ i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @strbuff_3855993015, i32 0, i32 0) }>
@strbuff_706834940 = private unnamed_addr constant [4 x i8] c"true"
@gstr_706834940 = global %string <{ i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @strbuff_706834940, i32 0, i32 0) }>
declare i32 @printf(i8*, ...)
declare void @exit(i32)
declare i8* @malloc(i64)
; Function Attrs: nounwind readnone
declare void @llvm.donothing() #0
; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #1
declare void @rf_stdlib_print_int64(i64)
declare void @rf_stdlib_print_uint64(i64)
declare void @rf_stdlib_print_string(%string*)
define void @print(%internal_struct_4260204557*) {
function_start:
%1 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 0
%2 = load i32, i32* %1
%3 = icmp eq i32 %2, 0
br i1 %3, label %label_0, label %label_1
label_0: ; preds = %function_start
%4 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 1
%5 = alloca i64
%6 = load i64, i64* %4
store i64 %6, i64* %5
%7 = load i64, i64* %5
call void @rf_stdlib_print_int64(i64 %7)
br label %function_end
label_1: ; preds = %function_start
%8 = icmp eq i32 %2, 1
br i1 %8, label %label_2, label %label_3
label_2: ; preds = %label_1
%9 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 2
%10 = alloca i64
%11 = load i64, i64* %9
store i64 %11, i64* %10
%12 = load i64, i64* %10
call void @rf_stdlib_print_uint64(i64 %12)
br label %function_end
label_3: ; preds = %label_1
%13 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 3
%14 = alloca %string
%15 = getelementptr %string, %string* %13, i32 0, i32 0
%loaded_str_len = load i32, i32* %15
%16 = getelementptr %string, %string* %13, i32 0, i32 1
%loaded_str_data = load i8*, i8** %16
%17 = getelementptr %string, %string* %14, i32 0, i32 0
store i32 %loaded_str_len, i32* %17
%18 = getelementptr %string, %string* %14, i32 0, i32 1
store i8* %loaded_str_data, i8** %18
call void @rf_stdlib_print_string(%string* %14)
br label %function_end
function_end: ; preds = %label_3, %label_2, %label_0
ret void
}
attributes #0 = { nounwind readnone }
attributes #1 = { argmemonly nounwind }
[DEBUG]: Module "function_end" is
; ModuleID = 'main'
source_filename = "main"
%string = type <{ i32, i8* }>
%internal_struct_4260204557 = type <{ i32, i64, i64, %string }>
%foo = type <{ i32, i32, %string }>
@gstr_3855993015 = global %string <{ i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @strbuff_3855993015, i32 0, i32 0) }>
@strbuff_3855993015 = private unnamed_addr constant [5 x i8] c"false"
@gstr_706834940 = global %string <{ i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @strbuff_706834940, i32 0, i32 0) }>
@strbuff_706834940 = private unnamed_addr constant [4 x i8] c"true"
@strbuff_3735928559 = private unnamed_addr constant [0 x i8] zeroinitializer
@gstr_3735928559 = global %string <{ i32 0, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @strbuff_3735928559, i32 0, i32 0) }>
@strbuff_3855993015.1 = private unnamed_addr constant [5 x i8] c"false"
@gstr_3855993015.2 = global %string <{ i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @strbuff_3855993015.1, i32 0, i32 0) }>
@strbuff_885767278 = private unnamed_addr constant [5 x i8] c"hello"
@gstr_885767278 = global %string <{ i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @strbuff_885767278, i32 0, i32 0) }>
@strbuff_706834940.3 = private unnamed_addr constant [4 x i8] c"true"
@gstr_706834940.4 = global %string <{ i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @strbuff_706834940.3, i32 0, i32 0) }>
declare i32 @printf(i8*, ...)
declare void @exit(i32)
declare i8* @malloc(i64)
; Function Attrs: nounwind readnone
declare void @llvm.donothing() #0
; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #1
define void @print(%internal_struct_4260204557*) {
function_start:
%1 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 0
%2 = load i32, i32* %1
%3 = icmp eq i32 %2, 0
br i1 %3, label %label_0, label %label_1
label_0: ; preds = %function_start
%4 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 1
%5 = alloca i64
%6 = load i64, i64* %4
store i64 %6, i64* %5
%7 = load i64, i64* %5
call void @rf_stdlib_print_int64(i64 %7)
br label %function_end
label_1: ; preds = %function_start
%8 = icmp eq i32 %2, 1
br i1 %8, label %label_2, label %label_3
label_2: ; preds = %label_1
%9 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 2
%10 = alloca i64
%11 = load i64, i64* %9
store i64 %11, i64* %10
%12 = load i64, i64* %10
call void @rf_stdlib_print_uint64(i64 %12)
br label %function_end
label_3: ; preds = %label_1
%13 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %0, i32 0, i32 3
%14 = alloca %string
%15 = getelementptr %string, %string* %13, i32 0, i32 0
%loaded_str_len = load i32, i32* %15
%16 = getelementptr %string, %string* %13, i32 0, i32 1
%loaded_str_data = load i8*, i8** %16
%17 = getelementptr %string, %string* %14, i32 0, i32 0
store i32 %loaded_str_len, i32* %17
%18 = getelementptr %string, %string* %14, i32 0, i32 1
store i8* %loaded_str_data, i8** %18
call void @rf_stdlib_print_string(%string* %14)
br label %function_end
function_end: ; preds = %label_3, %label_2, %label_0
ret void
}
declare void @rf_stdlib_print_int64(i64)
declare void @rf_stdlib_print_uint64(i64)
declare void @rf_stdlib_print_string(%string*)
define i32 @main() {
function_start:
%0 = alloca i32
%1 = call i8* @malloc(i64 4)
%2 = bitcast i8* %1 to i32*
%3 = alloca %foo
%4 = alloca %foo
%5 = alloca %string
%6 = getelementptr %foo, %foo* %4, i32 0, i32 0
store i32 0, i32* %6
%7 = getelementptr %foo, %foo* %4, i32 0, i32 1
store i32 29, i32* %7
%8 = getelementptr %foo, %foo* %3, i32 0, i32 0
store i32 1, i32* %8
%9 = getelementptr %foo, %foo* %3, i32 0, i32 2
%loaded_str_len = load i32, i32* getelementptr inbounds (%string, %string* @gstr_885767278, i32 0, i32 0)
%loaded_str_data = load i8*, i8** getelementptr inbounds (%string, %string* @gstr_885767278, i32 0, i32 1)
%10 = getelementptr %string, %string* %9, i32 0, i32 0
store i32 %loaded_str_len, i32* %10
%11 = getelementptr %string, %string* %9, i32 0, i32 1
store i8* %loaded_str_data, i8** %11
%12 = getelementptr %foo, %foo* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %label_1, label %label_2
label_1: ; preds = %function_start
%15 = getelementptr %foo, %foo* %4, i32 0, i32 1
%16 = alloca i32
%17 = load i32, i32* %15
store i32 %17, i32* %16
%18 = load i32, i32* %16
store i32 %18, i32* %2
br label %label_0
label_2: ; preds = %function_start
%19 = getelementptr %foo, %foo* %4, i32 0, i32 2
store i32 0, i32* %2
br label %label_0
label_0: ; preds = %label_2, %label_1
%20 = getelementptr %foo, %foo* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 1
br i1 %22, label %label_4, label %label_5
label_4: ; preds = %label_0
%23 = getelementptr %foo, %foo* %3, i32 0, i32 2
%24 = alloca %string
%25 = getelementptr %string, %string* %23, i32 0, i32 0
%loaded_str_len1 = load i32, i32* %25
%26 = getelementptr %string, %string* %23, i32 0, i32 1
%loaded_str_data2 = load i8*, i8** %26
%27 = getelementptr %string, %string* %24, i32 0, i32 0
store i32 %loaded_str_len1, i32* %27
%28 = getelementptr %string, %string* %24, i32 0, i32 1
store i8* %loaded_str_data2, i8** %28
%29 = getelementptr %string, %string* %24, i32 0, i32 0
%loaded_str_len3 = load i32, i32* %29
%30 = getelementptr %string, %string* %24, i32 0, i32 1
%loaded_str_data4 = load i8*, i8** %30
%31 = getelementptr %string, %string* %5, i32 0, i32 0
store i32 %loaded_str_len3, i32* %31
%32 = getelementptr %string, %string* %5, i32 0, i32 1
store i8* %loaded_str_data4, i8** %32
br label %label_3
label_5: ; preds = %label_0
%33 = getelementptr %foo, %foo* %3, i32 0, i32 1
%loaded_str_len5 = load i32, i32* getelementptr inbounds (%string, %string* @gstr_3735928559, i32 0, i32 0)
%loaded_str_data6 = load i8*, i8** getelementptr inbounds (%string, %string* @gstr_3735928559, i32 0, i32 1)
%34 = getelementptr %string, %string* %5, i32 0, i32 0
store i32 %loaded_str_len5, i32* %34
%35 = getelementptr %string, %string* %5, i32 0, i32 1
store i8* %loaded_str_data6, i8** %35
br label %label_3
label_3: ; preds = %label_5, %label_4
%36 = alloca %internal_struct_4260204557
%37 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %36, i32 0, i32 0
store i32 2, i32* %37
%38 = getelementptr %internal_struct_4260204557, %internal_struct_4260204557* %36, i32 0, i32 3
%39 = getelementptr %string, %string* %5, i32 0, i32 0
%loaded_str_len7 = load i32, i32* %39
%40 = getelementptr %string, %string* %5, i32 0, i32 1
%loaded_str_data8 = load i8*, i8** %40
%41 = getelementptr %string, %string* %38, i32 0, i32 0
store i32 %loaded_str_len7, i32* %41
%42 = getelementptr %string, %string* %38, i32 0, i32 1
store i8* %loaded_str_data8, i8** %42
call void @print(%internal_struct_4260204557* %36)
%43 = load i32, i32* %2
store i32 %43, i32* %0
br label %function_end
function_end: ; preds = %label_3
%44 = load i32, i32* %0
ret i32 %44
}
attributes #0 = { nounwind readnone }
attributes #1 = { argmemonly nounwind }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment