; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/implot_items.ll (ZN6ImPlot13BustItemCacheEv)

; 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.ImPlotContext = type { %struct.ImPool, %struct.ImPool.121, ptr, ptr, ptr, ptr, ptr, %struct.ImPlotTicker, %struct.ImPlotAnnotationCollection, %struct.ImPlotTagCollection, i8, [3 x i8], %struct.ImPlotStyle, %struct.ImVector.127, %struct.ImVector.128, %struct.ImPlotColormapData, %struct.ImVector.130, %struct.tm, %struct.ImVector.132, %struct.ImVector.132, %struct.ImVector.130, i32, i32, %struct.ImPlotNextPlotData, %struct.ImPlotNextItemData, %struct.ImPlotInputMap, i8, %struct.ImGuiTextBuffer, ptr, %struct.ImPool.133, ptr, ptr }
%struct.ImPool = type { %struct.ImVector, %struct.ImGuiStorage, i32, i32 }
%struct.ImVector = type { i32, i32, ptr }
%struct.ImGuiStorage = type { %struct.ImVector.120 }
%struct.ImVector.120 = type { i32, i32, ptr }
%struct.ImPool.121 = type { %struct.ImVector.122, %struct.ImGuiStorage, i32, i32 }
%struct.ImVector.122 = type { i32, i32, ptr }
%struct.ImPlotTicker = type <{ %struct.ImVector.123, %struct.ImGuiTextBuffer, %struct.ImVec2, %struct.ImVec2, i32, [4 x i8] }>
%struct.ImVector.123 = type { i32, i32, ptr }
%struct.ImVec2 = type { float, float }
%struct.ImPlotAnnotationCollection = type <{ %struct.ImVector.125, %struct.ImGuiTextBuffer, i32, [4 x i8] }>
%struct.ImVector.125 = type { i32, i32, ptr }
%struct.ImPlotTagCollection = type <{ %struct.ImVector.126, %struct.ImGuiTextBuffer, i32, [4 x i8] }>
%struct.ImVector.126 = type { i32, i32, ptr }
%struct.ImPlotStyle = type <{ float, i32, float, float, float, float, float, float, float, float, float, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, [21 x %struct.ImVec4], i32, i8, i8, i8, i8 }>
%struct.ImVec4 = type { float, float, float, float }
%struct.ImVector.127 = type { i32, i32, ptr }
%struct.ImVector.128 = type { i32, i32, ptr }
%struct.ImPlotColormapData = type <{ %struct.ImVector.129, %struct.ImVector.130, %struct.ImVector.130, %struct.ImVector.129, %struct.ImVector.130, %struct.ImVector.130, %struct.ImGuiTextBuffer, %struct.ImVector.130, %struct.ImVector.131, %struct.ImGuiStorage, i32, [4 x i8] }>
%struct.ImVector.129 = type { i32, i32, ptr }
%struct.ImVector.131 = type { i32, i32, ptr }
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, ptr }
%struct.ImVector.132 = type { i32, i32, ptr }
%struct.ImVector.130 = type { i32, i32, ptr }
%struct.ImPlotNextPlotData = type { [6 x i32], [6 x %struct.ImPlotRange], [6 x i8], [6 x i8], [6 x ptr], [6 x ptr] }
%struct.ImPlotRange = type { double, double }
%struct.ImPlotNextItemData = type { [5 x %struct.ImVec4], float, i32, float, float, float, float, float, float, float, i8, i8, i8, i8, i8, i8, i32 }
%struct.ImPlotInputMap = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float }
%struct.ImGuiTextBuffer = type { %struct.ImVector.124 }
%struct.ImVector.124 = type { i32, i32, ptr }
%struct.ImPool.133 = type { %struct.ImVector.134, %struct.ImGuiStorage, i32, i32 }
%struct.ImVector.134 = type { i32, i32, ptr }
%struct.ImPlotPlot = type <{ i32, i32, i32, i32, i32, [4 x i8], [6 x %struct.ImPlotAxis], %struct.ImGuiTextBuffer, %struct.ImPlotItemGroup, i32, i32, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImVec2, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, [3 x i8] }>
%struct.ImPlotAxis = type <{ i32, i32, i32, [4 x i8], %struct.ImPlotRange, i32, i32, %struct.ImPlotRange, ptr, %struct.ImPlotRange, %struct.ImPlotRange, %struct.ImPlotTicker, ptr, ptr, [16 x i8], ptr, ptr, ptr, i32, [4 x i8], %struct.ImPlotTime, %struct.ImPlotTime, ptr, ptr, ptr, float, float, double, double, double, float, float, %struct.ImRect, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, [4 x i8] }>
%struct.ImPlotTime = type <{ i64, i32, [4 x i8] }>
%struct.ImPlotItemGroup = type <{ i32, [4 x i8], %struct.ImPlotLegend, %struct.ImPool.236, i32, [4 x i8] }>
%struct.ImPlotLegend = type <{ i32, i32, i32, i32, %struct.ImVector.130, %struct.ImGuiTextBuffer, %struct.ImRect, i8, i8, i8, [5 x i8] }>
%struct.ImPool.236 = type { %struct.ImVector.237, %struct.ImGuiStorage, i32, i32 }
%struct.ImVector.237 = type { i32, i32, ptr }
%struct.ImRect = type { %struct.ImVec2, %struct.ImVec2 }
%struct.ImPlotSubplot = type <{ i32, i32, i32, [4 x i8], %struct.ImPlotItemGroup, i32, i32, i32, %struct.ImRect, %struct.ImRect, %struct.ImVec2, [4 x i8], %struct.ImVector.134, %struct.ImVector.134, %struct.ImVector.238, %struct.ImVector.238, %struct.ImVector.239, %struct.ImVector.239, [2 x float], i8, i8, [6 x i8] }>
%struct.ImVector.238 = type { i32, i32, ptr }
%struct.ImVector.239 = type { i32, i32, ptr }

