; LLVM IR from xhub/reshop :: gui/external/imgui/imgui_widgets.ll (ZN26ImGuiInputTextCallbackData11DeleteCharsEii)

; 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.ImGuiInputTextCallbackData = type { ptr, i32, i32, ptr, i16, i32, ptr, i32, i32, i8, i32, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__._ZN26ImGuiInputTextCallbackData11DeleteCharsEii = external hidden unnamed_addr constant [55 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN26ImGuiInputTextCallbackData11DeleteCharsEii(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) #2 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
  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
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = add nsw i32 %10, %11
  %13 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 7
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp sle i32 %12, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  br label %19

17:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.54, ptr noundef @.str.2, i32 noundef 4196, ptr noundef @__PRETTY_FUNCTION__._ZN26ImGuiInputTextCallbackData11DeleteCharsEii) #4
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %20 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %25 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 7
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sub nsw i32 %36, %37
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sub nsw i32 %38, %39
  %41 = add nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %42, i1 false)
  %43 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 10
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = add nsw i32 %45, %46
  %48 = icmp sge i32 %44, %47
  br i1 %48, label %49, label %54

49:                                               ; preds = %19
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 10
  %52 = load i32, ptr %51, align 4, !tbaa !17
  %53 = sub nsw i32 %52, %50
  store i32 %53, ptr %51, align 4, !tbaa !17
  br label %63

54:                                               ; preds = %19
  %55 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 10
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = icmp sge i32 %56, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %54
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 10
  store i32 %60, ptr %61, align 4, !tbaa !17
  br label %62

62:                                               ; preds = %59, %54
  br label %63

63:                                               ; preds = %62, %49
  %64 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 10
  %65 = load i32, ptr %64, align 4, !tbaa !17
  %66 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 12
  store i32 %65, ptr %66, align 4, !tbaa !18
  %67 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 11
  store i32 %65, ptr %67, align 8, !tbaa !19
  %68 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 9
  store i8 1, ptr %68, align 8, !tbaa !20
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = getelementptr inbounds %struct.ImGuiInputTextCallbackData, ptr %9, i32 0, i32 7
  %71 = load i32, ptr %70, align 8, !tbaa !11
  %72 = sub nsw i32 %71, %69
  store i32 %72, ptr %70, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn nounwind }
attributes #5 = { 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, !10, i64 40}
!12 = !{!"_ZTS26ImGuiInputTextCallbackData", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !13, i64 24, !14, i64 28, !6, i64 32, !10, i64 40, !10, i64 44, !15, i64 48, !10, i64 52, !10, i64 56, !10, i64 60}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTS8ImGuiKey", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !10, i64 52}
!18 = !{!12, !10, i64 60}
!19 = !{!12, !10, i64 56}
!20 = !{!12, !15, 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"

@.str.2 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__._ZN26ImGuiInputTextCallbackData11DeleteCharsEii = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN26ImGuiInputTextCallbackData11DeleteCharsEii(ptr nocapture noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = add nsw i32 %2, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp sgt i32 %4, %6
  br i1 %.not, label %7, label %8

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.54, ptr noundef nonnull @.str.2, i32 noundef 4196, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN26ImGuiInputTextCallbackData11DeleteCharsEii) #3
  unreachable

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  %13 = sext i32 %2 to i64
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %reass.sub = sub i32 %6, %4
  %15 = add i32 %reass.sub, 1
  %16 = sext i32 %15 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %12, ptr align 1 %14, i64 %16, i1 false)
  %17 = getelementptr inbounds i8, ptr %0, i64 52
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %.not18 = icmp slt i32 %18, %4
  br i1 %.not18, label %21, label %19

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

21:                                               ; preds = %8
  %.not19 = icmp slt i32 %18, %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 %17, align 4, !tbaa !15
  br label %22

22:                                               ; preds = %.sink.split, %21
  %23 = phi i32 [ %18, %21 ], [ %.sink, %.sink.split ]
  %24 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %23, ptr %24, align 4, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %23, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 1, ptr %26, align 8, !tbaa !18
  %27 = load i32, ptr %5, align 8, !tbaa !5
  %28 = sub nsw i32 %27, %2
  store i32 %28, ptr %5, align 8, !tbaa !5
  ret void
}

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

attributes #0 = { noreturn nounwind "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn 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, !10, i64 40}
!6 = !{!"_ZTS26ImGuiInputTextCallbackData", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !11, i64 24, !12, i64 28, !7, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !10, i64 52, !10, i64 56, !10, i64 60}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"_ZTS8ImGuiKey", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !10, i64 52}
!16 = !{!6, !10, i64 60}
!17 = !{!6, !10, i64 56}
!18 = !{!6, !13, i64 48}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass