@space = global i32 32 @LF = global i32 10 @maxNode = global i32 10000 @value = global [10000 x i32] zeroinitializer @left_child = global [10000 x i32] zeroinitializer @right_child = global [10000 x i32] zeroinitializer @now = 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 @search(i32 %arg.root, i32 %arg.x) { entry: %t0 = alloca i32 store i32 %arg.root, i32* %t0 %t1 = alloca i32 store i32 %arg.x, i32* %t1 %t2 = load i32, i32* %t0 %t3 = icmp eq i32 %t2, -1 %t4 = zext i1 %t3 to i32 %t5 = icmp ne i32 %t4, 0 br i1 %t5, label %if.then.1, label %lor.rhs.4 if.then.1: %t13 = load i32, i32* %t0 ret i32 %t13 if.else.2: %t14 = load i32, i32* %t1 %t15 = load i32, i32* %t0 %t16 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t15 %t17 = load i32, i32* %t16 %t18 = icmp sgt i32 %t14, %t17 %t19 = zext i1 %t18 to i32 %t20 = icmp ne i32 %t19, 0 br i1 %t20, label %if.then.5, label %if.else.6 if.end.3: ret i32 0 lor.rhs.4: %t6 = load i32, i32* %t0 %t7 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t6 %t8 = load i32, i32* %t7 %t9 = load i32, i32* %t1 %t10 = icmp eq i32 %t8, %t9 %t11 = zext i1 %t10 to i32 %t12 = icmp ne i32 %t11, 0 br i1 %t12, label %if.then.1, label %if.else.2 if.then.5: %t21 = load i32, i32* %t0 %t22 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t21 %t23 = load i32, i32* %t22 %t24 = load i32, i32* %t1 %t25 = call i32 @search(i32 %t23, i32 %t24) ret i32 %t25 if.else.6: %t26 = load i32, i32* %t0 %t27 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t26 %t28 = load i32, i32* %t27 %t29 = load i32, i32* %t1 %t30 = call i32 @search(i32 %t28, i32 %t29) ret i32 %t30 if.end.7: ret i32 0 } define i32 @find_minimum(i32 %arg.root) { entry: %t31 = alloca i32 store i32 %arg.root, i32* %t31 %t32 = load i32, i32* %t31 %t33 = icmp eq i32 %t32, -1 %t34 = zext i1 %t33 to i32 %t35 = icmp ne i32 %t34, 0 br i1 %t35, label %if.then.8, label %if.else.9 if.then.8: ret i32 -1 if.else.9: %t36 = load i32, i32* %t31 %t37 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t36 %t38 = load i32, i32* %t37 %t39 = icmp ne i32 %t38, -1 %t40 = zext i1 %t39 to i32 %t41 = icmp ne i32 %t40, 0 br i1 %t41, label %if.then.11, label %if.end.12 if.end.10: %t46 = load i32, i32* %t31 ret i32 %t46 if.then.11: %t42 = load i32, i32* %t31 %t43 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t42 %t44 = load i32, i32* %t43 %t45 = call i32 @find_minimum(i32 %t44) ret i32 %t45 if.end.12: br label %if.end.10 } define i32 @new_node(i32 %arg.x) { entry: %t47 = alloca i32 store i32 %arg.x, i32* %t47 %t48 = load i32, i32* @now %t49 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t48 %t50 = load i32, i32* %t47 store i32 %t50, i32* %t49 %t51 = load i32, i32* @now %t52 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t51 store i32 -1, i32* %t52 %t53 = load i32, i32* @now %t54 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t53 store i32 -1, i32* %t54 %t55 = load i32, i32* @now %t56 = add i32 %t55, 1 store i32 %t56, i32* @now %t57 = load i32, i32* @now %t58 = sub i32 %t57, 1 ret i32 %t58 } define i32 @insert(i32 %arg.root, i32 %arg.x) { entry: %t59 = alloca i32 store i32 %arg.root, i32* %t59 %t60 = alloca i32 store i32 %arg.x, i32* %t60 %t61 = load i32, i32* %t59 %t62 = icmp eq i32 %t61, -1 %t63 = zext i1 %t62 to i32 %t64 = icmp ne i32 %t63, 0 br i1 %t64, label %if.then.13, label %if.else.14 if.then.13: %t65 = load i32, i32* %t60 %t66 = call i32 @new_node(i32 %t65) ret i32 %t66 if.else.14: %t67 = load i32, i32* %t60 %t68 = load i32, i32* %t59 %t69 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t68 %t70 = load i32, i32* %t69 %t71 = icmp sgt i32 %t67, %t70 %t72 = zext i1 %t71 to i32 %t73 = icmp ne i32 %t72, 0 br i1 %t73, label %if.then.16, label %if.else.17 if.end.15: %t88 = load i32, i32* %t59 ret i32 %t88 if.then.16: %t74 = load i32, i32* %t59 %t75 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t74 %t76 = load i32, i32* %t59 %t77 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t76 %t78 = load i32, i32* %t77 %t79 = load i32, i32* %t60 %t80 = call i32 @insert(i32 %t78, i32 %t79) store i32 %t80, i32* %t75 br label %if.end.18 if.else.17: %t81 = load i32, i32* %t59 %t82 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t81 %t83 = load i32, i32* %t59 %t84 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t83 %t85 = load i32, i32* %t84 %t86 = load i32, i32* %t60 %t87 = call i32 @insert(i32 %t85, i32 %t86) store i32 %t87, i32* %t82 br label %if.end.18 if.end.18: br label %if.end.15 } define i32 @delete(i32 %arg.root, i32 %arg.x) { entry: %t159 = alloca i32 %t89 = alloca i32 store i32 %arg.root, i32* %t89 %t90 = alloca i32 store i32 %arg.x, i32* %t90 %t91 = load i32, i32* %t89 %t92 = icmp eq i32 %t91, -1 %t93 = zext i1 %t92 to i32 %t94 = icmp ne i32 %t93, 0 br i1 %t94, label %if.then.19, label %if.end.20 if.then.19: ret i32 -1 if.end.20: %t95 = load i32, i32* %t90 %t96 = load i32, i32* %t89 %t97 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t96 %t98 = load i32, i32* %t97 %t99 = icmp sgt i32 %t95, %t98 %t100 = zext i1 %t99 to i32 %t101 = icmp ne i32 %t100, 0 br i1 %t101, label %if.then.21, label %if.else.22 if.then.21: %t102 = load i32, i32* %t89 %t103 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t102 %t104 = load i32, i32* %t89 %t105 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t104 %t106 = load i32, i32* %t105 %t107 = load i32, i32* %t90 %t108 = call i32 @delete(i32 %t106, i32 %t107) store i32 %t108, i32* %t103 br label %if.end.23 if.else.22: %t109 = load i32, i32* %t90 %t110 = load i32, i32* %t89 %t111 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t110 %t112 = load i32, i32* %t111 %t113 = icmp slt i32 %t109, %t112 %t114 = zext i1 %t113 to i32 %t115 = icmp ne i32 %t114, 0 br i1 %t115, label %if.then.24, label %if.else.25 if.end.23: %t178 = load i32, i32* %t89 ret i32 %t178 if.then.24: %t116 = load i32, i32* %t89 %t117 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t116 %t118 = load i32, i32* %t89 %t119 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t118 %t120 = load i32, i32* %t119 %t121 = load i32, i32* %t90 %t122 = call i32 @delete(i32 %t120, i32 %t121) store i32 %t122, i32* %t117 br label %if.end.26 if.else.25: %t123 = load i32, i32* %t89 %t124 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t123 %t125 = load i32, i32* %t124 %t126 = icmp eq i32 %t125, -1 %t127 = zext i1 %t126 to i32 %t128 = icmp ne i32 %t127, 0 br i1 %t128, label %land.rhs.30, label %if.else.28 if.end.26: br label %if.end.23 if.then.27: ret i32 -1 if.else.28: %t135 = load i32, i32* %t89 %t136 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t135 %t137 = load i32, i32* %t136 %t138 = icmp eq i32 %t137, -1 %t139 = zext i1 %t138 to i32 %t140 = icmp ne i32 %t139, 0 br i1 %t140, label %if.then.31, label %lor.rhs.34 if.end.29: br label %if.end.26 land.rhs.30: %t129 = load i32, i32* %t89 %t130 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t129 %t131 = load i32, i32* %t130 %t132 = icmp eq i32 %t131, -1 %t133 = zext i1 %t132 to i32 %t134 = icmp ne i32 %t133, 0 br i1 %t134, label %if.then.27, label %if.else.28 if.then.31: %t147 = load i32, i32* %t89 %t148 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t147 %t149 = load i32, i32* %t148 %t150 = icmp eq i32 %t149, -1 %t151 = zext i1 %t150 to i32 %t152 = icmp ne i32 %t151, 0 br i1 %t152, label %if.then.35, label %if.else.36 if.else.32: %t160 = load i32, i32* %t89 %t161 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t160 %t162 = load i32, i32* %t161 %t163 = call i32 @find_minimum(i32 %t162) store i32 %t163, i32* %t159 %t164 = load i32, i32* %t89 %t165 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t164 %t166 = load i32, i32* %t159 %t167 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t166 %t168 = load i32, i32* %t167 store i32 %t168, i32* %t165 %t169 = load i32, i32* %t89 %t170 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t169 %t171 = load i32, i32* %t89 %t172 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t171 %t173 = load i32, i32* %t172 %t174 = load i32, i32* %t159 %t175 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t174 %t176 = load i32, i32* %t175 %t177 = call i32 @delete(i32 %t173, i32 %t176) store i32 %t177, i32* %t170 br label %if.end.33 if.end.33: br label %if.end.29 lor.rhs.34: %t141 = load i32, i32* %t89 %t142 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t141 %t143 = load i32, i32* %t142 %t144 = icmp eq i32 %t143, -1 %t145 = zext i1 %t144 to i32 %t146 = icmp ne i32 %t145, 0 br i1 %t146, label %if.then.31, label %if.else.32 if.then.35: %t153 = load i32, i32* %t89 %t154 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t153 %t155 = load i32, i32* %t154 ret i32 %t155 if.else.36: %t156 = load i32, i32* %t89 %t157 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t156 %t158 = load i32, i32* %t157 ret i32 %t158 if.end.37: ret i32 0 } define void @inorder(i32 %arg.root) { entry: %t179 = alloca i32 store i32 %arg.root, i32* %t179 %t180 = load i32, i32* %t179 %t181 = icmp ne i32 %t180, -1 %t182 = zext i1 %t181 to i32 %t183 = icmp ne i32 %t182, 0 br i1 %t183, label %if.then.38, label %if.end.39 if.then.38: %t184 = load i32, i32* %t179 %t185 = getelementptr inbounds [10000 x i32], [10000 x i32]* @left_child, i32 0, i32 %t184 %t186 = load i32, i32* %t185 call void @inorder(i32 %t186) %t188 = load i32, i32* %t179 %t189 = getelementptr inbounds [10000 x i32], [10000 x i32]* @value, i32 0, i32 %t188 %t190 = load i32, i32* %t189 call void @putint(i32 %t190) call void @putch(i32 32) %t193 = load i32, i32* %t179 %t194 = getelementptr inbounds [10000 x i32], [10000 x i32]* @right_child, i32 0, i32 %t193 %t195 = load i32, i32* %t194 call void @inorder(i32 %t195) br label %if.end.39 if.end.39: ret void } define i32 @main() { entry: %t197 = alloca i32 %t203 = alloca i32 %t206 = alloca i32 store i32 0, i32* @now %t198 = call i32 @getint() store i32 %t198, i32* %t197 %t199 = load i32, i32* %t197 %t200 = icmp eq i32 %t199, 0 %t201 = zext i1 %t200 to i32 %t202 = icmp ne i32 %t201, 0 br i1 %t202, label %if.then.40, label %if.end.41 if.then.40: ret i32 0 if.end.41: %t204 = call i32 @getint() %t205 = call i32 @new_node(i32 %t204) store i32 %t205, i32* %t203 store i32 1, i32* %t206 br label %while.cond.42 while.cond.42: %t207 = load i32, i32* %t206 %t208 = load i32, i32* %t197 %t209 = icmp slt i32 %t207, %t208 %t210 = zext i1 %t209 to i32 %t211 = icmp ne i32 %t210, 0 br i1 %t211, label %while.body.43, label %while.end.44 while.body.43: %t212 = load i32, i32* %t203 %t213 = call i32 @getint() %t214 = call i32 @insert(i32 %t212, i32 %t213) %t215 = load i32, i32* %t206 %t216 = add i32 %t215, 1 store i32 %t216, i32* %t206 br label %while.cond.42 while.end.44: %t217 = load i32, i32* %t203 call void @inorder(i32 %t217) call void @putch(i32 10) %t220 = call i32 @getint() store i32 %t220, i32* %t197 store i32 0, i32* %t206 br label %while.cond.45 while.cond.45: %t221 = load i32, i32* %t206 %t222 = load i32, i32* %t197 %t223 = icmp slt i32 %t221, %t222 %t224 = zext i1 %t223 to i32 %t225 = icmp ne i32 %t224, 0 br i1 %t225, label %while.body.46, label %while.end.47 while.body.46: %t226 = load i32, i32* %t203 %t227 = call i32 @getint() %t228 = call i32 @delete(i32 %t226, i32 %t227) store i32 %t228, i32* %t203 %t229 = load i32, i32* %t206 %t230 = add i32 %t229, 1 store i32 %t230, i32* %t206 br label %while.cond.45 while.end.47: %t231 = load i32, i32* %t203 call void @inorder(i32 %t231) call void @putch(i32 10) ret i32 0 }