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

; 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.col_t = type { i8 }
%class.char_t = type { i8, %class.col_t }
%class.pos_t = type { i8, i8 }

@_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: mustprogress uwtable
define dso_local void @_ZN3TUI5clearEv(ptr noundef nonnull align 8 dereferenceable(8) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %class.char_t, align 1
  %8 = alloca %class.col_t, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %class.pos_t, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %37, %1
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 25
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %40

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %29, %17
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = icmp ult i64 %19, 80
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %36

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %23 = load i64, ptr %3, align 8, !tbaa !9
  %24 = mul i64 %23, 80
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = add i64 %24, %25
  store i64 %26, ptr %6, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @_ZN3TUI5colorE, i64 1, i1 false), !tbaa.struct !11
  invoke void @_ZN6char_tC1Eh5col_t(ptr noundef nonnull align 1 dereferenceable(2) %7, i8 noundef zeroext 32, ptr noundef %8)
          to label %28 unwind label %32

28:                                               ; preds = %22
  call void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %12, i64 noundef %27, ptr noundef %7)
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %7) #4
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %29

29:                                               ; preds = %28
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = add i64 %30, 1
  store i64 %31, ptr %5, align 8, !tbaa !9
  br label %18, !llvm.loop !13

32:                                               ; preds = %22
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %9, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %10, align 4
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %46

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %3, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %3, align 8, !tbaa !9
  br label %13, !llvm.loop !15

40:                                               ; preds = %16
  call void @_ZN5pos_tC1Ehh(ptr noundef nonnull align 1 dereferenceable(2) %11, i8 noundef zeroext 0, i8 noundef zeroext 0)
  invoke void @_ZN3TUI7set_posE5pos_t(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef %11)
          to label %41 unwind label %42

41:                                               ; preds = %40
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %11) #4
  ret void

42:                                               ; preds = %40
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %9, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %10, align 4
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %11) #4
  br label %46

46:                                               ; preds = %42, %32
  %47 = load ptr, ptr %9, align 8
  %48 = load i32, ptr %10, align 4
  %49 = insertvalue { ptr, i32 } poison, ptr %47, 0
  %50 = insertvalue { ptr, i32 } %49, i32 %48, 1
  resume { ptr, i32 } %50
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, ptr noundef) #3 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) #2

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

declare void @_ZN5pos_tC1Ehh(ptr, i8, i8)

declare void @_ZN5pos_tD1Ev(ptr)

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 1, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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.col_t = type { i8 }
%class.char_t = type { i8, %class.col_t }
%class.pos_t = type { i8, i8 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TUI5clearEv(ptr noundef nonnull align 8 dereferenceable(8) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %class.char_t, align 1
  %3 = alloca %class.col_t, align 1
  %4 = alloca %class.pos_t, align 1
  br label %.preheader

.preheader:                                       ; preds = %1, %7
  %.01014 = phi i64 [ 0, %1 ], [ %8, %7 ]
  %5 = mul nuw nsw i64 %.01014, 80
  br label %9

6:                                                ; preds = %7
  call void @_ZN5pos_tC1Ehh(ptr noundef nonnull align 1 dereferenceable(2) %4, i8 noundef zeroext 0, i8 noundef zeroext 0)
  invoke void @_ZN3TUI7set_posE5pos_t(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %4)
          to label %16 unwind label %17

7:                                                ; preds = %11
  %8 = add nuw nsw i64 %.01014, 1
  %exitcond15.not = icmp eq i64 %8, 25
  br i1 %exitcond15.not, label %6, label %.preheader, !llvm.loop !5

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

11:                                               ; preds = %9
  %12 = add nuw nsw i64 %.01113, %5
  call void @_ZN3TUI5writeEm6char_t(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %12, ptr noundef nonnull %2)
  call void @_ZN6char_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %2) #2
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %3) #2
  %13 = add nuw nsw i64 %.01113, 1
  %exitcond.not = icmp eq i64 %13, 80
  br i1 %exitcond.not, label %7, label %9, !llvm.loop !10

14:                                               ; preds = %9
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %3) #2
  br label %19

16:                                               ; preds = %6
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %4) #2
  ret void

17:                                               ; preds = %6
  %18 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %4) #2
  br label %19

19:                                               ; preds = %17, %14
  %.pn = phi { ptr, i32 } [ %15, %14 ], [ %18, %17 ]
  resume { ptr, i32 } %.pn
}

; 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 #1 align 2

declare i32 @__gxx_personality_v0(...)

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

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

declare void @_ZN5pos_tD1Ev(ptr) local_unnamed_addr

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


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass