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.
426 lines
13 KiB
426 lines
13 KiB
@maxn = global i32 10005
|
|
@n = global i32 0
|
|
@m = global i32 0
|
|
@f = global [200100 x i32] zeroinitializer
|
|
@dep = global [10005 x i32] zeroinitializer
|
|
@to = global [10005 x i32] zeroinitializer
|
|
@next = global [10005 x i32] zeroinitializer
|
|
@head = global [10005 x i32] zeroinitializer
|
|
@cnt = global i32 0
|
|
|
|
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 @add_edge(i32 %arg.from, i32 %arg.To) {
|
|
entry:
|
|
%t36 = alloca i32
|
|
store i32 %arg.from, i32* %t36
|
|
%t37 = alloca i32
|
|
store i32 %arg.To, i32* %t37
|
|
%t38 = load i32, i32* @cnt
|
|
%t39 = getelementptr inbounds [10005 x i32], [10005 x i32]* @to, i32 0, i32 %t38
|
|
%t40 = load i32, i32* %t37
|
|
store i32 %t40, i32* %t39
|
|
%t41 = load i32, i32* @cnt
|
|
%t42 = getelementptr inbounds [10005 x i32], [10005 x i32]* @next, i32 0, i32 %t41
|
|
%t43 = load i32, i32* %t36
|
|
%t44 = getelementptr inbounds [10005 x i32], [10005 x i32]* @head, i32 0, i32 %t43
|
|
%t45 = load i32, i32* %t44
|
|
store i32 %t45, i32* %t42
|
|
%t46 = load i32, i32* %t36
|
|
%t47 = getelementptr inbounds [10005 x i32], [10005 x i32]* @head, i32 0, i32 %t46
|
|
%t48 = load i32, i32* @cnt
|
|
store i32 %t48, i32* %t47
|
|
%t49 = load i32, i32* @cnt
|
|
%t50 = add i32 %t49, 1
|
|
store i32 %t50, i32* @cnt
|
|
%t51 = load i32, i32* %t37
|
|
%t52 = mul i32 %t51, 20
|
|
%t53 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t52
|
|
%t54 = load i32, i32* %t36
|
|
store i32 %t54, i32* %t53
|
|
ret void
|
|
}
|
|
define void @init() {
|
|
entry:
|
|
%t56 = alloca i32
|
|
%t55 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 0
|
|
store i32 1061109567, i32* %t55
|
|
store i32 1, i32* %t56
|
|
br label %while.cond.14
|
|
while.cond.14:
|
|
%t57 = load i32, i32* %t56
|
|
%t58 = load i32, i32* @n
|
|
%t59 = icmp sle i32 %t57, %t58
|
|
%t60 = zext i1 %t59 to i32
|
|
%t61 = icmp ne i32 %t60, 0
|
|
br i1 %t61, label %while.body.15, label %while.end.16
|
|
while.body.15:
|
|
%t62 = load i32, i32* %t56
|
|
%t63 = getelementptr inbounds [10005 x i32], [10005 x i32]* @head, i32 0, i32 %t62
|
|
store i32 -1, i32* %t63
|
|
%t64 = load i32, i32* %t56
|
|
%t65 = add i32 %t64, 1
|
|
store i32 %t65, i32* %t56
|
|
br label %while.cond.14
|
|
while.end.16:
|
|
ret void
|
|
}
|
|
define void @tree(i32 %arg.x, i32 %arg.d) {
|
|
entry:
|
|
%t71 = alloca i32
|
|
%t105 = alloca i32
|
|
%t66 = alloca i32
|
|
store i32 %arg.x, i32* %t66
|
|
%t67 = alloca i32
|
|
store i32 %arg.d, i32* %t67
|
|
%t68 = load i32, i32* %t66
|
|
%t69 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t68
|
|
%t70 = load i32, i32* %t67
|
|
store i32 %t70, i32* %t69
|
|
store i32 0, i32* %t71
|
|
br label %while.cond.17
|
|
while.cond.17:
|
|
%t72 = load i32, i32* %t66
|
|
%t73 = load i32, i32* %t71
|
|
%t74 = mul i32 %t72, 20
|
|
%t75 = add i32 %t74, %t73
|
|
%t76 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t75
|
|
%t77 = load i32, i32* %t76
|
|
%t78 = icmp ne i32 %t77, 0
|
|
br i1 %t78, label %while.body.18, label %while.end.19
|
|
while.body.18:
|
|
%t79 = load i32, i32* %t66
|
|
%t80 = load i32, i32* %t71
|
|
%t81 = add i32 %t80, 1
|
|
%t82 = mul i32 %t79, 20
|
|
%t83 = add i32 %t82, %t81
|
|
%t84 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t83
|
|
%t85 = load i32, i32* %t66
|
|
%t86 = load i32, i32* %t71
|
|
%t87 = mul i32 %t85, 20
|
|
%t88 = add i32 %t87, %t86
|
|
%t89 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t88
|
|
%t90 = load i32, i32* %t89
|
|
%t91 = load i32, i32* %t71
|
|
%t92 = mul i32 %t90, 20
|
|
%t93 = add i32 %t92, %t91
|
|
%t94 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t93
|
|
%t95 = load i32, i32* %t94
|
|
store i32 %t95, i32* %t84
|
|
%t96 = load i32, i32* %t71
|
|
%t97 = add i32 %t96, 1
|
|
store i32 %t97, i32* %t71
|
|
br label %while.cond.17
|
|
while.end.19:
|
|
%t98 = load i32, i32* %t66
|
|
%t99 = getelementptr inbounds [10005 x i32], [10005 x i32]* @head, i32 0, i32 %t98
|
|
%t100 = load i32, i32* %t99
|
|
store i32 %t100, i32* %t71
|
|
br label %while.cond.20
|
|
while.cond.20:
|
|
%t101 = load i32, i32* %t71
|
|
%t102 = icmp ne i32 %t101, -1
|
|
%t103 = zext i1 %t102 to i32
|
|
%t104 = icmp ne i32 %t103, 0
|
|
br i1 %t104, label %while.body.21, label %while.end.22
|
|
while.body.21:
|
|
%t106 = load i32, i32* %t71
|
|
%t107 = getelementptr inbounds [10005 x i32], [10005 x i32]* @to, i32 0, i32 %t106
|
|
%t108 = load i32, i32* %t107
|
|
store i32 %t108, i32* %t105
|
|
%t109 = load i32, i32* %t105
|
|
%t110 = load i32, i32* %t67
|
|
%t111 = add i32 %t110, 1
|
|
call void @tree(i32 %t109, i32 %t111)
|
|
%t113 = load i32, i32* %t71
|
|
%t114 = getelementptr inbounds [10005 x i32], [10005 x i32]* @next, i32 0, i32 %t113
|
|
%t115 = load i32, i32* %t114
|
|
store i32 %t115, i32* %t71
|
|
br label %while.cond.20
|
|
while.end.22:
|
|
ret void
|
|
}
|
|
define i32 @LCA(i32 %arg.x, i32 %arg.y) {
|
|
entry:
|
|
%t127 = alloca i32
|
|
%t131 = alloca i32
|
|
%t116 = alloca i32
|
|
store i32 %arg.x, i32* %t116
|
|
%t117 = alloca i32
|
|
store i32 %arg.y, i32* %t117
|
|
%t118 = load i32, i32* %t116
|
|
%t119 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t118
|
|
%t120 = load i32, i32* %t119
|
|
%t121 = load i32, i32* %t117
|
|
%t122 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t121
|
|
%t123 = load i32, i32* %t122
|
|
%t124 = icmp slt i32 %t120, %t123
|
|
%t125 = zext i1 %t124 to i32
|
|
%t126 = icmp ne i32 %t125, 0
|
|
br i1 %t126, label %if.then.23, label %if.end.24
|
|
if.then.23:
|
|
%t128 = load i32, i32* %t116
|
|
store i32 %t128, i32* %t127
|
|
%t129 = load i32, i32* %t117
|
|
store i32 %t129, i32* %t116
|
|
%t130 = load i32, i32* %t127
|
|
store i32 %t130, i32* %t117
|
|
br label %if.end.24
|
|
if.end.24:
|
|
store i32 19, i32* %t131
|
|
br label %while.cond.25
|
|
while.cond.25:
|
|
%t132 = load i32, i32* %t116
|
|
%t133 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t132
|
|
%t134 = load i32, i32* %t133
|
|
%t135 = load i32, i32* %t117
|
|
%t136 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t135
|
|
%t137 = load i32, i32* %t136
|
|
%t138 = icmp sgt i32 %t134, %t137
|
|
%t139 = zext i1 %t138 to i32
|
|
%t140 = icmp ne i32 %t139, 0
|
|
br i1 %t140, label %while.body.26, label %while.end.27
|
|
while.body.26:
|
|
%t141 = load i32, i32* %t116
|
|
%t142 = load i32, i32* %t131
|
|
%t143 = mul i32 %t141, 20
|
|
%t144 = add i32 %t143, %t142
|
|
%t145 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t144
|
|
%t146 = load i32, i32* %t145
|
|
%t147 = icmp ne i32 %t146, 0
|
|
br i1 %t147, label %land.rhs.30, label %if.end.29
|
|
while.end.27:
|
|
%t170 = load i32, i32* %t116
|
|
%t171 = load i32, i32* %t117
|
|
%t172 = icmp eq i32 %t170, %t171
|
|
%t173 = zext i1 %t172 to i32
|
|
%t174 = icmp ne i32 %t173, 0
|
|
br i1 %t174, label %if.then.31, label %if.end.32
|
|
if.then.28:
|
|
%t162 = load i32, i32* %t116
|
|
%t163 = load i32, i32* %t131
|
|
%t164 = mul i32 %t162, 20
|
|
%t165 = add i32 %t164, %t163
|
|
%t166 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t165
|
|
%t167 = load i32, i32* %t166
|
|
store i32 %t167, i32* %t116
|
|
br label %if.end.29
|
|
if.end.29:
|
|
%t168 = load i32, i32* %t131
|
|
%t169 = sub i32 %t168, 1
|
|
store i32 %t169, i32* %t131
|
|
br label %while.cond.25
|
|
land.rhs.30:
|
|
%t148 = load i32, i32* %t116
|
|
%t149 = load i32, i32* %t131
|
|
%t150 = mul i32 %t148, 20
|
|
%t151 = add i32 %t150, %t149
|
|
%t152 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t151
|
|
%t153 = load i32, i32* %t152
|
|
%t154 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t153
|
|
%t155 = load i32, i32* %t154
|
|
%t156 = load i32, i32* %t117
|
|
%t157 = getelementptr inbounds [10005 x i32], [10005 x i32]* @dep, i32 0, i32 %t156
|
|
%t158 = load i32, i32* %t157
|
|
%t159 = icmp sge i32 %t155, %t158
|
|
%t160 = zext i1 %t159 to i32
|
|
%t161 = icmp ne i32 %t160, 0
|
|
br i1 %t161, label %if.then.28, label %if.end.29
|
|
if.then.31:
|
|
%t175 = load i32, i32* %t116
|
|
ret i32 %t175
|
|
if.end.32:
|
|
store i32 19, i32* %t131
|
|
br label %while.cond.33
|
|
while.cond.33:
|
|
%t176 = load i32, i32* %t131
|
|
%t177 = icmp sge i32 %t176, 0
|
|
%t178 = zext i1 %t177 to i32
|
|
%t179 = icmp ne i32 %t178, 0
|
|
br i1 %t179, label %while.body.34, label %while.end.35
|
|
while.body.34:
|
|
%t180 = load i32, i32* %t116
|
|
%t181 = load i32, i32* %t131
|
|
%t182 = mul i32 %t180, 20
|
|
%t183 = add i32 %t182, %t181
|
|
%t184 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t183
|
|
%t185 = load i32, i32* %t184
|
|
%t186 = load i32, i32* %t117
|
|
%t187 = load i32, i32* %t131
|
|
%t188 = mul i32 %t186, 20
|
|
%t189 = add i32 %t188, %t187
|
|
%t190 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t189
|
|
%t191 = load i32, i32* %t190
|
|
%t192 = icmp ne i32 %t185, %t191
|
|
%t193 = zext i1 %t192 to i32
|
|
%t194 = icmp ne i32 %t193, 0
|
|
br i1 %t194, label %if.then.36, label %if.end.37
|
|
while.end.35:
|
|
%t209 = load i32, i32* %t116
|
|
%t210 = mul i32 %t209, 20
|
|
%t211 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t210
|
|
%t212 = load i32, i32* %t211
|
|
ret i32 %t212
|
|
if.then.36:
|
|
%t195 = load i32, i32* %t116
|
|
%t196 = load i32, i32* %t131
|
|
%t197 = mul i32 %t195, 20
|
|
%t198 = add i32 %t197, %t196
|
|
%t199 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t198
|
|
%t200 = load i32, i32* %t199
|
|
store i32 %t200, i32* %t116
|
|
%t201 = load i32, i32* %t117
|
|
%t202 = load i32, i32* %t131
|
|
%t203 = mul i32 %t201, 20
|
|
%t204 = add i32 %t203, %t202
|
|
%t205 = getelementptr inbounds [200100 x i32], [200100 x i32]* @f, i32 0, i32 %t204
|
|
%t206 = load i32, i32* %t205
|
|
store i32 %t206, i32* %t117
|
|
br label %if.end.37
|
|
if.end.37:
|
|
%t207 = load i32, i32* %t131
|
|
%t208 = sub i32 %t207, 1
|
|
store i32 %t208, i32* %t131
|
|
br label %while.cond.33
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t216 = alloca i32
|
|
%t222 = alloca i32
|
|
%t224 = alloca i32
|
|
%t234 = alloca i32
|
|
%t236 = alloca i32
|
|
%t213 = call i32 @quick_read()
|
|
store i32 %t213, i32* @n
|
|
%t214 = call i32 @quick_read()
|
|
store i32 %t214, i32* @m
|
|
call void @init()
|
|
store i32 1, i32* %t216
|
|
br label %while.cond.38
|
|
while.cond.38:
|
|
%t217 = load i32, i32* %t216
|
|
%t218 = load i32, i32* @n
|
|
%t219 = icmp ne i32 %t217, %t218
|
|
%t220 = zext i1 %t219 to i32
|
|
%t221 = icmp ne i32 %t220, 0
|
|
br i1 %t221, label %while.body.39, label %while.end.40
|
|
while.body.39:
|
|
%t223 = call i32 @quick_read()
|
|
store i32 %t223, i32* %t222
|
|
%t225 = call i32 @quick_read()
|
|
store i32 %t225, i32* %t224
|
|
%t226 = load i32, i32* %t222
|
|
%t227 = load i32, i32* %t224
|
|
call void @add_edge(i32 %t226, i32 %t227)
|
|
%t229 = load i32, i32* %t216
|
|
%t230 = add i32 %t229, 1
|
|
store i32 %t230, i32* %t216
|
|
br label %while.cond.38
|
|
while.end.40:
|
|
call void @tree(i32 1, i32 1)
|
|
br label %while.cond.41
|
|
while.cond.41:
|
|
%t232 = load i32, i32* @m
|
|
%t233 = icmp ne i32 %t232, 0
|
|
br i1 %t233, label %while.body.42, label %while.end.43
|
|
while.body.42:
|
|
%t235 = call i32 @quick_read()
|
|
store i32 %t235, i32* %t234
|
|
%t237 = call i32 @quick_read()
|
|
store i32 %t237, i32* %t236
|
|
%t238 = load i32, i32* %t234
|
|
%t239 = load i32, i32* %t236
|
|
%t240 = call i32 @LCA(i32 %t238, i32 %t239)
|
|
call void @putint(i32 %t240)
|
|
call void @putch(i32 10)
|
|
%t243 = load i32, i32* @m
|
|
%t244 = sub i32 %t243, 1
|
|
store i32 %t244, i32* @m
|
|
br label %while.cond.41
|
|
while.end.43:
|
|
ret i32 0
|
|
}
|