Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @.output_str = private constant [12 x i8] c"Output: %d\0A\00"
- @.err_str = private constant [22 x i8] c"Error: zero division\0A\00"
- declare i32 @printf(i8*, ...)
- define i32 @main() {
- %num = alloca i32
- %denom = alloca i32
- store i32 25200, i32* %num
- store i32 2500, i32* %denom
- %denom_val = load i32* %denom
- ; check if the denom is zero
- %denom_is_zero = icmp eq i32 %denom_val, 0
- br i1 %denom_is_zero, label %if_denom_zero, label %if_denom_non_zero
- if_denom_zero:
- %err_str = getelementptr inbounds [22 x i8]* @.err_str, i32 0, i32 0
- %call = call i32 (i8*, ...)* @printf(i8* %err_str)
- ret i32 0
- if_denom_non_zero:
- %quot = alloca i32
- store i32 0, i32* %quot
- %rem = alloca i32
- store i32 0, i32* %rem
- %cur_denom_multiple = alloca i32
- %cur_quot = alloca i32
- br label %cond_is_finished
- cond_is_finished:
- %temp1 = load i32* %num
- %finished = icmp ugt i32 %denom_val, %temp1
- br i1 %finished, label %finished_true, label %finished_false
- finished_false:
- %temp2 = load i32* %denom
- store i32 %temp2, i32* %cur_denom_multiple
- store i32 1, i32* %cur_quot
- br label %cond_if_should_multiply_denom
- cond_if_should_multiply_denom:
- %temp3 = load i32* %cur_denom_multiple
- %temp4 = add i32 %temp3, %temp3
- %temp5 = load i32* %num
- %cond_not_should_multiply_denom = icmp ugt i32 %temp4, %temp5
- br i1 %cond_not_should_multiply_denom, label %if_not_should_multiply_denom, label %if_should_multiply_denom
- if_should_multiply_denom:
- store i32 %temp4, i32* %cur_denom_multiple
- %temp6 = load i32* %cur_quot
- %temp7 = add i32 %temp6, %temp6
- store i32 %temp7, i32* %cur_quot
- br label %cond_if_should_multiply_denom
- if_not_should_multiply_denom:
- %temp8 = load i32* %cur_quot
- %temp9 = load i32* %quot
- %temp10 = add i32 %temp8, %temp9
- store i32 %temp10, i32* %quot
- %temp11 = load i32* %num
- %temp12 = load i32* %cur_denom_multiple
- %temp13 = sub i32 %temp11, %temp12
- store i32 %temp13, i32* %num
- br label %cond_is_finished
- finished_true:
- %temp14 = load i32* %num
- store i32 %temp14, i32* %rem
- %temp15 = load i32* %quot
- %output_str = getelementptr inbounds [12 x i8]* @.output_str, i32 0, i32 0
- %call2 = call i32 (i8*, ...)* @printf(i8* %output_str, i32 %temp15)
- %call3 = call i32 (i8*, ...)* @printf(i8* %output_str, i32 %temp14)
- ret i32 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement