; LLVM IR from DarrenSweeney/3D-Physics-Engine :: Physics Engine/Imgui/imgui.ll (ZN25ImGuiTextEditCallbackData11DeleteCharsEii)

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

%struct.ImGuiTextEditCallbackData = type { i32, i32, ptr, i16, i32, ptr, i64, i8, i32, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN25ImGuiTextEditCallbackData11DeleteCharsEii(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, ptr %8, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %38, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %8, align 8, !tbaa !5
  %28 = load i8, ptr %26, align 1, !tbaa !16
  store i8 %28, ptr %9, align 1, !tbaa !16
  %29 = load i8, ptr %9, align 1, !tbaa !16
  %30 = icmp ne i8 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  store i32 3, ptr %10, align 4
  br label %36

32:                                               ; preds = %25
  %33 = load i8, ptr %9, align 1, !tbaa !16
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %7, align 8, !tbaa !5
  store i8 %33, ptr %34, align 1, !tbaa !16
  store i32 0, ptr %10, align 4
  br label %36

36:                                               ; preds = %32, %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  %37 = load i32, ptr %10, align 4
  switch i32 %37, label %67 [
    i32 0, label %38
    i32 3, label %39
  ]

38:                                               ; preds = %36
  br label %25, !llvm.loop !17

39:                                               ; preds = %36
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %40, align 1, !tbaa !16
  %41 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  store i8 1, ptr %41, align 8, !tbaa !19
  %42 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  %43 = load i32, ptr %42, align 4, !tbaa !20
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %43, %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = icmp sge i32 %45, %46
  br i1 %47, label %48, label %53

48:                                               ; preds = %39
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  %51 = load i32, ptr %50, align 4, !tbaa !20
  %52 = sub nsw i32 %51, %49
  store i32 %52, ptr %50, align 4, !tbaa !20
  br label %62

53:                                               ; preds = %39
  %54 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  %55 = load i32, ptr %54, align 4, !tbaa !20
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = icmp sge i32 %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %53
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  store i32 %59, ptr %60, align 4, !tbaa !20
  br label %61

61:                                               ; preds = %58, %53
  br label %62

62:                                               ; preds = %61, %48
  %63 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  %64 = load i32, ptr %63, align 4, !tbaa !20
  %65 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 10
  store i32 %64, ptr %65, align 4, !tbaa !21
  %66 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 9
  store i32 %64, ptr %66, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void

67:                                               ; preds = %36
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTS25ImGuiTextEditCallbackData", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !10, i64 20, !6, i64 24, !14, i64 32, !15, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !15, i64 40}
!20 = !{!12, !10, i64 44}
!21 = !{!12, !10, i64 52}
!22 = !{!12, !10, i64 48}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN25ImGuiTextEditCallbackData11DeleteCharsEii(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds i8, ptr %5, i64 %6
  %8 = sext i32 %2 to i64
  %9 = getelementptr inbounds i8, ptr %7, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !14
  %.not24 = icmp eq i8 %10, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %11 = phi i8 [ %14, %.lr.ph ], [ %10, %3 ]
  %.01426 = phi ptr [ %13, %.lr.ph ], [ %7, %3 ]
  %.01525 = phi ptr [ %12, %.lr.ph ], [ %9, %3 ]
  %12 = getelementptr inbounds i8, ptr %.01525, i64 1
  %13 = getelementptr inbounds i8, ptr %.01426, i64 1
  store i8 %11, ptr %.01426, align 1, !tbaa !14
  %14 = load i8, ptr %12, align 1, !tbaa !14
  %.not = icmp eq i8 %14, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.014.lcssa = phi ptr [ %7, %3 ], [ %13, %.lr.ph ]
  store i8 0, ptr %.014.lcssa, align 1, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 1, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 44
  %17 = load i32, ptr %16, align 4, !tbaa !16
  %18 = add nsw i32 %17, %2
  %.not18 = icmp slt i32 %18, %1
  br i1 %.not18, label %21, label %19

19:                                               ; preds = %._crit_edge
  %20 = sub nsw i32 %17, %2
  br label %.sink.split

21:                                               ; preds = %._crit_edge
  %.not19 = icmp slt i32 %17, %1
  br i1 %.not19, label %22, label %.sink.split

.sink.split:                                      ; preds = %21, %19
  %.sink = phi i32 [ %20, %19 ], [ %1, %21 ]
  store i32 %.sink, ptr %16, align 4, !tbaa !16
  br label %22

22:                                               ; preds = %.sink.split, %21
  %23 = phi i32 [ %17, %21 ], [ %.sink, %.sink.split ]
  %24 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %23, ptr %24, align 4, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %23, ptr %25, align 8, !tbaa !18
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 24}
!6 = !{!"_ZTS25ImGuiTextEditCallbackData", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !7, i64 20, !10, i64 24, !12, i64 32, !13, i64 40, !7, i64 44, !7, i64 48, !7, i64 52}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !13, i64 40}
!16 = !{!6, !7, i64 44}
!17 = !{!6, !7, i64 52}
!18 = !{!6, !7, i64 48}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass