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

; 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.ImVec2 = type { float, float }
%struct.ImGuiTextEditState = type <{ i32, [1024 x i16], [3073 x i8], [3 x i8], i64, float, float, %struct.STB_TexteditState, float, %struct.ImVec2, i8, [7 x i8], ptr, float, [4 x i8] }>
%struct.STB_TexteditState = type { i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, float, %struct.StbUndoState }
%struct.StbUndoState = type { [99 x %struct.StbUndoRecord], [999 x i16], i16, i16, i16, i16 }
%struct.StbUndoRecord = type { i32, i16, i16, i16 }

@.str.10 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.99 = external hidden unnamed_addr constant [23 x i8], align 1
@__PRETTY_FUNCTION__._ZNK18ImGuiTextEditState28CalcDisplayOffsetFromCharIdxEi = external hidden unnamed_addr constant [67 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 uwtable
declare dso_local <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120), float noundef, float noundef, ptr noundef, ptr noundef, ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK18ImGuiTextEditState28CalcDisplayOffsetFromCharIdxEi(ptr noundef nonnull align 8 dereferenceable(8396) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca %struct.ImVec2, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 12
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 13
  %12 = load float, ptr %11, align 8, !tbaa !20
  %13 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 1
  %14 = getelementptr inbounds [1024 x i16], ptr %13, i64 0, i64 0
  %15 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 6
  %16 = load float, ptr %15, align 4, !tbaa !21
  %17 = call noundef ptr @_ZN18ImGuiTextEditState22GetTextPointerClippedWEP6ImFontfPKtfP6ImVec2(ptr noundef %10, float noundef %12, ptr noundef %14, float noundef %16, ptr noundef null)
  store ptr %17, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %18 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 1
  %19 = getelementptr inbounds [1024 x i16], ptr %18, i64 0, i64 0
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i16, ptr %19, i64 %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp uge ptr %22, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %2
  %26 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 1
  %27 = getelementptr inbounds [1024 x i16], ptr %26, i64 0, i64 0
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i16, ptr %27, i64 %29
  br label %33

31:                                               ; preds = %2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %25
  %34 = phi ptr [ %30, %25 ], [ %32, %31 ]
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = icmp uge ptr %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  br label %41

39:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.99, ptr noundef @.str.10, i32 noundef 5275, ptr noundef @__PRETTY_FUNCTION__._ZNK18ImGuiTextEditState28CalcDisplayOffsetFromCharIdxEi) #4
  unreachable

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %38
  %42 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 12
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 13
  %45 = load float, ptr %44, align 8, !tbaa !20
  %46 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %8, i32 0, i32 5
  %47 = load float, ptr %46, align 8, !tbaa !22
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120) %43, float noundef %45, float noundef %47, ptr noundef %48, ptr noundef %49, ptr noundef null)
  store <2 x float> %50, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %51 = load <2 x float>, ptr %3, align 4
  ret <2 x float> %51
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN18ImGuiTextEditState22GetTextPointerClippedWEP6ImFontfPKtfP6ImVec2(ptr noundef, float noundef, ptr noundef, float noundef, ptr noundef) #2 align 2

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 uwtable "min-legal-vector-width"="64" "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 = { nounwind }
attributes #4 = { 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, !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 8384}
!12 = !{!"_ZTS18ImGuiTextEditState", !10, i64 0, !7, i64 4, !7, i64 2052, !13, i64 5128, !14, i64 5136, !14, i64 5140, !15, i64 5144, !14, i64 8364, !18, i64 8368, !19, i64 8376, !6, i64 8384, !14, i64 8392}
!13 = !{!"long", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS17STB_TexteditState", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !14, i64 20, !16, i64 24}
!16 = !{!"_ZTS12StbUndoState", !7, i64 0, !7, i64 1188, !17, i64 3186, !17, i64 3188, !17, i64 3190, !17, i64 3192}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_ZTS6ImVec2", !14, i64 0, !14, i64 4}
!19 = !{!"bool", !7, i64 0}
!20 = !{!12, !14, i64 8392}
!21 = !{!12, !14, i64 5140}
!22 = !{!12, !14, i64 5136}


; 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 uwtable
declare dso_local <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120), float noundef, float noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK18ImGuiTextEditState28CalcDisplayOffsetFromCharIdxEi(ptr noundef nonnull align 8 dereferenceable(8396) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8384
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8392
  %6 = load float, ptr %5, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = getelementptr inbounds i8, ptr %0, i64 5140
  %9 = load float, ptr %8, align 4, !tbaa !19
  %10 = tail call noundef ptr @_ZN18ImGuiTextEditState22GetTextPointerClippedWEP6ImFontfPKtfP6ImVec2(ptr noundef %4, float noundef %6, ptr noundef nonnull %7, float noundef %9, ptr noundef null)
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds i16, ptr %7, i64 %11
  %.not = icmp ult ptr %12, %10
  %13 = select i1 %.not, ptr %10, ptr %12
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load float, ptr %5, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %0, i64 5136
  %17 = load float, ptr %16, align 8, !tbaa !20
  %18 = tail call <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120) %14, float noundef %15, float noundef %17, ptr noundef %10, ptr noundef nonnull %13, ptr noundef null)
  ret <2 x float> %18
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN18ImGuiTextEditState22GetTextPointerClippedWEP6ImFontfPKtfP6ImVec2(ptr noundef, float noundef, ptr noundef, float noundef, ptr noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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, !17, i64 8384}
!6 = !{!"_ZTS18ImGuiTextEditState", !7, i64 0, !8, i64 4, !8, i64 2052, !10, i64 5128, !11, i64 5136, !11, i64 5140, !12, i64 5144, !11, i64 8364, !15, i64 8368, !16, i64 8376, !17, i64 8384, !11, i64 8392}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"_ZTS17STB_TexteditState", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !8, i64 18, !8, i64 19, !11, i64 20, !13, i64 24}
!13 = !{!"_ZTS12StbUndoState", !8, i64 0, !8, i64 1188, !14, i64 3186, !14, i64 3188, !14, i64 3190, !14, i64 3192}
!14 = !{!"short", !8, i64 0}
!15 = !{!"_ZTS6ImVec2", !11, i64 0, !11, i64 4}
!16 = !{!"bool", !8, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!6, !11, i64 8392}
!19 = !{!6, !11, i64 5140}
!20 = !{!6, !11, i64 5136}


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