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.

91 lines
2.4 KiB

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 @move(i32 %arg.x, i32 %arg.y) {
entry:
%t0 = alloca i32
store i32 %arg.x, i32* %t0
%t1 = alloca i32
store i32 %arg.y, i32* %t1
%t2 = load i32, i32* %t0
call void @putint(i32 %t2)
call void @putch(i32 32)
%t5 = load i32, i32* %t1
call void @putint(i32 %t5)
call void @putch(i32 44)
call void @putch(i32 32)
ret void
}
define void @hanoi(i32 %arg.n, i32 %arg.one, i32 %arg.two, i32 %arg.three) {
entry:
%t9 = alloca i32
store i32 %arg.n, i32* %t9
%t10 = alloca i32
store i32 %arg.one, i32* %t10
%t11 = alloca i32
store i32 %arg.two, i32* %t11
%t12 = alloca i32
store i32 %arg.three, i32* %t12
%t13 = load i32, i32* %t9
%t14 = icmp eq i32 %t13, 1
%t15 = zext i1 %t14 to i32
%t16 = icmp ne i32 %t15, 0
br i1 %t16, label %if.then.1, label %if.else.2
if.then.1:
%t17 = load i32, i32* %t10
%t18 = load i32, i32* %t12
call void @move(i32 %t17, i32 %t18)
br label %if.end.3
if.else.2:
%t20 = load i32, i32* %t9
%t21 = sub i32 %t20, 1
%t22 = load i32, i32* %t10
%t23 = load i32, i32* %t12
%t24 = load i32, i32* %t11
call void @hanoi(i32 %t21, i32 %t22, i32 %t23, i32 %t24)
%t26 = load i32, i32* %t10
%t27 = load i32, i32* %t12
call void @move(i32 %t26, i32 %t27)
%t29 = load i32, i32* %t9
%t30 = sub i32 %t29, 1
%t31 = load i32, i32* %t11
%t32 = load i32, i32* %t10
%t33 = load i32, i32* %t12
call void @hanoi(i32 %t30, i32 %t31, i32 %t32, i32 %t33)
br label %if.end.3
if.end.3:
ret void
}
define i32 @main() {
entry:
%t35 = alloca i32
%t36 = call i32 @getint()
store i32 %t36, i32* %t35
br label %while.cond.4
while.cond.4:
%t37 = load i32, i32* %t35
%t38 = icmp sgt i32 %t37, 0
%t39 = zext i1 %t38 to i32
%t40 = icmp ne i32 %t39, 0
br i1 %t40, label %while.body.5, label %while.end.6
while.body.5:
%t41 = call i32 @getint()
call void @hanoi(i32 %t41, i32 1, i32 2, i32 3)
call void @putch(i32 10)
%t44 = load i32, i32* %t35
%t45 = sub i32 %t44, 1
store i32 %t45, i32* %t35
br label %while.cond.4
while.end.6:
ret i32 0
}