forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
6.2 KiB
238 lines
6.2 KiB
@n = global i32 0
|
|
@m = global i32 0
|
|
@fa = global [100005 x i32] zeroinitializer
|
|
|
|
declare i32 @getint()
|
|
declare float @getfloat()
|
|
declare i32 @getarray(i32* %arg.a)
|
|
declare i32 @getfarray(float* %arg.a)
|
|
declare i32 @getch()
|
|
declare void @putint(i32 %arg.x)
|
|
declare void @putfloat(float %arg.x)
|
|
declare void @putarray(i32 %arg.n, i32* %arg.a)
|
|
declare void @putfarray(i32 %arg.n, float* %arg.a)
|
|
declare void @putch(i32 %arg.x)
|
|
declare void @starttime()
|
|
declare void @stoptime()
|
|
define i32 @quick_read() {
|
|
entry:
|
|
%t0 = alloca i32
|
|
%t2 = alloca i32
|
|
%t3 = alloca i32
|
|
%t1 = call i32 @getch()
|
|
store i32 %t1, i32* %t0
|
|
store i32 0, i32* %t2
|
|
store i32 0, i32* %t3
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t4 = load i32, i32* %t0
|
|
%t5 = icmp slt i32 %t4, 48
|
|
%t6 = zext i1 %t5 to i32
|
|
%t7 = icmp ne i32 %t6, 0
|
|
br i1 %t7, label %while.body.2, label %lor.rhs.4
|
|
while.body.2:
|
|
%t12 = load i32, i32* %t0
|
|
%t13 = icmp eq i32 %t12, 45
|
|
%t14 = zext i1 %t13 to i32
|
|
%t15 = icmp ne i32 %t14, 0
|
|
br i1 %t15, label %if.then.5, label %if.end.6
|
|
while.end.3:
|
|
br label %while.cond.7
|
|
lor.rhs.4:
|
|
%t8 = load i32, i32* %t0
|
|
%t9 = icmp sgt i32 %t8, 57
|
|
%t10 = zext i1 %t9 to i32
|
|
%t11 = icmp ne i32 %t10, 0
|
|
br i1 %t11, label %while.body.2, label %while.end.3
|
|
if.then.5:
|
|
store i32 1, i32* %t3
|
|
br label %if.end.6
|
|
if.end.6:
|
|
%t16 = call i32 @getch()
|
|
store i32 %t16, i32* %t0
|
|
br label %while.cond.1
|
|
while.cond.7:
|
|
%t17 = load i32, i32* %t0
|
|
%t18 = icmp sge i32 %t17, 48
|
|
%t19 = zext i1 %t18 to i32
|
|
%t20 = icmp ne i32 %t19, 0
|
|
br i1 %t20, label %land.rhs.10, label %while.end.9
|
|
while.body.8:
|
|
%t25 = load i32, i32* %t2
|
|
%t26 = mul i32 %t25, 10
|
|
%t27 = load i32, i32* %t0
|
|
%t28 = add i32 %t26, %t27
|
|
%t29 = sub i32 %t28, 48
|
|
store i32 %t29, i32* %t2
|
|
%t30 = call i32 @getch()
|
|
store i32 %t30, i32* %t0
|
|
br label %while.cond.7
|
|
while.end.9:
|
|
%t31 = load i32, i32* %t3
|
|
%t32 = icmp ne i32 %t31, 0
|
|
br i1 %t32, label %if.then.11, label %if.else.12
|
|
land.rhs.10:
|
|
%t21 = load i32, i32* %t0
|
|
%t22 = icmp sle i32 %t21, 57
|
|
%t23 = zext i1 %t22 to i32
|
|
%t24 = icmp ne i32 %t23, 0
|
|
br i1 %t24, label %while.body.8, label %while.end.9
|
|
if.then.11:
|
|
%t33 = load i32, i32* %t2
|
|
%t34 = sub i32 0, %t33
|
|
ret i32 %t34
|
|
if.else.12:
|
|
%t35 = load i32, i32* %t2
|
|
ret i32 %t35
|
|
if.end.13:
|
|
ret i32 0
|
|
}
|
|
define void @init() {
|
|
entry:
|
|
%t36 = alloca i32
|
|
store i32 1, i32* %t36
|
|
br label %while.cond.14
|
|
while.cond.14:
|
|
%t37 = load i32, i32* %t36
|
|
%t38 = load i32, i32* @n
|
|
%t39 = icmp sle i32 %t37, %t38
|
|
%t40 = zext i1 %t39 to i32
|
|
%t41 = icmp ne i32 %t40, 0
|
|
br i1 %t41, label %while.body.15, label %while.end.16
|
|
while.body.15:
|
|
%t42 = load i32, i32* %t36
|
|
%t43 = getelementptr inbounds [100005 x i32], [100005 x i32]* @fa, i32 0, i32 %t42
|
|
%t44 = load i32, i32* %t36
|
|
store i32 %t44, i32* %t43
|
|
%t45 = load i32, i32* %t36
|
|
%t46 = add i32 %t45, 1
|
|
store i32 %t46, i32* %t36
|
|
br label %while.cond.14
|
|
while.end.16:
|
|
ret void
|
|
}
|
|
define i32 @find(i32 %arg.x) {
|
|
entry:
|
|
%t56 = alloca i32
|
|
%t47 = alloca i32
|
|
store i32 %arg.x, i32* %t47
|
|
%t48 = load i32, i32* %t47
|
|
%t49 = getelementptr inbounds [100005 x i32], [100005 x i32]* @fa, i32 0, i32 %t48
|
|
%t50 = load i32, i32* %t49
|
|
%t51 = load i32, i32* %t47
|
|
%t52 = icmp eq i32 %t50, %t51
|
|
%t53 = zext i1 %t52 to i32
|
|
%t54 = icmp ne i32 %t53, 0
|
|
br i1 %t54, label %if.then.17, label %if.else.18
|
|
if.then.17:
|
|
%t55 = load i32, i32* %t47
|
|
ret i32 %t55
|
|
if.else.18:
|
|
%t57 = load i32, i32* %t47
|
|
%t58 = getelementptr inbounds [100005 x i32], [100005 x i32]* @fa, i32 0, i32 %t57
|
|
%t59 = load i32, i32* %t58
|
|
%t60 = call i32 @find(i32 %t59)
|
|
store i32 %t60, i32* %t56
|
|
%t61 = load i32, i32* %t47
|
|
%t62 = getelementptr inbounds [100005 x i32], [100005 x i32]* @fa, i32 0, i32 %t61
|
|
%t63 = load i32, i32* %t56
|
|
store i32 %t63, i32* %t62
|
|
%t64 = load i32, i32* %t56
|
|
ret i32 %t64
|
|
if.end.19:
|
|
ret i32 0
|
|
}
|
|
define i32 @same(i32 %arg.x, i32 %arg.y) {
|
|
entry:
|
|
%t65 = alloca i32
|
|
store i32 %arg.x, i32* %t65
|
|
%t66 = alloca i32
|
|
store i32 %arg.y, i32* %t66
|
|
%t67 = load i32, i32* %t65
|
|
%t68 = call i32 @find(i32 %t67)
|
|
%t69 = load i32, i32* %t66
|
|
%t70 = call i32 @find(i32 %t69)
|
|
%t71 = icmp eq i32 %t68, %t70
|
|
%t72 = zext i1 %t71 to i32
|
|
%t73 = icmp ne i32 %t72, 0
|
|
br i1 %t73, label %if.then.20, label %if.end.21
|
|
if.then.20:
|
|
ret i32 1
|
|
if.end.21:
|
|
ret i32 0
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t79 = alloca i32
|
|
%t94 = alloca i32
|
|
%t96 = alloca i32
|
|
%t103 = alloca i32
|
|
%t106 = alloca i32
|
|
%t74 = call i32 @quick_read()
|
|
store i32 %t74, i32* @n
|
|
%t75 = call i32 @quick_read()
|
|
store i32 %t75, i32* @m
|
|
call void @init()
|
|
br label %while.cond.22
|
|
while.cond.22:
|
|
%t77 = load i32, i32* @m
|
|
%t78 = icmp ne i32 %t77, 0
|
|
br i1 %t78, label %while.body.23, label %while.end.24
|
|
while.body.23:
|
|
%t80 = call i32 @getch()
|
|
store i32 %t80, i32* %t79
|
|
br label %while.cond.25
|
|
while.end.24:
|
|
ret i32 0
|
|
while.cond.25:
|
|
%t81 = load i32, i32* %t79
|
|
%t82 = icmp ne i32 %t81, 81
|
|
%t83 = zext i1 %t82 to i32
|
|
%t84 = icmp ne i32 %t83, 0
|
|
br i1 %t84, label %land.rhs.28, label %while.end.27
|
|
while.body.26:
|
|
%t89 = call i32 @getch()
|
|
store i32 %t89, i32* %t79
|
|
br label %while.cond.25
|
|
while.end.27:
|
|
%t90 = load i32, i32* %t79
|
|
%t91 = icmp eq i32 %t90, 81
|
|
%t92 = zext i1 %t91 to i32
|
|
%t93 = icmp ne i32 %t92, 0
|
|
br i1 %t93, label %if.then.29, label %if.else.30
|
|
land.rhs.28:
|
|
%t85 = load i32, i32* %t79
|
|
%t86 = icmp ne i32 %t85, 85
|
|
%t87 = zext i1 %t86 to i32
|
|
%t88 = icmp ne i32 %t87, 0
|
|
br i1 %t88, label %while.body.26, label %while.end.27
|
|
if.then.29:
|
|
%t95 = call i32 @quick_read()
|
|
store i32 %t95, i32* %t94
|
|
%t97 = call i32 @quick_read()
|
|
store i32 %t97, i32* %t96
|
|
%t98 = load i32, i32* %t94
|
|
%t99 = load i32, i32* %t96
|
|
%t100 = call i32 @same(i32 %t98, i32 %t99)
|
|
call void @putint(i32 %t100)
|
|
call void @putch(i32 10)
|
|
br label %if.end.31
|
|
if.else.30:
|
|
%t104 = call i32 @quick_read()
|
|
%t105 = call i32 @find(i32 %t104)
|
|
store i32 %t105, i32* %t103
|
|
%t107 = call i32 @quick_read()
|
|
%t108 = call i32 @find(i32 %t107)
|
|
store i32 %t108, i32* %t106
|
|
%t109 = load i32, i32* %t103
|
|
%t110 = getelementptr inbounds [100005 x i32], [100005 x i32]* @fa, i32 0, i32 %t109
|
|
%t111 = load i32, i32* %t106
|
|
store i32 %t111, i32* %t110
|
|
br label %if.end.31
|
|
if.end.31:
|
|
%t112 = load i32, i32* @m
|
|
%t113 = sub i32 %t112, 1
|
|
store i32 %t113, i32* @m
|
|
br label %while.cond.22
|
|
}
|