; LLVM IR from Simple-XX/SimpleKernel :: src/drv/tui/tui.ll (ZN3TUI6scrollEv)

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

%class.pos_t = type { i8, i8 }
%class.col_t = type { i8 }
%class.char_t = type { i8, %class.col_t }

@_ZN3TUI3posE = external dso_local global %class.pos_t, align 1
@_ZN3TUI5colorE = external dso_local global %class.col_t, align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, ptr noundef) #2 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TUI6scrollEv(ptr noundef nonnull align 8 dereferenceable(8) %0) #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca %class.char_t, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca %class.char_t, align 1
  %9 = alloca %class.col_t, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  %11 = load i8, ptr getelementptr inbounds (%class.pos_t, ptr @_ZN3TUI3posE, i32 0, i32 1), align 1, !tbaa !9
  %12 = zext i8 %11 to i64
  %13 = icmp uge i64 %12, 25
  br i1 %13, label %14, label %53

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %24, %14
  %16 = load i64, ptr %3, align 8, !tbaa !11
  %17 = icmp ult i64 %16, 1920
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %31

19:                                               ; preds = %15
  %20 = load i64, ptr %3, align 8, !tbaa !11
  %21 = load i64, ptr %3, align 8, !tbaa !11
  %22 = add i64 %21, 80
  call void @_ZNK3TUI4readEm(ptr dead_on_unwind writable sret(%class.char_t) align 1 %4, ptr noundef nonnull align 8 dereferenceable(8) %10, i64 noundef %22)
  invoke void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %10, i64 noundef %20, ptr noundef %4)
          to label %23 unwind label %27

23:                                               ; preds = %19
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %4) #4
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %3, align 8, !tbaa !11
  %26 = add i64 %25, 1
  store i64 %26, ptr %3, align 8, !tbaa !11
  br label %15, !llvm.loop !13

27:                                               ; preds = %19
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %5, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %6, align 4
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %54

31:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 1920, ptr %7, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %40, %31
  %33 = load i64, ptr %7, align 8, !tbaa !11
  %34 = icmp ult i64 %33, 2000
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %52

36:                                               ; preds = %32
  %37 = load i64, ptr %7, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 @_ZN3TUI5colorE, i64 1, i1 false), !tbaa.struct !15
  invoke void @_ZN6char_tC1Eh5col_t(ptr noundef nonnull align 1 dereferenceable(2) %8, i8 noundef zeroext 32, ptr noundef %9)
          to label %38 unwind label %43

38:                                               ; preds = %36
  invoke void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %10, i64 noundef %37, ptr noundef %8)
          to label %39 unwind label %47

39:                                               ; preds = %38
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %8) #4
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %9) #4
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = add i64 %41, 1
  store i64 %42, ptr %7, align 8, !tbaa !11
  br label %32, !llvm.loop !17

43:                                               ; preds = %36
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %5, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %6, align 4
  br label %51

47:                                               ; preds = %38
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %5, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %6, align 4
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %8) #4
  br label %51

51:                                               ; preds = %47, %43
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %54

52:                                               ; preds = %35
  store i8 24, ptr getelementptr inbounds (%class.pos_t, ptr @_ZN3TUI3posE, i32 0, i32 1), align 1, !tbaa !9
  br label %53

53:                                               ; preds = %52, %1
  ret void

54:                                               ; preds = %51, %27
  %55 = load ptr, ptr %5, align 8
  %56 = load i32, ptr %6, align 4
  %57 = insertvalue { ptr, i32 } poison, ptr %55, 0
  %58 = insertvalue { ptr, i32 } %57, i32 %56, 1
  resume { ptr, i32 } %58
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3TUI4readEm(ptr dead_on_unwind noalias writable sret(%class.char_t) align 1, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

declare void @_ZN5col_tD1Ev(ptr)

declare void @_ZN6char_tC1Eh5col_t(ptr, i8, ptr)

declare void @_ZN6char_tD1Ev(ptr)

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !7, i64 1}
!10 = !{!"_ZTS5pos_t", !7, i64 0, !7, i64 1}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 1, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !14}


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

%class.pos_t = type { i8, i8 }
%class.col_t = type { i8 }
%class.char_t = type { i8, %class.col_t }

@_ZN3TUI3posE = external dso_local local_unnamed_addr global %class.pos_t, align 1
@_ZN3TUI5colorE = external dso_local local_unnamed_addr global %class.col_t, align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, ptr noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TUI6scrollEv(ptr noundef nonnull align 8 dereferenceable(8) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %class.char_t, align 1
  %3 = alloca %class.char_t, align 1
  %4 = alloca %class.col_t, align 1
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3TUI3posE, i64 1), align 1, !tbaa !5
  %6 = icmp ugt i8 %5, 24
  br i1 %6, label %.preheader10, label %15

.preheader10:                                     ; preds = %1, %.preheader10
  %.0911 = phi i64 [ %8, %.preheader10 ], [ 0, %1 ]
  %7 = add nuw nsw i64 %.0911, 80
  call void @_ZNK3TUI4readEm(ptr dead_on_unwind nonnull writable sret(%class.char_t) align 1 %2, ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %7)
  call void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %.0911, ptr noundef nonnull %2)
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %2) #2
  %8 = add nuw nsw i64 %.0911, 1
  %exitcond.not = icmp eq i64 %8, 1920
  br i1 %exitcond.not, label %.preheader, label %.preheader10, !llvm.loop !9

9:                                                ; preds = %11
  store i8 24, ptr getelementptr inbounds (i8, ptr @_ZN3TUI3posE, i64 1), align 1, !tbaa !5
  br label %15

.preheader:                                       ; preds = %.preheader10, %11
  %.012 = phi i64 [ %12, %11 ], [ 1920, %.preheader10 ]
  %10 = load i8, ptr @_ZN3TUI5colorE, align 1, !tbaa !11
  store i8 %10, ptr %4, align 1, !tbaa !11
  invoke void @_ZN6char_tC1Eh5col_t(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext 32, ptr noundef nonnull %4)
          to label %11 unwind label %13

11:                                               ; preds = %.preheader
  call void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %.012, ptr noundef nonnull %3)
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %3) #2
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %4) #2
  %12 = add nuw nsw i64 %.012, 1
  %exitcond13.not = icmp eq i64 %12, 2000
  br i1 %exitcond13.not, label %9, label %.preheader, !llvm.loop !12

13:                                               ; preds = %.preheader
  %14 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %4) #2
  resume { ptr, i32 } %14

15:                                               ; preds = %9, %1
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3TUI4readEm(ptr dead_on_unwind noalias writable sret(%class.char_t) align 1, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 2

declare void @_ZN5col_tD1Ev(ptr) local_unnamed_addr

declare void @_ZN6char_tC1Eh5col_t(ptr, i8, ptr) local_unnamed_addr

declare void @_ZN6char_tD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress 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 = { mustprogress 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 #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, !7, i64 1}
!6 = !{!"_ZTS5pos_t", !7, i64 0, !7, i64 1}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


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