@GImPlot = external global ptr, align 8

; 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 uwtable
define dso_local void @_ZN6ImPlot13BustItemCacheEv() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %6 = load ptr, ptr @GImPlot, align 8, !tbaa !5
  store ptr %6, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %21, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ImPlotContext, ptr %9, i32 0, i32 0
  %11 = call noundef i32 @_ZNK6ImPoolI10ImPlotPlotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %10)
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %24

14:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ImPlotContext, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = call noundef ptr @_ZN6ImPoolI10ImPlotPlotE10GetByIndexEi(ptr noundef nonnull align 8 dereferenceable(40) %16, i32 noundef %17)
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ImPlotPlot, ptr %19, i32 0, i32 8
  call void @_ZN15ImPlotItemGroup5ResetEv(ptr noundef nonnull align 8 dereferenceable(124) %20)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %21

21:                                               ; preds = %14
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !11

24:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %39, %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ImPlotContext, ptr %27, i32 0, i32 1
  %29 = call noundef i32 @_ZNK6ImPoolI13ImPlotSubplotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %28)
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %42

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ImPlotContext, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = call noundef ptr @_ZN6ImPoolI13ImPlotSubplotE10GetByIndexEi(ptr noundef nonnull align 8 dereferenceable(40) %34, i32 noundef %35)
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ImPlotSubplot, ptr %37, i32 0, i32 4
  call void @_ZN15ImPlotItemGroup5ResetEv(ptr noundef nonnull align 8 dereferenceable(124) %38)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %39

39:                                               ; preds = %32
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !13

42:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6ImPoolI10ImPlotPlotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6ImPoolI13ImPlotSubplotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

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

attributes #0 = { nocallback nofree nosync 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 = { 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@GImPlot = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6ImPlot13BustItemCacheEv() local_unnamed_addr #0 {
  %1 = load ptr, ptr @GImPlot, align 8, !tbaa !5
  %2 = tail call noundef i32 @_ZNK6ImPoolI10ImPlotPlotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  %4 = getelementptr inbounds i8, ptr %1, i64 40
  %5 = tail call noundef i32 @_ZNK6ImPoolI13ImPlotSubplotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph14, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.012 = phi i32 [ %9, %.lr.ph ], [ 0, %0 ]
  %7 = tail call noundef ptr @_ZN6ImPoolI10ImPlotPlotE10GetByIndexEi(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.012)
  %8 = getelementptr inbounds i8, ptr %7, i64 2296
  tail call void @_ZN15ImPlotItemGroup5ResetEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %9 = add nuw nsw i32 %.012, 1
  %10 = tail call noundef i32 @_ZNK6ImPoolI10ImPlotPlotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph14, %.preheader
  ret void

.lr.ph14:                                         ; preds = %.preheader, %.lr.ph14
  %.01113 = phi i32 [ %14, %.lr.ph14 ], [ 0, %.preheader ]
  %12 = tail call noundef ptr @_ZN6ImPoolI13ImPlotSubplotE10GetByIndexEi(ptr noundef nonnull align 8 dereferenceable(40) %4, i32 noundef %.01113)
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  tail call void @_ZN15ImPlotItemGroup5ResetEv(ptr noundef nonnull align 8 dereferenceable(124) %13)
  %14 = add nuw nsw i32 %.01113, 1
  %15 = tail call noundef i32 @_ZNK6ImPoolI13ImPlotSubplotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %.lr.ph14, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6ImPoolI10ImPlotPlotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6ImPoolI13ImPlotSubplotE10GetBufSizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

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

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass