; LLVM IR from Devaniti/BoolkaEngine :: ThirdParty/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, i16, i16, i8, i8 }>
%struct.ImGuiTabBar = type { %struct.ImVector.31, i32, i32, i32, i32, i32, i32, i32, %struct.ImRect, float, float, float, float, float, float, float, float, float, float, i32, i8, i8, i8, i8, i8, i16, i16, float, %struct.ImVec2, %struct.ImVec2, %struct.ImGuiTextBuffer }
%struct.ImVector.31 = type { i32, i32, ptr }
%struct.ImRect = type { %struct.ImVec2, %struct.ImVec2 }
%struct.ImVec2 = type { float, float }
%struct.ImGuiTextBuffer = type { %struct.ImVector.25 }
%struct.ImVector.25 = 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(35) 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 19
  %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 eq ptr %14, null
  br i1 %15, label %22, label %16

16:                                               ; preds = %1
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ImGuiTabItem, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !20
  %20 = and i32 %19, 32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

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

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(152) %24, ptr noundef %25)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ImGuiTabBar, ptr %27, i32 0, i32 20
  %29 = load i8, ptr %28, align 8, !tbaa !22
  %30 = sext i8 %29 to i32
  %31 = add nsw i32 %26, %30
  store i32 %31, ptr %6, align 4, !tbaa !23
  %32 = load i32, ptr %6, align 4, !tbaa !23
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %41, label %34

34:                                               ; preds = %23
  %35 = load i32, ptr %6, align 4, !tbaa !23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ImGuiTabBar, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.ImVector.31, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !24
  %40 = icmp sge i32 %35, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %34, %23
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %77

42:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ImGuiTabBar, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %6, align 4, !tbaa !23
  %46 = call noundef nonnull align 4 dereferenceable(35) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16) %44, i32 noundef %45)
  store ptr %46, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ImGuiTabItem, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !20
  %50 = and i32 %49, 32
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %76

53:                                               ; preds = %42
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ImGuiTabItem, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = and i32 %56, 192
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ImGuiTabItem, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = and i32 %60, 192
  %62 = icmp ne i32 %57, %61
  br i1 %62, label %63, label %64

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

64:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 36, ptr %8) #5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %65, i64 36, i1 false), !tbaa.struct !25
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %67, ptr align 4 %66, i64 35, i1 false), !tbaa.struct !25
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %68, ptr align 4 %8, i64 35, i1 false), !tbaa.struct !25
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ImGuiTabBar, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !29
  %72 = and i32 %71, 4194304
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %64
  call void @_ZN5ImGui20MarkIniSettingsDirtyEv()
  br label %75

75:                                               ; preds = %74, %64
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 36, ptr %8) #5
  br label %76

76:                                               ; preds = %75, %63, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %77

77:                                               ; preds = %76, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %78

78:                                               ; preds = %77, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %79 = load i1, ptr %2, align 1
  ret i1 %79
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(152), 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 100}
!10 = !{!"_ZTS11ImGuiTabBar", !11, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !13, i64 44, !15, i64 60, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !15, i64 80, !15, i64 84, !15, i64 88, !15, i64 92, !15, i64 96, !12, i64 100, !7, i64 104, !7, i64 105, !16, i64 106, !16, i64 107, !16, i64 108, !17, i64 110, !17, i64 112, !15, i64 116, !14, i64 120, !14, i64 128, !18, i64 136}
!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 = !{!21, !12, i64 4}
!21 = !{!"_ZTS12ImGuiTabItem", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !17, i64 28, !17, i64 30, !17, i64 32, !16, i64 34}
!22 = !{!10, !7, i64 104}
!23 = !{!12, !12, i64 0}
!24 = !{!10, !12, i64 0}
!25 = !{i64 0, i64 4, !23, i64 4, i64 4, !23, i64 8, i64 4, !23, i64 12, i64 4, !23, i64 16, i64 4, !26, i64 20, i64 4, !26, i64 24, i64 4, !26, i64 28, i64 2, !27, i64 30, i64 2, !27, i64 32, i64 2, !27, i64 34, i64 1, !28}
!26 = !{!15, !15, i64 0}
!27 = !{!17, !17, i64 0}
!28 = !{!16, !16, i64 0}
!29 = !{!10, !12, i64 16}


; 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, i16, 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(35) 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 100
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = tail call noundef ptr @_ZN5ImGui17TabBarFindTabByIDEP11ImGuiTabBarj(ptr noundef %0, i32 noundef %4)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %35, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !19
  %10 = and i32 %9, 32
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %35

11:                                               ; preds = %7
  %12 = tail call noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef nonnull %5)
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  %14 = load i8, ptr %13, align 8, !tbaa !21
  %15 = sext i8 %14 to i32
  %16 = add nsw i32 %12, %15
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %35, label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %0, align 8, !tbaa !22
  %.not22 = icmp slt i32 %16, %19
  br i1 %.not22, label %20, label %35

20:                                               ; preds = %18
  %21 = tail call noundef nonnull align 4 dereferenceable(35) ptr @_ZN8ImVectorI12ImGuiTabItemEixEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %16)
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !19
  %24 = and i32 %23, 32
  %.not23 = icmp eq i32 %24, 0
  br i1 %.not23, label %25, label %35

25:                                               ; preds = %20
  %26 = load i32, ptr %8, align 4, !tbaa !19
  %27 = xor i32 %26, %23
  %28 = and i32 %27, 192
  %.not24 = icmp eq i32 %28, 0
  br i1 %.not24, label %29, label %35

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %2)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %2, ptr noundef nonnull align 4 dereferenceable(36) %5, i64 36, i1 false), !tbaa.struct !23
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(35) %5, ptr noundef nonnull align 4 dereferenceable(35) %21, i64 35, i1 false), !tbaa.struct !23
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(35) %21, ptr noundef nonnull align 4 dereferenceable(35) %2, i64 35, i1 false), !tbaa.struct !23
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !28
  %32 = and i32 %31, 4194304
  %.not25 = icmp eq i32 %32, 0
  br i1 %.not25, label %34, label %33

33:                                               ; preds = %29
  tail call void @_ZN5ImGui20MarkIniSettingsDirtyEv()
  br label %34

34:                                               ; preds = %33, %29
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %2)
  br label %35

35:                                               ; preds = %18, %11, %25, %20, %34, %1, %7
  %.2 = phi i1 [ false, %7 ], [ false, %1 ], [ false, %18 ], [ false, %11 ], [ true, %34 ], [ false, %20 ], [ false, %25 ]
  ret i1 %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK11ImGuiTabBar11GetTabOrderEPK12ImGuiTabItem(ptr noundef nonnull align 8 dereferenceable(152), 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 100}
!6 = !{!"_ZTS11ImGuiTabBar", !7, i64 0, !8, i64 16, !8, i64 20, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !8, i64 40, !12, i64 44, !14, i64 60, !14, i64 64, !14, i64 68, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !14, i64 92, !14, i64 96, !8, i64 100, !9, i64 104, !9, i64 105, !15, i64 106, !15, i64 107, !15, i64 108, !16, i64 110, !16, i64 112, !14, i64 116, !13, i64 120, !13, i64 128, !17, i64 136}
!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 = !{!20, !8, i64 4}
!20 = !{!"_ZTS12ImGuiTabItem", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !16, i64 28, !16, i64 30, !16, i64 32, !15, i64 34}
!21 = !{!6, !9, i64 104}
!22 = !{!6, !8, i64 0}
!23 = !{i64 0, i64 4, !24, i64 4, i64 4, !24, i64 8, i64 4, !24, i64 12, i64 4, !24, i64 16, i64 4, !25, i64 20, i64 4, !25, i64 24, i64 4, !25, i64 28, i64 2, !26, i64 30, i64 2, !26, i64 32, i64 2, !26, i64 34, i64 1, !27}
!24 = !{!8, !8, i64 0}
!25 = !{!14, !14, i64 0}
!26 = !{!16, !16, i64 0}
!27 = !{!15, !15, i64 0}
!28 = !{!6, !8, i64 16}


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