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.

100 lines
2.8 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 float @myabs(float %arg.num) {
entry:
%t0 = alloca float
store float %arg.num, float* %t0
%t1 = load float, float* %t0
%t2 = fcmp ogt float %t1, 0x0000000000000000
%t3 = zext i1 %t2 to i32
%t4 = icmp ne i32 %t3, 0
br i1 %t4, label %if.then.1, label %if.end.2
if.then.1:
%t5 = load float, float* %t0
ret float %t5
if.end.2:
%t6 = load float, float* %t0
%t7 = fcmp olt float %t6, 0x0000000000000000
%t8 = zext i1 %t7 to i32
%t9 = icmp ne i32 %t8, 0
br i1 %t9, label %if.then.3, label %if.end.4
if.then.3:
%t10 = load float, float* %t0
%t11 = fsub float 0x0000000000000000, %t10
ret float %t11
if.end.4:
ret float 0x0000000000000000
}
define float @func(float %arg.data, i32 %arg.num) {
entry:
%t12 = alloca float
store float %arg.data, float* %t12
%t13 = alloca i32
store i32 %arg.num, i32* %t13
%t14 = load i32, i32* %t13
%t15 = icmp slt i32 %t14, 0
%t16 = zext i1 %t15 to i32
%t17 = icmp ne i32 %t16, 0
br i1 %t17, label %if.then.5, label %if.end.6
if.then.5:
ret float 0x0000000000000000
if.end.6:
%t18 = load i32, i32* %t13
%t19 = sub i32 %t18, 1
store i32 %t19, i32* %t13
%t20 = load float, float* %t12
%t21 = load float, float* %t12
%t22 = load i32, i32* %t13
%t23 = call float @func(float %t21, i32 %t22)
%t24 = fadd float %t20, %t23
store float %t24, float* %t12
%t25 = load float, float* %t12
%t26 = load float, float* %t12
%t27 = load i32, i32* %t13
%t28 = call float @func(float %t26, i32 %t27)
%t29 = fsub float %t25, %t28
store float %t29, float* %t12
%t30 = load float, float* %t12
ret float %t30
}
define i32 @main() {
entry:
%t32 = alloca float
%t33 = alloca i32
%t35 = alloca float
%t36 = alloca float
call void @starttime()
store float 0x3FF00418A0000000, float* %t32
%t34 = call i32 @getint()
store i32 %t34, i32* %t33
store float 0x0000000000000000, float* %t35
store float 0x3FF00418A0000000, float* %t36
%t37 = load float, float* %t32
%t38 = load i32, i32* %t33
%t39 = call float @func(float %t37, i32 %t38)
store float %t39, float* %t35
%t40 = load float, float* %t35
%t41 = load float, float* %t36
%t42 = fsub float %t40, %t41
%t43 = fcmp oeq float %t42, 0x0000000000000000
%t44 = zext i1 %t43 to i32
%t45 = icmp ne i32 %t44, 0
br i1 %t45, label %if.then.7, label %if.end.8
if.then.7:
call void @putch(i32 112)
br label %if.end.8
if.end.8:
call void @stoptime()
ret i32 0
}