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.

205 lines
6.5 KiB

@i = global [1 x i32] zeroinitializer
@k = global [1 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 void @inc_impl(i32* %arg.x, i32 %arg.rec) {
entry:
%t0 = alloca i32
store i32 %arg.rec, i32* %t0
%t1 = load i32, i32* %t0
%t2 = icmp eq i32 %t1, 0
%t3 = zext i1 %t2 to i32
%t4 = icmp ne i32 %t3, 0
br i1 %t4, label %if.then.1, label %if.else.2
if.then.1:
%t5 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t6 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t7 = load i32, i32* %t6
%t8 = add i32 %t7, 1
store i32 %t8, i32* %t5
br label %if.end.3
if.else.2:
%t9 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t10 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t11 = load i32, i32* %t10
%t12 = mul i32 %t11, 2
store i32 %t12, i32* %t9
%t13 = load i32, i32* %t0
%t14 = sub i32 %t13, 1
call void @inc_impl(i32* %arg.x, i32 %t14)
br label %if.end.3
if.end.3:
ret void
}
define void @inc(i32* %arg.x) {
entry:
%t16 = getelementptr inbounds [1 x i32], [1 x i32]* @k, i32 0, i32 0
%t17 = load i32, i32* %t16
call void @inc_impl(i32* %arg.x, i32 %t17)
ret void
}
define void @add_impl(i32* %arg.x, i32* %arg.y, i32 %arg.rec) {
entry:
%t19 = alloca i32
store i32 %arg.rec, i32* %t19
%t20 = load i32, i32* %t19
%t21 = icmp eq i32 %t20, 0
%t22 = zext i1 %t21 to i32
%t23 = icmp ne i32 %t22, 0
br i1 %t23, label %if.then.4, label %if.else.5
if.then.4:
%t24 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t25 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t26 = load i32, i32* %t25
%t27 = getelementptr inbounds i32, i32* %arg.y, i32 0
%t28 = load i32, i32* %t27
%t29 = add i32 %t26, %t28
store i32 %t29, i32* %t24
br label %if.end.6
if.else.5:
%t30 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t31 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t32 = load i32, i32* %t31
%t33 = mul i32 %t32, 2
store i32 %t33, i32* %t30
%t34 = load i32, i32* %t19
%t35 = sub i32 %t34, 1
call void @add_impl(i32* %arg.x, i32* %arg.y, i32 %t35)
br label %if.end.6
if.end.6:
ret void
}
define void @add(i32* %arg.x, i32* %arg.y) {
entry:
%t37 = getelementptr inbounds [1 x i32], [1 x i32]* @k, i32 0, i32 0
%t38 = load i32, i32* %t37
call void @add_impl(i32* %arg.x, i32* %arg.y, i32 %t38)
ret void
}
define void @sub_impl(i32* %arg.x, i32* %arg.y, i32 %arg.rec) {
entry:
%t40 = alloca i32
store i32 %arg.rec, i32* %t40
%t41 = load i32, i32* %t40
%t42 = icmp eq i32 %t41, 0
%t43 = zext i1 %t42 to i32
%t44 = icmp ne i32 %t43, 0
br i1 %t44, label %if.then.7, label %if.else.8
if.then.7:
%t45 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t46 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t47 = load i32, i32* %t46
%t48 = getelementptr inbounds i32, i32* %arg.y, i32 0
%t49 = load i32, i32* %t48
%t50 = sub i32 %t47, %t49
store i32 %t50, i32* %t45
br label %if.end.9
if.else.8:
%t51 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t52 = getelementptr inbounds i32, i32* %arg.x, i32 0
%t53 = load i32, i32* %t52
%t54 = mul i32 %t53, 2
store i32 %t54, i32* %t51
%t55 = load i32, i32* %t40
%t56 = sub i32 %t55, 1
call void @sub_impl(i32* %arg.x, i32* %arg.y, i32 %t56)
br label %if.end.9
if.end.9:
ret void
}
define void @sub(i32* %arg.x, i32* %arg.y) {
entry:
%t58 = getelementptr inbounds [1 x i32], [1 x i32]* @k, i32 0, i32 0
%t59 = load i32, i32* %t58
call void @sub_impl(i32* %arg.x, i32* %arg.y, i32 %t59)
ret void
}
define i32 @main() {
entry:
%t61 = alloca i32, i32 1
%t62 = alloca i32, i32 1
%t63 = alloca i32, i32 2
%t64 = getelementptr inbounds i32, i32* %t63, i32 0
store i32 -1, i32* %t64
%t65 = getelementptr inbounds i32, i32* %t63, i32 1
store i32 0, i32* %t65
%t66 = getelementptr inbounds [1 x i32], [1 x i32]* @k, i32 0, i32 0
%t67 = call i32 @getint()
store i32 %t67, i32* %t66
%t68 = getelementptr inbounds i32, i32* %t62, i32 0
%t69 = call i32 @getint()
store i32 %t69, i32* %t68
%t70 = getelementptr inbounds i32, i32* %t63, i32 0
%t71 = call i32 @getarray(i32* %t70)
br label %while.cond.10
while.cond.10:
%t72 = getelementptr inbounds i32, i32* %t62, i32 0
%t73 = load i32, i32* %t72
%t74 = icmp ne i32 %t73, 0
br i1 %t74, label %while.body.11, label %while.end.12
while.body.11:
%t75 = getelementptr inbounds i32, i32* %t61, i32 0
%t76 = getelementptr inbounds i32, i32* %t63, i32 0
%t77 = load i32, i32* %t76
store i32 %t77, i32* %t75
br label %while.cond.13
while.end.12:
call void @putch(i32 10)
ret i32 0
while.cond.13:
%t78 = getelementptr inbounds i32, i32* %t61, i32 0
%t79 = load i32, i32* %t78
%t80 = icmp slt i32 %t79, 5
%t81 = zext i1 %t80 to i32
%t82 = icmp ne i32 %t81, 0
br i1 %t82, label %while.body.14, label %while.end.15
while.body.14:
%t83 = getelementptr inbounds [1 x i32], [1 x i32]* @i, i32 0, i32 0
%t84 = load i32, i32* %t83
call void @putint(i32 %t84)
%t86 = getelementptr inbounds i32, i32* %t61, i32 0
%t87 = load i32, i32* %t86
call void @putint(i32 %t87)
%t89 = getelementptr inbounds i32, i32* %t62, i32 0
%t90 = load i32, i32* %t89
call void @putint(i32 %t90)
%t92 = getelementptr inbounds i32, i32* %t63, i32 0
%t93 = load i32, i32* %t92
call void @putint(i32 %t93)
%t95 = getelementptr inbounds i32, i32* %t63, i32 0
call void @add(i32* %t95, i32* %t62)
call void @add(i32* %t61, i32* %t62)
%t98 = getelementptr inbounds i32, i32* %t63, i32 0
call void @sub(i32* %t98, i32* %t62)
br label %while.cond.13
while.end.15:
%t100 = getelementptr inbounds [1 x i32], [1 x i32]* @i, i32 0, i32 0
call void @inc(i32* %t100)
%t102 = getelementptr inbounds i32, i32* %t63, i32 0
%t103 = getelementptr inbounds [1 x i32], [1 x i32]* @i, i32 0, i32 0
call void @add(i32* %t103, i32* %t102)
%t105 = getelementptr inbounds [1 x i32], [1 x i32]* @i, i32 0, i32 0
%t106 = load i32, i32* %t105
%t107 = getelementptr inbounds i32, i32* %t63, i32 1
%t108 = load i32, i32* %t107
%t109 = icmp eq i32 %t106, %t108
%t110 = zext i1 %t109 to i32
%t111 = icmp ne i32 %t110, 0
br i1 %t111, label %if.then.16, label %if.end.17
if.then.16:
br label %while.end.12
if.end.17:
br label %while.cond.10
}