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

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

@_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: mustprogress uwtable
declare dso_local void @_ZN3TUI12put_entry_atEc5col_tmm(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext, ptr noundef, i64 noundef, i64 noundef) #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3TUI10escapeconvEc(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TUI8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %0, i8 noundef signext %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca %class.col_t, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %class.pos_t, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  %10 = load i8, ptr %4, align 1, !tbaa !9
  %11 = call noundef zeroext i1 @_ZN3TUI10escapeconvEc(ptr noundef nonnull align 8 dereferenceable(8) %9, i8 noundef signext %10)
  %12 = zext i1 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %33

14:                                               ; preds = %2
  %15 = load i8, ptr %4, align 1, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 @_ZN3TUI5colorE, i64 1, i1 false), !tbaa.struct !10
  %16 = load i8, ptr @_ZN3TUI3posE, align 1, !tbaa !11
  %17 = zext i8 %16 to i64
  %18 = load i8, ptr getelementptr inbounds (%class.pos_t, ptr @_ZN3TUI3posE, i32 0, i32 1), align 1, !tbaa !13
  %19 = zext i8 %18 to i64
  invoke void @_ZN3TUI12put_entry_atEc5col_tmm(ptr noundef nonnull align 8 dereferenceable(8) %9, i8 noundef signext %15, ptr noundef %5, i64 noundef %17, i64 noundef %19)
          to label %20 unwind label %28

20:                                               ; preds = %14
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %5) #2
  %21 = load i8, ptr @_ZN3TUI3posE, align 1, !tbaa !11
  %22 = add i8 %21, 1
  store i8 %22, ptr @_ZN3TUI3posE, align 1, !tbaa !11
  %23 = zext i8 %22 to i64
  %24 = icmp uge i64 %23, 80
  br i1 %24, label %25, label %32

25:                                               ; preds = %20
  store i8 0, ptr @_ZN3TUI3posE, align 1, !tbaa !11
  %26 = load i8, ptr getelementptr inbounds (%class.pos_t, ptr @_ZN3TUI3posE, i32 0, i32 1), align 1, !tbaa !13
  %27 = add i8 %26, 1
  store i8 %27, ptr getelementptr inbounds (%class.pos_t, ptr @_ZN3TUI3posE, i32 0, i32 1), align 1, !tbaa !13
  br label %32

28:                                               ; preds = %14
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %6, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %7, align 4
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %5) #2
  br label %39

32:                                               ; preds = %25, %20
  br label %33

33:                                               ; preds = %32, %2
  call void @_ZN3TUI6scrollEv(ptr noundef nonnull align 8 dereferenceable(8) %9)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @_ZN3TUI3posE, i64 2, i1 false), !tbaa.struct !14
  invoke void @_ZN3TUI7set_posE5pos_t(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef %8)
          to label %34 unwind label %35

34:                                               ; preds = %33
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %8) #2
  ret void

35:                                               ; preds = %33
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %6, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %7, align 4
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %8) #2
  br label %39

39:                                               ; preds = %35, %28
  %40 = load ptr, ptr %6, align 8
  %41 = load i32, ptr %7, align 4
  %42 = insertvalue { ptr, i32 } poison, ptr %40, 0
  %43 = insertvalue { ptr, i32 } %42, i32 %41, 1
  resume { ptr, i32 } %43
}

declare void @_ZN5pos_tD1Ev(ptr)

declare void @_ZN5col_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 = { 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 = !{!7, !7, i64 0}
!10 = !{i64 0, i64 1, !9}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS5pos_t", !7, i64 0, !7, i64 1}
!13 = !{!12, !7, i64 1}
!14 = !{i64 0, i64 1, !9, i64 1, i64 1, !9}


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

@_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 uwtable
declare dso_local void @_ZN3TUI12put_entry_atEc5col_tmm(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3TUI10escapeconvEc(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #0 align 2

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

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TUI8put_charEc(ptr noundef nonnull align 8 dereferenceable(8) %0, i8 noundef signext %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.col_t, align 1
  %4 = alloca %class.pos_t, align 2
  %5 = tail call noundef zeroext i1 @_ZN3TUI10escapeconvEc(ptr noundef nonnull align 8 dereferenceable(8) %0, i8 noundef signext %1)
  br i1 %5, label %21, label %6

6:                                                ; preds = %2
  %7 = load i8, ptr @_ZN3TUI5colorE, align 1, !tbaa !5
  store i8 %7, ptr %3, align 1, !tbaa !5
  %8 = load i8, ptr @_ZN3TUI3posE, align 1, !tbaa !8
  %9 = zext i8 %8 to i64
  %10 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3TUI3posE, i64 1), align 1, !tbaa !10
  %11 = zext i8 %10 to i64
  invoke void @_ZN3TUI12put_entry_atEc5col_tmm(ptr noundef nonnull align 8 dereferenceable(8) %0, i8 noundef signext %1, ptr noundef nonnull %3, i64 noundef %9, i64 noundef %11)
          to label %12 unwind label %19

12:                                               ; preds = %6
  call void @_ZN5col_tD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %3) #1
  %13 = load i8, ptr @_ZN3TUI3posE, align 1, !tbaa !8
  %14 = add i8 %13, 1
  store i8 %14, ptr @_ZN3TUI3posE, align 1, !tbaa !8
  %15 = icmp ugt i8 %14, 79
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  store i8 0, ptr @_ZN3TUI3posE, align 1, !tbaa !8
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3TUI3posE, i64 1), align 1, !tbaa !10
  %18 = add i8 %17, 1
  store i8 %18, ptr getelementptr inbounds (i8, ptr @_ZN3TUI3posE, i64 1), align 1, !tbaa !10
  br label %21

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

21:                                               ; preds = %12, %16, %2
  call void @_ZN3TUI6scrollEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %22 = load i16, ptr @_ZN3TUI3posE, align 1
  store i16 %22, ptr %4, align 2
  invoke void @_ZN3TUI7set_posE5pos_t(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %4)
          to label %23 unwind label %24

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

24:                                               ; preds = %21
  %25 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5pos_tD1Ev(ptr noundef nonnull align 1 dereferenceable(2) %4) #1
  br label %26

26:                                               ; preds = %24, %19
  %.pn = phi { ptr, i32 } [ %25, %24 ], [ %20, %19 ]
  resume { ptr, i32 } %.pn
}

declare void @_ZN5pos_tD1Ev(ptr) local_unnamed_addr

declare void @_ZN5col_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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 0}
!9 = !{!"_ZTS5pos_t", !6, i64 0, !6, i64 1}
!10 = !{!9, !6, i64 1}


; Effective O3 passes: GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass