; LLVM IR from rociodellasala/TP3_SO :: Kernel (video_driver)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@buffer_max_per_line = external hidden global i32, align 4
@buffer_max_per_column = external hidden global i32, align 4
@buffer_position = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @move_screen() #0

; Function Attrs: nounwind uwtable
declare dso_local void @nextLineAnyway() #0

; Function Attrs: nounwind uwtable
define dso_local void @print_charColor(i8 noundef zeroext %0, i32 noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !8
  %5 = load i8, ptr %3, align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  %7 = icmp eq i32 %6, 10
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  call void @nextLineAnyway()
  br label %32

9:                                                ; preds = %2
  %10 = load i8, ptr %3, align 1, !tbaa !5
  %11 = load i32, ptr @buffer_position, align 4, !tbaa !8
  %12 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !8
  %13 = srem i32 %11, %12
  %14 = mul nsw i32 %13, 10
  %15 = load i32, ptr @buffer_position, align 4, !tbaa !8
  %16 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !8
  %17 = sdiv i32 %15, %16
  %18 = mul nsw i32 %17, 15
  %19 = load i32, ptr %4, align 4, !tbaa !8
  call void @draw_charColor(i8 noundef zeroext %10, i32 noundef %14, i32 noundef %18, i32 noundef %19)
  %20 = load i32, ptr @buffer_position, align 4, !tbaa !8
  %21 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !8
  %22 = sdiv i32 %20, %21
  %23 = load i32, ptr @buffer_max_per_column, align 4, !tbaa !8
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %9
  call void @move_screen()
  %26 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !8
  %27 = load i32, ptr @buffer_position, align 4, !tbaa !8
  %28 = sub nsw i32 %27, %26
  store i32 %28, ptr @buffer_position, align 4, !tbaa !8
  br label %29

29:                                               ; preds = %25, %9
  %30 = load i32, ptr @buffer_position, align 4, !tbaa !8
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @buffer_position, align 4, !tbaa !8
  br label %32

32:                                               ; preds = %29, %8
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @draw_charColor(i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef) #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@buffer_max_per_line = external hidden local_unnamed_addr global i32, align 4
@buffer_max_per_column = external hidden local_unnamed_addr global i32, align 4
@buffer_position = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @move_screen() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @nextLineAnyway() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @print_charColor(i8 noundef zeroext %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i8 %0, 10
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void @nextLineAnyway()
  br label %24

5:                                                ; preds = %2
  %6 = load i32, ptr @buffer_position, align 4, !tbaa !5
  %7 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %8 = srem i32 %6, %7
  %9 = mul nsw i32 %8, 10
  %10 = sdiv i32 %6, %7
  %11 = mul nsw i32 %10, 15
  tail call void @draw_charColor(i8 noundef zeroext %0, i32 noundef %9, i32 noundef %11, i32 noundef %1)
  %12 = load i32, ptr @buffer_position, align 4, !tbaa !5
  %13 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %14 = sdiv i32 %12, %13
  %15 = load i32, ptr @buffer_max_per_column, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %5
  tail call void @move_screen()
  %18 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %19 = load i32, ptr @buffer_position, align 4, !tbaa !5
  %20 = sub nsw i32 %19, %18
  br label %21

21:                                               ; preds = %17, %5
  %22 = phi i32 [ %20, %17 ], [ %12, %5 ]
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @buffer_position, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %21, %4
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @draw_charColor(i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass