forked from CMinusGroup/C_compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.cpp.ll
43 lines (37 loc) · 1.18 KB
/
demo.cpp.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
; ModuleID = 'demo.cpp'
source_filename = "demo.cpp"
@ans = internal global i32 0
@0 = private unnamed_addr constant [13 x i8] c"\22ans = %d\\n\22\00", align 1
define i32 @gcd(i32 %0, i32 %1) {
entry:
%a = alloca i32, align 4
store i32 %0, i32* %a, align 4
%b = alloca i32, align 4
store i32 %1, i32* %b, align 4
%2 = load i32, i32* %b, align 4
%ifequal = icmp eq i32 %2, 0
br i1 %ifequal, label %then, label %else
then: ; preds = %entry
%3 = load i32, i32* %a, align 4
ret i32 %3
else: ; preds = %entry
%4 = load i32, i32* %b, align 4
%5 = load i32, i32* %a, align 4
%6 = load i32, i32* %b, align 4
%7 = srem i32 %5, %6
%8 = call i32 @gcd(i32 %4, i32 %7)
ret i32 %8
}
define i32 @main() {
entry:
%0 = load i32, i32* @ans, align 4
%1 = call i32 @gcd(i32 9, i32 36)
%2 = call i32 @gcd(i32 3, i32 6)
%3 = mul i32 %1, %2
store i32 %3, i32* @ans, align 4
%4 = load i32, i32* @ans, align 4
%5 = load i32, i32* @ans, align 4
%call = call i32 (...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0), i32 %5)
ret i32 0
}
declare i32 @printf(...)