; LLVM IR from xing1357/SimpleOS :: src (console)

; 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"

@g_vga_buffer = external hidden global ptr, align 8
@g_vga_index = external hidden global i32, align 4
@cursor_pos_x = external hidden global i8, align 1
@cursor_pos_y = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @console_clear(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %17, %2
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = icmp ult i32 %7, 2200
  br i1 %8, label %9, label %20

9:                                                ; preds = %6
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = call zeroext i16 @vga_item_entry(i8 noundef zeroext 0, i32 noundef %10, i32 noundef %11)
  %13 = load ptr, ptr @g_vga_buffer, align 8, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds i16, ptr %13, i64 %15
  store i16 %12, ptr %16, align 2, !tbaa !11
  br label %17

17:                                               ; preds = %9
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !5
  br label %6, !llvm.loop !13

20:                                               ; preds = %6
  store i32 0, ptr @g_vga_index, align 4, !tbaa !5
  store i8 0, ptr @cursor_pos_x, align 1, !tbaa !15
  store i8 0, ptr @cursor_pos_y, align 1, !tbaa !15
  %21 = load i8, ptr @cursor_pos_x, align 1, !tbaa !15
  %22 = load i8, ptr @cursor_pos_y, align 1, !tbaa !15
  call void @vga_set_cursor_pos(i8 noundef zeroext %21, i8 noundef zeroext %22)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare zeroext i16 @vga_item_entry(i8 noundef zeroext, i32 noundef, i32 noundef) #2

declare void @vga_set_cursor_pos(i8 noundef zeroext, i8 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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" }
attributes #3 = { nounwind }

!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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, 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"

@g_vga_buffer = external hidden local_unnamed_addr global ptr, align 8
@g_vga_index = external hidden local_unnamed_addr global i32, align 4
@cursor_pos_x = external hidden local_unnamed_addr global i8, align 1
@cursor_pos_y = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @console_clear(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %2, %3
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %3 ]
  %4 = tail call zeroext i16 @vga_item_entry(i8 noundef zeroext 0, i32 noundef %0, i32 noundef %1) #2
  %5 = load ptr, ptr @g_vga_buffer, align 8, !tbaa !5
  %6 = getelementptr inbounds i16, ptr %5, i64 %indvars.iv
  store i16 %4, ptr %6, align 2, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 2200
  br i1 %exitcond.not, label %7, label %3, !llvm.loop !11

7:                                                ; preds = %3
  store i32 0, ptr @g_vga_index, align 4, !tbaa !13
  store i8 0, ptr @cursor_pos_x, align 1, !tbaa !15
  store i8 0, ptr @cursor_pos_y, align 1, !tbaa !15
  tail call void @vga_set_cursor_pos(i8 noundef zeroext 0, i8 noundef zeroext 0) #2
  ret void
}

declare zeroext i16 @vga_item_entry(i8 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @vga_set_cursor_pos(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

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" }
attributes #1 = { "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" }
attributes #2 = { nounwind }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass