; LLVM IR from TheNachoBIT/GeoFenix-Engine :: GeoFenix/ImGUI/imgui_widgets.ll (ZN5ImGui20TabBarProcessReorderEP11ImGuiTabBar)

; 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.ImGuiTabItem = type { i32, i32, i32, i32, float, float, float, i16, i8, i8 }
%struct.ImGuiTabBar = type { %struct.ImVector.26, i32, i32, i32, i32, i32, i32, %struct.ImRect, float, float, float, float, float, float, float, float, i32, i32, i8, i8, i8, i8, i16, %struct.ImVec2, %struct.ImGuiTextBuffer }
%struct.ImVector.26 = type { i32, i32, ptr }
%struct.ImRect = type { %struct.ImVec2, %struct.ImVec2 }
%struct.ImVec2 = type { float, float }
%struct.ImGuiTextBuffer = type { %struct.ImVector.22 }
%struct.ImVector.22 = type { i32, i32, ptr }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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
declare dso_local noundef ptr @_ZN5ImGui17TabBarFindTabByIDEP11ImGuiTabBarj(ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5ImGui20TabBarProcessReorderEP11ImGuiTabBar(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.ImGuiTabItem, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ImGuiTabBar, ptr %10, i32 0, i32 17
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = call noundef ptr @_ZN5ImGui17TabBarFindTabByIDEP11ImGuiTabBarj(ptr noundef %9, i32 noundef %12)
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %53

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(128) %18, ptr noundef %19)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ImGuiTabBar, ptr %21, i32 0, i32 18
  %23 = load i8, ptr %22, align 8, !tbaa !20
  %24 = sext i8 %23 to i32
  %25 = add nsw i32 %20, %24
  store i32 %25, ptr %6, align 4, !tbaa !21
  %26 = load i32, ptr %6, align 4, !tbaa !21
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %35, label %28

28:                                               ; preds = %17
  %29 = load i32, ptr %6, align 4, !tbaa !21
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ImGuiTabBar, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.ImVector.26, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !22
  %34 = icmp sge i32 %29, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %28, %17
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %52

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ImGuiTabBar, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %6, align 4, !tbaa !21
  %40 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16) %38, i32 noundef %39)
  store ptr %40, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %41, i64 32, i1 false), !tbaa.struct !23
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %43, ptr align 4 %42, i64 32, i1 false), !tbaa.struct !23
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %44, ptr align 4 %8, i64 32, i1 false), !tbaa.struct !23
  store ptr null, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ImGuiTabBar, ptr %45, i32 0, i32 16
  %47 = load i32, ptr %46, align 8, !tbaa !28
  %48 = and i32 %47, 4194304
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %36
  call void @_ZN5ImGui20MarkIniSettingsDirtyEv()
  br label %51

51:                                               ; preds = %50, %36
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %52

52:                                               ; preds = %51, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %53

53:                                               ; preds = %52, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %54 = load i1, ptr %2, align 1
  ret i1 %54
}

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

declare void @_ZN5ImGui20MarkIniSettingsDirtyEv() #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { "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 #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, !12, i64 92}
!10 = !{!"_ZTS11ImGuiTabBar", !11, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !13, i64 40, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !15, i64 80, !15, i64 84, !12, i64 88, !12, i64 92, !7, i64 96, !7, i64 97, !16, i64 98, !16, i64 99, !17, i64 100, !14, i64 104, !18, i64 112}
!11 = !{!"_ZTS8ImVectorI12ImGuiTabItemE", !12, i64 0, !12, i64 4, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS6ImRect", !14, i64 0, !14, i64 8}
!14 = !{!"_ZTS6ImVec2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_ZTS15ImGuiTextBuffer", !19, i64 0}
!19 = !{!"_ZTS8ImVectorIcE", !12, i64 0, !12, i64 4, !6, i64 8}
!20 = !{!10, !7, i64 96}
!21 = !{!12, !12, i64 0}
!22 = !{!10, !12, i64 0}
!23 = !{i64 0, i64 4, !21, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 12, i64 4, !21, i64 16, i64 4, !24, i64 20, i64 4, !24, i64 24, i64 4, !24, i64 28, i64 2, !25, i64 30, i64 1, !26, i64 31, i64 1, !27}
!24 = !{!15, !15, i64 0}
!25 = !{!17, !17, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!16, !16, i64 0}
!28 = !{!10, !12, i64 88}


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

%struct.ImGuiTabItem = type { i32, i32, i32, i32, float, float, float, i16, i8, i8 }

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

; Function Attrs: mustprogress 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) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5ImGui17TabBarFindTabByIDEP11ImGuiTabBarj(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5ImGui20TabBarProcessReorderEP11ImGuiTabBar(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.ImGuiTabItem, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 92
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = tail call noundef ptr @_ZN5ImGui17TabBarFindTabByIDEP11ImGuiTabBarj(ptr noundef %0, i32 noundef %4)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %22, label %6

6:                                                ; preds = %1
  %7 = tail call noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull %5)
  %8 = getelementptr inbounds i8, ptr %0, i64 96
  %9 = load i8, ptr %8, align 8, !tbaa !19
  %10 = sext i8 %9 to i32
  %11 = add nsw i32 %7, %10
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %22, label %13

13:                                               ; preds = %6
  %14 = load i32, ptr %0, align 8, !tbaa !20
  %.not18 = icmp slt i32 %11, %14
  br i1 %.not18, label %15, label %22

15:                                               ; preds = %13
  %16 = tail call noundef nonnull align 4 dereferenceable(32) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %2, ptr noundef nonnull align 4 dereferenceable(32) %5, i64 32, i1 false), !tbaa.struct !21
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %5, ptr noundef nonnull align 4 dereferenceable(32) %16, i64 32, i1 false), !tbaa.struct !21
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %16, ptr noundef nonnull align 4 dereferenceable(32) %2, i64 32, i1 false), !tbaa.struct !21
  %17 = getelementptr inbounds i8, ptr %0, i64 88
  %18 = load i32, ptr %17, align 8, !tbaa !27
  %19 = and i32 %18, 4194304
  %.not19 = icmp eq i32 %19, 0
  br i1 %.not19, label %21, label %20

20:                                               ; preds = %15
  tail call void @_ZN5ImGui20MarkIniSettingsDirtyEv()
  br label %21

21:                                               ; preds = %20, %15
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2)
  br label %22

22:                                               ; preds = %21, %13, %6, %1
  %.1 = phi i1 [ false, %1 ], [ true, %21 ], [ false, %13 ], [ false, %6 ]
  ret i1 %.1
}

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

declare void @_ZN5ImGui20MarkIniSettingsDirtyEv() local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { "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, !8, i64 92}
!6 = !{!"_ZTS11ImGuiTabBar", !7, i64 0, !8, i64 16, !8, i64 20, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !12, i64 40, !14, i64 56, !14, i64 60, !14, i64 64, !14, i64 68, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !8, i64 88, !8, i64 92, !9, i64 96, !9, i64 97, !15, i64 98, !15, i64 99, !16, i64 100, !13, i64 104, !17, i64 112}
!7 = !{!"_ZTS8ImVectorI12ImGuiTabItemE", !8, i64 0, !8, i64 4, !11, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTS6ImRect", !13, i64 0, !13, i64 8}
!13 = !{!"_ZTS6ImVec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !9, i64 0}
!15 = !{!"bool", !9, i64 0}
!16 = !{!"short", !9, i64 0}
!17 = !{!"_ZTS15ImGuiTextBuffer", !18, i64 0}
!18 = !{!"_ZTS8ImVectorIcE", !8, i64 0, !8, i64 4, !11, i64 8}
!19 = !{!6, !9, i64 96}
!20 = !{!6, !8, i64 0}
!21 = !{i64 0, i64 4, !22, i64 4, i64 4, !22, i64 8, i64 4, !22, i64 12, i64 4, !22, i64 16, i64 4, !23, i64 20, i64 4, !23, i64 24, i64 4, !23, i64 28, i64 2, !24, i64 30, i64 1, !25, i64 31, i64 1, !26}
!22 = !{!8, !8, i64 0}
!23 = !{!14, !14, i64 0}
!24 = !{!16, !16, i64 0}
!25 = !{!9, !9, i64 0}
!26 = !{!15, !15, i64 0}
!27 = !{!6, !8, i64 88}


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